From 6afaffb9c2a9e84858e552286858584bd328413e Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Mon, 30 May 2022 20:35:51 +0000 Subject: [PATCH] Check for `can_have_side_effects()` and `in_external_macro()` inside `suggest_missing_semicolon()` --- compiler/rustc_typeck/src/check/coercion.rs | 2 -- .../rustc_typeck/src/check/fn_ctxt/suggestions.rs | 13 ++++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 407a0267f1358..d6a8659d54b58 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -1579,8 +1579,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { if let Some(expr) = expression && let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_, _, body_id, ..), .. }) = parent && !matches!(fcx.tcx.hir().get(body_id.hir_id), hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Block(..), .. })) - && expr.can_have_side_effects() - && !in_external_macro(fcx.tcx.sess, expr.span) { fcx.suggest_missing_semicolon(&mut err, expr, expected, true); } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 40b667beaac0a..76add2fb9c285 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -46,12 +46,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { blk_id: hir::HirId, ) -> bool { let expr = expr.peel_drop_temps(); - // If the expression is from an external macro, then do not suggest - // adding a semicolon, because there's nowhere to put it. - // See issue #81943. - if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) { - self.suggest_missing_semicolon(err, expr, expected, false); - } + self.suggest_missing_semicolon(err, expr, expected, false); let mut pointing_at_return_type = false; if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) { let fn_id = self.tcx.hir().get_return_block(blk_id).unwrap(); @@ -493,7 +488,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ExprKind::If(..) | ExprKind::Match(..) | ExprKind::Block(..) - if expression.can_have_side_effects() => + if expression.can_have_side_effects() + // If the expression is from an external macro, then do not suggest + // adding a semicolon, because there's nowhere to put it. + // See issue #81943. + && !in_external_macro(self.tcx.sess, expression.span) => { if needs_block { err.multipart_suggestion(