]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/usefulness/issue-31561.stderr
Suggest `if let`/`let_else` for refutable pat in `let`
[rust.git] / src / test / ui / pattern / usefulness / issue-31561.stderr
1 error[E0005]: refutable pattern in local binding: `Bar` and `Baz` not covered
2   --> $DIR/issue-31561.rs:8:9
3    |
4 LL |     let Thing::Foo(y) = Thing::Foo(1);
5    |         ^^^^^^^^^^^^^ patterns `Bar` and `Baz` 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/ch18-02-refutability.html
9 note: `Thing` defined here
10   --> $DIR/issue-31561.rs:3:5
11    |
12 LL | enum Thing {
13    |      -----
14 LL |     Foo(u8),
15 LL |     Bar,
16    |     ^^^ not covered
17 LL |     Baz
18    |     ^^^ not covered
19    = note: the matched value is of type `Thing`
20 help: you might want to use `if let` to ignore the variants that aren't matched
21    |
22 LL |     let y = if let Thing::Foo(y) = Thing::Foo(1) { y } else { todo!() };
23    |     ++++++++++                                   ++++++++++++++++++++++
24 help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
25    |
26 LL |     let Thing::Foo(y) = Thing::Foo(1) else { todo!() };
27    |                                       ++++++++++++++++
28
29 error: aborting due to previous error
30
31 For more information about this error, try `rustc --explain E0005`.