Skip to content

Commit b7f3316

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

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// `Some(x) = Some(1)` is treated as a let statement,
2+
// so we should 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+
15+
fn main() {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0005`.

0 commit comments

Comments
 (0)