Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redundant_slicing suggests change that doesn't compile. #12751

Open
Dirbaio opened this issue May 2, 2024 · 1 comment
Open

redundant_slicing suggests change that doesn't compile. #12751

Dirbaio opened this issue May 2, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Dirbaio
Copy link

Dirbaio commented May 2, 2024

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 Dirbaio added the C-bug Category: Clippy is not doing the correct thing label May 2, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label May 2, 2024
@ia0
Copy link

ia0 commented May 13, 2024

In particular, clippy shouldn't suggest to replace &x[..] with x if x: &mut [T]. It should only do so if x: &[T].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants