Fix single_match lint being emitted when it should not

This commit is contained in:
Guillaume Gomez 2024-11-30 22:42:27 +01:00
parent 650e0c8d3d
commit efe3fe9b8c
5 changed files with 85 additions and 22 deletions

View file

@ -17,7 +17,13 @@ fn single_match() {
};
let x = Some(1u8);
if let Some(y) = x { println!("{:?}", y) }
match x {
// Note the missing block braces.
// We suggest `if let Some(y) = x { .. }` because the macro
// is expanded before we can do anything.
Some(y) => println!("{:?}", y),
_ => (),
}
let z = (1u8, 1u8);
if let (2..=3, 7..=9) = z { dummy() };
@ -318,5 +324,25 @@ fn irrefutable_match() {
println!()
println!();
let mut x = vec![1i8];
// Should not lint.
match x.pop() {
// bla
Some(u) => println!("{u}"),
// more comments!
None => {},
}
// Should not lint.
match x.pop() {
// bla
Some(u) => {
// bla
println!("{u}");
},
// bla
None => {},
}
}

View file

@ -401,4 +401,24 @@ fn irrefutable_match() {
CONST_I32 => println!(),
_ => {},
}
let mut x = vec![1i8];
// Should not lint.
match x.pop() {
// bla
Some(u) => println!("{u}"),
// more comments!
None => {},
}
// Should not lint.
match x.pop() {
// bla
Some(u) => {
// bla
println!("{u}");
},
// bla
None => {},
}
}

View file

@ -18,18 +18,6 @@ LL + println!("{:?}", y);
LL ~ };
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> tests/ui/single_match.rs:23:5
|
LL | / match x {
LL | | // Note the missing block braces.
LL | | // We suggest `if let Some(y) = x { .. }` because the macro
LL | | // is expanded before we can do anything.
LL | | Some(y) => println!("{:?}", y),
LL | | _ => (),
LL | | }
| |_____^ help: try: `if let Some(y) = x { println!("{:?}", y) }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> tests/ui/single_match.rs:32:5
|
@ -279,7 +267,7 @@ LL | / match CONST_I32 {
LL | | CONST_I32 => println!(),
LL | | _ => {},
LL | | }
| |_____^ help: try: `println!()`
| |_____^ help: try: `println!();`
error: aborting due to 26 previous errors
error: aborting due to 25 previous errors