Skip to content

Commit ab71ee7

Browse files
committed
Auto merge of #123736 - compiler-errors:multiply-on-rhs, r=estebank
Don't delay a bug if we suggest adding a semicolon to the RHS of an assign operator It only makes sense to delay a bug based on the assumption that "[we] defer to the later error produced by `check_lhs_assignable`" *if* the expression we're erroring actually is an LHS; otherwise, we should still report the error since it's both useful and required. Fixes #123722
2 parents 6bc9dcd + 889ca7e commit ab71ee7

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

compiler/rustc_hir_typeck/src/op.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382382
(err, output_def_id)
383383
}
384384
};
385-
if self.check_for_missing_semi(expr, &mut err)
386-
&& let hir::Node::Expr(expr) = self.tcx.parent_hir_node(expr.hir_id)
387-
&& let hir::ExprKind::Assign(..) = expr.kind
385+
386+
// Try to suggest a semicolon if it's `A \n *B` where `B` is a place expr
387+
let maybe_missing_semi = self.check_for_missing_semi(expr, &mut err);
388+
389+
// We defer to the later error produced by `check_lhs_assignable`.
390+
// We only downgrade this if it's the LHS, though.
391+
if maybe_missing_semi
392+
&& let hir::Node::Expr(parent) = self.tcx.parent_hir_node(expr.hir_id)
393+
&& let hir::ExprKind::Assign(lhs, _, _) = parent.kind
394+
&& lhs.hir_id == expr.hir_id
388395
{
389-
// We defer to the later error produced by `check_lhs_assignable`.
390396
err.downgrade_to_delayed_bug();
391397
}
392398

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub fn test(y: &i32) {
2+
let x;
3+
x = ()
4+
*y
5+
//~^ ERROR cannot multiply `()` by `&i32`
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0369]: cannot multiply `()` by `&i32`
2+
--> $DIR/multiply-is-deref-on-rhs.rs:4:5
3+
|
4+
LL | x = ()
5+
| -- ()
6+
LL | *y
7+
| ^- &i32
8+
|
9+
help: you might have meant to write a semicolon here
10+
|
11+
LL | x = ();
12+
| +
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0369`.

0 commit comments

Comments
 (0)