File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 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 ( ) { }
Original file line number Diff line number Diff line change 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`.
You can’t perform that action at this time.
0 commit comments