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

single_match: type are incompatible #12758

Open
matthiaskrgr opened this issue May 3, 2024 · 1 comment
Open

single_match: type are incompatible #12758

matthiaskrgr opened this issue May 3, 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

@matthiaskrgr
Copy link
Member

Summary

.

Reproducer

I tried this code:
cargo clippy --fix

fn test(s: &[u8]) {
    match &s[0..3] {
        b"hello" => {}
        _ => {}
    }
}

fn main() {}

I expected to see this happen:

Instead, this happened:

warning: function `test` is never used
 --> src/main.rs:1:4
  |
1 | fn test(s: &[u8]) {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: you seem to be trying to use `match` for an equality check. Consider using `if`
 --> src/main.rs:2:5
  |
2 | /     match &s[0..3] {
3 | |         b"hello" => {}
4 | |         _ => {}
5 | |     }
  | |_____^ help: try: `if s[0..3] == b"hello" {}`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
  = note: `#[warn(clippy::single_match)]` on by default

warning: `lint` (bin "lint" test) generated 2 warnings (run `cargo clippy --fix --bin "lint" --tests` to apply 1 suggestion)
warning: failed to automatically apply fixes suggested by rustc to crate `lint`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0277]: can't compare `[u8]` with `&[u8; 5]`
 --> src/main.rs:2:16
  |
2 |     if s[0..3] == b"hello" {}
  |                ^^ no implementation for `[u8] == &[u8; 5]`
  |
  = help: the trait `std::cmp::PartialEq<&[u8; 5]>` is not implemented for `[u8]`
help: consider dereferencing here
  |
2 |     if s[0..3] == *b"hello" {}
  |                   +

Version

rustc 1.80.0-nightly (79734f1db 2024-05-02)
binary: rustc
commit-hash: 79734f1db8dbe322192dea32c0f6b80ab14c4c1d
commit-date: 2024-05-02
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Additional Labels

No response

@matthiaskrgr matthiaskrgr added 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 labels May 3, 2024
@matthiaskrgr
Copy link
Member Author

Same problem with single_match_else

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

1 participant