rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

redundant_slicing suggests change that doesn't compile.

Open Dirbaio opened this issue 1 year ago • 0 comments

Summary

redundant_slicing

Reproducer

I tried this code:

fn cmp(a: &mut [u8], b: & [u8]) -> bool {
    &a[..] < b
}

Clippy suggests this:

warning: redundant slicing of the whole range
 --> src/lib.rs:2:5
  |
2 |     &a[..] < b
  |     ^^^^^^ help: use the original value instead: `a`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing
  = note: `#[warn(clippy::redundant_slicing)]` on by default

However it doesn't compile:

error[E0308]: mismatched types
 --> src/lib.rs:2:9
  |
2 |     a < b
  |         ^ types differ in mutability
  |
  = note: expected mutable reference `&mut _`
                     found reference `&_`

Version

rustc 1.80.0-nightly (c987ad527 2024-05-01)
binary: rustc
commit-hash: c987ad527540e8f1565f57c31204bde33f63df76
commit-date: 2024-05-01
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Additional Labels

@rustbot label +I-suggestion-causes-error

Dirbaio avatar May 02 '24 16:05 Dirbaio