-
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.
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 multiplyiable 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. Fix #80446.
- Loading branch information
Showing
4 changed files
with
77 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,9 @@ | ||
fn foo() {} | ||
fn main() { | ||
let mut y = 42; | ||
let x = &mut y; | ||
foo() | ||
*x = 0; //~ ERROR invalid left-hand side of assignment | ||
//~^ ERROR cannot multiply `()` by `&mut {integer}` | ||
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,31 @@ | ||
error[E0369]: cannot multiply `()` by `&mut {integer}` | ||
--> $DIR/false-binop-caused-by-missing-semi.rs:6:5 | ||
| | ||
LL | foo() | ||
| ----- () | ||
LL | *x = 0; | ||
| ^- &mut {integer} | ||
| | ||
help: you might have meant to write a semicolon here | ||
| | ||
LL | foo(); | ||
| + | ||
|
||
error[E0070]: invalid left-hand side of assignment | ||
--> $DIR/false-binop-caused-by-missing-semi.rs:6: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 2 previous errors | ||
|
||
Some errors have detailed explanations: E0070, E0369. | ||
For more information about an error, try `rustc --explain E0070`. |