Skip to content

Commit

Permalink
Silence redundant error on typo resulting on binop
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 27, 2023
1 parent 231f935 commit 12c7832
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
";".to_string(),
Applicability::MaybeIncorrect,
);
if let hir::Node::Expr(expr) = self.tcx.hir().get_parent(expr.hir_id)
&& let hir::ExprKind::Assign(..) = expr.kind
{
// We defer to the later error produced by `check_lhs_assignable`.
err.delay_as_bug();
}
}

let suggest_deref_binop =
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/binop/false-binop-caused-by-missing-semi.fixed
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}");
}
3 changes: 2 additions & 1 deletion tests/ui/binop/false-binop-caused-by-missing-semi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +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
//~^ ERROR cannot multiply `()` by `&mut {integer}`
let _ = x;
println!("{y}");
}
20 changes: 3 additions & 17 deletions tests/ui/binop/false-binop-caused-by-missing-semi.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
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
--> $DIR/false-binop-caused-by-missing-semi.rs:7:8
|
LL | / foo()
LL | | *x = 0;
Expand All @@ -25,7 +12,6 @@ help: you might have meant to write a semicolon here
LL | foo();
| +

error: aborting due to 2 previous errors
error: aborting due to previous error

Some errors have detailed explanations: E0070, E0369.
For more information about an error, try `rustc --explain E0070`.
For more information about this error, try `rustc --explain E0070`.

0 comments on commit 12c7832

Please sign in to comment.