Skip to content

Commit 8cbd78c

Browse files
committed
Add test suggest-with-let-issue-145548
Signed-off-by: xizheyin <[email protected]>
1 parent 425a9c0 commit 8cbd78c

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// `Some(x) = Some(1)` is treated as a let statement/expr,
2+
// so we should not suggest to add `let ... else{...}`
3+
4+
fn foo1(){
5+
let x = 2;
6+
Some(x) = Some(1); //~ ERROR refutable pattern in local binding [E0005]
7+
}
8+
9+
fn foo2(){
10+
let x = 2;
11+
let Some(x) = Some(1); //~ ERROR refutable pattern in local binding [E0005]
12+
}
13+
14+
fn foo3(){
15+
Some(()) = Some(()); //~ ERROR refutable pattern in local binding [E0005]
16+
}
17+
18+
fn main() {}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error[E0005]: refutable pattern in local binding
2+
--> $DIR/suggest-with-let-issue-145548.rs:6:5
3+
|
4+
LL | Some(x) = Some(1);
5+
| ^^^^^^^ pattern `None` not covered
6+
|
7+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
8+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
9+
= note: the matched value is of type `Option<i32>`
10+
help: you might want to use `let else` to handle the variant that isn't matched
11+
|
12+
LL | Some(x) = Some(1) else { todo!() };
13+
| ++++++++++++++++
14+
15+
error[E0005]: refutable pattern in local binding
16+
--> $DIR/suggest-with-let-issue-145548.rs:11:9
17+
|
18+
LL | let Some(x) = Some(1);
19+
| ^^^^^^^ pattern `None` not covered
20+
|
21+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
22+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
23+
= note: the matched value is of type `Option<i32>`
24+
help: you might want to use `let else` to handle the variant that isn't matched
25+
|
26+
LL | let Some(x) = Some(1) else { todo!() };
27+
| ++++++++++++++++
28+
29+
error[E0005]: refutable pattern in local binding
30+
--> $DIR/suggest-with-let-issue-145548.rs:15:5
31+
|
32+
LL | Some(()) = Some(());
33+
| ^^^^^^^^ pattern `None` not covered
34+
|
35+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
36+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
37+
= note: the matched value is of type `Option<()>`
38+
help: you might want to use `if let` to ignore the variant that isn't matched
39+
|
40+
LL | if Some(()) = Some(()) { todo!() };
41+
| ++ +++++++++++
42+
43+
error: aborting due to 3 previous errors
44+
45+
For more information about this error, try `rustc --explain E0005`.

0 commit comments

Comments
 (0)