-
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.
Auto merge of #117292 - estebank:issue-80446, r=davidtwco
Detect misparsed binop caused by missing semi When encountering ```rust foo() *bar = baz; ``` We currently emit potentially two errors, one for the return type of `foo` not being multiplicative by the type of `bar`, and another for `foo() * bar` not being assignable. We now check for this case and suggest adding a semicolon in the right place and emit only a single error. Fix #80446.
- Loading branch information
Showing
5 changed files
with
71 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
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,10 @@ | ||
// run-rustfix | ||
fn foo() {} | ||
fn main() { | ||
let mut y = 42; | ||
let x = &mut y; | ||
foo(); | ||
*x = 0; //~ ERROR invalid left-hand side of assignment | ||
let _ = x; | ||
println!("{y}"); | ||
} |
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,10 @@ | ||
// run-rustfix | ||
fn foo() {} | ||
fn main() { | ||
let mut y = 42; | ||
let x = &mut y; | ||
foo() | ||
*x = 0; //~ ERROR invalid left-hand side of assignment | ||
let _ = x; | ||
println!("{y}"); | ||
} |
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[E0070]: invalid left-hand side of assignment | ||
--> $DIR/false-binop-caused-by-missing-semi.rs:7:8 | ||
| | ||
LL | / foo() | ||
LL | | *x = 0; | ||
| | - ^ | ||
| |______| | ||
| cannot assign to this expression | ||
| | ||
help: you might have meant to write a semicolon here | ||
| | ||
LL | foo(); | ||
| + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0070`. |