mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-24 04:46:58 +00:00
Adds additional tests for lint
This commit is contained in:
parent
fc32425521
commit
1080f6c70c
@ -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() {}
|
fn main() {}
|
||||||
|
@ -45,5 +45,24 @@ error: redundant pattern matching, consider using `is_none()`
|
|||||||
LL | if let &None = &b {
|
LL | if let &None = &b {
|
||||||
| -------^^^^^----- help: try this: `if b.is_none()`
|
| -------^^^^^----- 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user