diff options
| author | bors <bors@rust-lang.org> | 2023-11-06 18:46:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-06 18:46:04 +0000 |
| commit | fb61292105708ea45cf5a4ed596dbbd54c8ed429 (patch) | |
| tree | c9c32c9269eb6f166211bed9ffdc54939f960711 /tests | |
| parent | aea82b268a7680b736be00e837eb8e32bc42a2da (diff) | |
| parent | 4b7aacaa4f5b2a5ceb05584f18b1a20f2572efa0 (diff) | |
| download | rust-fb61292105708ea45cf5a4ed596dbbd54c8ed429.tar.gz rust-fb61292105708ea45cf5a4ed596dbbd54c8ed429.zip | |
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.
Diffstat (limited to 'tests')
3 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/binop/false-binop-caused-by-missing-semi.fixed b/tests/ui/binop/false-binop-caused-by-missing-semi.fixed new file mode 100644 index 00000000000..b47372c9064 --- /dev/null +++ b/tests/ui/binop/false-binop-caused-by-missing-semi.fixed @@ -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}"); +} diff --git a/tests/ui/binop/false-binop-caused-by-missing-semi.rs b/tests/ui/binop/false-binop-caused-by-missing-semi.rs new file mode 100644 index 00000000000..14671de7e51 --- /dev/null +++ b/tests/ui/binop/false-binop-caused-by-missing-semi.rs @@ -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}"); +} diff --git a/tests/ui/binop/false-binop-caused-by-missing-semi.stderr b/tests/ui/binop/false-binop-caused-by-missing-semi.stderr new file mode 100644 index 00000000000..fca042b1c57 --- /dev/null +++ b/tests/ui/binop/false-binop-caused-by-missing-semi.stderr @@ -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`. |
