-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
.
Lint Name
unnested_or_patterns
Reproducer
I tried this code:
It looks like in the suggestion, we replace macros with actual code and thus produce invalid suggestions...?
// check-pass
// Test various exhaustive matches for `X..`, `..=X` and `..X` ranges.
#![feature(exclusive_range_pattern)]
fn main() {}
macro_rules! m {
($s:expr, $($t:tt)+) => {
match $s { $($t)+ => {} }
}
}
macro_rules! test_int {
($s:expr, $min:path, $max:path) => {
m!($s, $min..);
m!($s, $min..5 | 5..);
m!($s, ..5 | 5..);
m!($s, ..=4 | 5..);
m!($s, ..=$max);
m!($s, ..$max | $max);
m!(($s, true), (..5 | 5.., true) | (u8::MIN.., false));
}
}
fn unsigned_int() {
test_int!(0u8, u8::MIN, u8::MAX);
}
I saw this happen:
cargo clippy --fix -- -Aclippy::all -Wclippy::unnested_or_patterns
Checking clpy v0.1.0 (/tmp/clpy)
warning: failed to automatically apply fixes suggested by rustc to crate `clpy`
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/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[E0308]: mismatched types
--> src/main.rs:23:45
|
23 | m!(($s, true), (..5 | 5.., true) | (u128::MIN.., false));
| ---------- ^^^^^^^^^ expected `u8`, found `u128`
| |
| this expression has type `(u8, bool)`
...
28 | test_int!(0u8, u8::MIN, u8::MAX);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> src/main.rs:23:45
|
23 | m!(($s, true), (..5 | 5.., true) | (u128::MIN.., false));
| ---------- ^^^^^^^^^ expected `u16`, found `u128`
| |
| this expression has type `(u16, bool)`
...
29 | test_int!(0u16, u16::MIN, u16::MAX);
| ----------------------------------- in this macro invocation
|
= note: this error originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> src/main.rs:23:45
|
23 | m!(($s, true), (..5 | 5.., true) | (u128::MIN.., false));
| ---------- ^^^^^^^^^ expected `u32`, found `u128`
| |
| this expression has type `(u32, bool)`
...
30 | test_int!(0u32, u32::MIN, u32::MAX);
| ----------------------------------- in this macro invocation
|
= note: this error originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> src/main.rs:23:45
|
23 | m!(($s, true), (..5 | 5.., true) | (u128::MIN.., false));
| ---------- ^^^^^^^^^ expected `u64`, found `u128`
| |
| this expression has type `(u64, bool)`
...
31 | test_int!(0u64, u64::MIN, u64::MAX);
| ----------------------------------- in this macro invocation
|
= note: this error originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.
Original diagnostics will follow.
warning: unnested or-patterns
--> src/main.rs:23:24
|
23 | m!(($s, true), (..5, true) | (5.., true) | ($min.., false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
28 | test_int!(0u8, u8::MIN, u8::MAX);
| -------------------------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
= note: requested on the command line with `-W clippy::unnested-or-patterns`
= note: this warning originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
help: nest the patterns
|
23 | m!(($s, true), (..5 | 5.., true) | (u8::MIN.., false));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: unnested or-patterns
--> src/main.rs:23:24
|
23 | m!(($s, true), (..5, true) | (5.., true) | ($min.., false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
29 | test_int!(0u16, u16::MIN, u16::MAX);
| ----------------------------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
= note: this warning originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
help: nest the patterns
|
23 | m!(($s, true), (..5 | 5.., true) | (u16::MIN.., false));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: unnested or-patterns
--> src/main.rs:23:24
|
23 | m!(($s, true), (..5, true) | (5.., true) | ($min.., false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
30 | test_int!(0u32, u32::MIN, u32::MAX);
| ----------------------------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
= note: this warning originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
help: nest the patterns
|
23 | m!(($s, true), (..5 | 5.., true) | (u32::MIN.., false));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: unnested or-patterns
--> src/main.rs:23:24
|
23 | m!(($s, true), (..5, true) | (5.., true) | ($min.., false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
31 | test_int!(0u64, u64::MIN, u64::MAX);
| ----------------------------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
= note: this warning originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
help: nest the patterns
|
23 | m!(($s, true), (..5 | 5.., true) | (u64::MIN.., false));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: unnested or-patterns
--> src/main.rs:23:24
|
23 | m!(($s, true), (..5, true) | (5.., true) | ($min.., false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
32 | test_int!(0u128, u128::MIN, u128::MAX);
| -------------------------------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
= note: this warning originates in the macro `test_int` (in Nightly builds, run with -Z macro-backtrace for more info)
help: nest the patterns
|
23 | m!(($s, true), (..5 | 5.., true) | (u128::MIN.., false));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: function `unsigned_int` is never used
--> src/main.rs:27:4
|
27 | fn unsigned_int() {
| ^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `clpy` (bin "clpy") generated 6 warnings (6 duplicates)
warning: `clpy` (bin "clpy" test) generated 6 warnings (run `cargo fix --bin "clpy" --tests` to apply 5 suggestions)
Finished dev [unoptimized + debuginfo] target(s) in 0.60s
I expected to see this happen:
Version
rustc 1.67.0-nightly (c5d82ed7a 2022-11-19)
binary: rustc
commit-hash: c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b
commit-date: 2022-11-19
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
No response
fmease
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied