Skip to content

Commit 6afaffb

Browse files
Check for can_have_side_effects() and in_external_macro() inside suggest_missing_semicolon()
1 parent bf0193d commit 6afaffb

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

compiler/rustc_typeck/src/check/coercion.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15791579
if let Some(expr) = expression
15801580
&& let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_, _, body_id, ..), .. }) = parent
15811581
&& !matches!(fcx.tcx.hir().get(body_id.hir_id), hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Block(..), .. }))
1582-
&& expr.can_have_side_effects()
1583-
&& !in_external_macro(fcx.tcx.sess, expr.span)
15841582
{
15851583
fcx.suggest_missing_semicolon(&mut err, expr, expected, true);
15861584
}

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4646
blk_id: hir::HirId,
4747
) -> bool {
4848
let expr = expr.peel_drop_temps();
49-
// If the expression is from an external macro, then do not suggest
50-
// adding a semicolon, because there's nowhere to put it.
51-
// See issue #81943.
52-
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) {
53-
self.suggest_missing_semicolon(err, expr, expected, false);
54-
}
49+
self.suggest_missing_semicolon(err, expr, expected, false);
5550
let mut pointing_at_return_type = false;
5651
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
5752
let fn_id = self.tcx.hir().get_return_block(blk_id).unwrap();
@@ -493,7 +488,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
493488
| ExprKind::If(..)
494489
| ExprKind::Match(..)
495490
| ExprKind::Block(..)
496-
if expression.can_have_side_effects() =>
491+
if expression.can_have_side_effects()
492+
// If the expression is from an external macro, then do not suggest
493+
// adding a semicolon, because there's nowhere to put it.
494+
// See issue #81943.
495+
&& !in_external_macro(self.tcx.sess, expression.span) =>
497496
{
498497
if needs_block {
499498
err.multipart_suggestion(

0 commit comments

Comments
 (0)