Skip to content

Don't delay a bug if we suggest adding a semicolon to the RHS of an assign operator #123736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(err, output_def_id)
}
};
if self.check_for_missing_semi(expr, &mut err)
&& let hir::Node::Expr(expr) = self.tcx.parent_hir_node(expr.hir_id)
&& let hir::ExprKind::Assign(..) = expr.kind

// Try to suggest a semicolon if it's `A \n *B` where `B` is a place expr
let maybe_missing_semi = self.check_for_missing_semi(expr, &mut err);

// We defer to the later error produced by `check_lhs_assignable`.
// We only downgrade this if it's the LHS, though.
if maybe_missing_semi
&& let hir::Node::Expr(parent) = self.tcx.parent_hir_node(expr.hir_id)
&& let hir::ExprKind::Assign(lhs, _, _) = parent.kind
&& lhs.hir_id == expr.hir_id
{
// We defer to the later error produced by `check_lhs_assignable`.
err.downgrade_to_delayed_bug();
}

Expand Down
8 changes: 8 additions & 0 deletions tests/ui/binop/multiply-is-deref-on-rhs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub fn test(y: &i32) {
let x;
x = ()
*y
//~^ ERROR cannot multiply `()` by `&i32`
}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/binop/multiply-is-deref-on-rhs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0369]: cannot multiply `()` by `&i32`
--> $DIR/multiply-is-deref-on-rhs.rs:4:5
|
LL | x = ()
| -- ()
LL | *y
| ^- &i32
|
help: you might have meant to write a semicolon here
|
LL | x = ();
| +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0369`.
Loading