-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error if the user tries to do assignment ... else
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![feature(let_else)] | ||
#[derive(Debug)] | ||
enum Foo { | ||
Done, | ||
Nested(Option<&'static Foo>), | ||
} | ||
|
||
fn walk(mut value: &Foo) { | ||
loop { | ||
println!("{:?}", value); | ||
&Foo::Nested(Some(value)) = value else { break }; //~ ERROR invalid left-hand side of assignment | ||
//~^ERROR <assignment> ... else { ... } is not allowed | ||
} | ||
} | ||
|
||
fn main() { | ||
walk(&Foo::Done); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: <assignment> ... else { ... } is not allowed | ||
--> $DIR/let-else-destructuring.rs:11:9 | ||
| | ||
LL | &Foo::Nested(Some(value)) = value else { break }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0070]: invalid left-hand side of assignment | ||
--> $DIR/let-else-destructuring.rs:11:35 | ||
| | ||
LL | &Foo::Nested(Some(value)) = value else { break }; | ||
| ------------------------- ^ | ||
| | | ||
| cannot assign to this expression | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0070`. |