Address review comments

Add: attempt to remove address of expressions from the scrutinee expression before adding references to the pattern
This commit is contained in:
Jason Newcomb 2021-01-14 14:26:26 -05:00
parent 8d7417d807
commit 85edd65bf6
No known key found for this signature in database
GPG key ID: DA59E8643A37ED06
5 changed files with 104 additions and 48 deletions

View file

@ -81,7 +81,8 @@ fn single_match_know_enum() {
}
}
fn issue_173() {
// issue #173
fn if_suggestion() {
let x = "test";
match x {
"test" => println!(),
@ -106,6 +107,18 @@ fn issue_173() {
FOO_C => println!(),
_ => (),
}
match &&x {
Foo::A => println!(),
_ => (),
}
let x = &x;
match &x {
Foo::A => println!(),
_ => (),
}
enum Bar {
A,
B,

View file

@ -1,4 +1,4 @@
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:8:5
|
LL | / match x {
@ -17,7 +17,7 @@ LL | println!("{:?}", y);
LL | };
|
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:16:5
|
LL | / match x {
@ -29,7 +29,7 @@ LL | | _ => (),
LL | | }
| |_____^ help: try this: `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`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:25:5
|
LL | / match z {
@ -38,7 +38,7 @@ LL | | _ => {},
LL | | };
| |_____^ help: try this: `if let (2..=3, 7..=9) = z { dummy() }`
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:54:5
|
LL | / match x {
@ -47,7 +47,7 @@ LL | | None => (),
LL | | };
| |_____^ help: try this: `if let Some(y) = x { dummy() }`
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:59:5
|
LL | / match y {
@ -56,7 +56,7 @@ LL | | Err(..) => (),
LL | | };
| |_____^ help: try this: `if let Ok(y) = y { dummy() }`
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:66:5
|
LL | / match c {
@ -65,8 +65,8 @@ LL | | Cow::Owned(..) => (),
LL | | };
| |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }`
error: you seem to be trying to use match for an equality check. Consider using `if`
--> $DIR/single_match.rs:86:5
error: you seem to be trying to use `match` for an equality check. Consider using `if`
--> $DIR/single_match.rs:87:5
|
LL | / match x {
LL | | "test" => println!(),
@ -74,8 +74,8 @@ LL | | _ => (),
LL | | }
| |_____^ help: try this: `if x == "test" { println!() }`
error: you seem to be trying to use match for an equality check. Consider using `if`
--> $DIR/single_match.rs:99:5
error: you seem to be trying to use `match` for an equality check. Consider using `if`
--> $DIR/single_match.rs:100:5
|
LL | / match x {
LL | | Foo::A => println!(),
@ -83,8 +83,8 @@ LL | | _ => (),
LL | | }
| |_____^ help: try this: `if x == Foo::A { println!() }`
error: you seem to be trying to use match for an equality check. Consider using `if`
--> $DIR/single_match.rs:105:5
error: you seem to be trying to use `match` for an equality check. Consider using `if`
--> $DIR/single_match.rs:106:5
|
LL | / match x {
LL | | FOO_C => println!(),
@ -92,8 +92,26 @@ LL | | _ => (),
LL | | }
| |_____^ help: try this: `if x == FOO_C { println!() }`
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:121:5
error: you seem to be trying to use `match` for an equality check. Consider using `if`
--> $DIR/single_match.rs:111:5
|
LL | / match &&x {
LL | | Foo::A => println!(),
LL | | _ => (),
LL | | }
| |_____^ help: try this: `if x == Foo::A { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
--> $DIR/single_match.rs:117:5
|
LL | / match &x {
LL | | Foo::A => println!(),
LL | | _ => (),
LL | | }
| |_____^ help: try this: `if x == &Foo::A { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match.rs:134:5
|
LL | / match x {
LL | | Bar::A => println!(),
@ -101,5 +119,5 @@ LL | | _ => (),
LL | | }
| |_____^ help: try this: `if let Bar::A = x { println!() }`
error: aborting due to 10 previous errors
error: aborting due to 12 previous errors

View file

@ -1,4 +1,4 @@
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match_else.rs:14:5
|
LL | / match ExprNode::Butterflies {
@ -19,7 +19,7 @@ LL | None
LL | }
|
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match_else.rs:70:5
|
LL | / match Some(1) {
@ -39,7 +39,7 @@ LL | return
LL | }
|
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match_else.rs:79:5
|
LL | / match Some(1) {