Adds additional tests for lint

This commit is contained in:
1nF0rmed 2021-10-10 14:46:28 +05:30
parent fc32425521
commit 1080f6c70c
2 changed files with 62 additions and 1 deletions

View file

@ -72,4 +72,46 @@ mod ice_3719 {
}
}
mod issue_7740 {
macro_rules! foobar_variant(
($idx:expr) => (FooBar::get($idx).unwrap())
);
enum FooBar {
Foo,
Bar,
FooBar,
BarFoo,
}
impl FooBar {
fn get(idx: u8) -> Option<&'static Self> {
match idx {
0 => Some(&FooBar::Foo),
1 => Some(&FooBar::Bar),
2 => Some(&FooBar::FooBar),
3 => Some(&FooBar::BarFoo),
_ => None,
}
}
}
fn issue_7740() {
// Issue #7740
match foobar_variant!(0) {
&FooBar::Foo => println!("Foo"),
&FooBar::Bar => println!("Bar"),
&FooBar::FooBar => println!("FooBar"),
_ => println!("Wild"),
}
// This shouldn't trigger
if let &FooBar::BarFoo = foobar_variant!(3) {
println!("BarFoo");
} else {
println!("Wild");
}
}
}
fn main() {}

View file

@ -45,5 +45,24 @@ error: redundant pattern matching, consider using `is_none()`
LL | if let &None = &b {
| -------^^^^^----- help: try this: `if b.is_none()`
error: aborting due to 4 previous errors
error: you don't need to add `&` to all patterns
--> $DIR/match_ref_pats.rs:101:9
|
LL | / match foobar_variant!(0) {
LL | | &FooBar::Foo => println!("Foo"),
LL | | &FooBar::Bar => println!("Bar"),
LL | | &FooBar::FooBar => println!("FooBar"),
LL | | _ => println!("Wild"),
LL | | }
| |_________^
|
help: instead of prefixing all patterns with `&`, you can dereference the expression
|
LL ~ match *foobar_variant!(0) {
LL ~ FooBar::Foo => println!("Foo"),
LL ~ FooBar::Bar => println!("Bar"),
LL ~ FooBar::FooBar => println!("FooBar"),
|
error: aborting due to 5 previous errors