Skip to content

Commit 12c7832

Browse files
committed
Silence redundant error on typo resulting on binop
1 parent 231f935 commit 12c7832

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394394
";".to_string(),
395395
Applicability::MaybeIncorrect,
396396
);
397+
if let hir::Node::Expr(expr) = self.tcx.hir().get_parent(expr.hir_id)
398+
&& let hir::ExprKind::Assign(..) = expr.kind
399+
{
400+
// We defer to the later error produced by `check_lhs_assignable`.
401+
err.delay_as_bug();
402+
}
397403
}
398404

399405
let suggest_deref_binop =
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-rustfix
2+
fn foo() {}
3+
fn main() {
4+
let mut y = 42;
5+
let x = &mut y;
6+
foo();
7+
*x = 0; //~ ERROR invalid left-hand side of assignment
8+
let _ = x;
9+
println!("{y}");
10+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// run-rustfix
12
fn foo() {}
23
fn main() {
34
let mut y = 42;
45
let x = &mut y;
56
foo()
67
*x = 0; //~ ERROR invalid left-hand side of assignment
7-
//~^ ERROR cannot multiply `()` by `&mut {integer}`
8+
let _ = x;
89
println!("{y}");
910
}
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
error[E0369]: cannot multiply `()` by `&mut {integer}`
2-
--> $DIR/false-binop-caused-by-missing-semi.rs:6:5
3-
|
4-
LL | foo()
5-
| ----- ()
6-
LL | *x = 0;
7-
| ^- &mut {integer}
8-
|
9-
help: you might have meant to write a semicolon here
10-
|
11-
LL | foo();
12-
| +
13-
141
error[E0070]: invalid left-hand side of assignment
15-
--> $DIR/false-binop-caused-by-missing-semi.rs:6:8
2+
--> $DIR/false-binop-caused-by-missing-semi.rs:7:8
163
|
174
LL | / foo()
185
LL | | *x = 0;
@@ -25,7 +12,6 @@ help: you might have meant to write a semicolon here
2512
LL | foo();
2613
| +
2714

28-
error: aborting due to 2 previous errors
15+
error: aborting due to previous error
2916

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

0 commit comments

Comments
 (0)