diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2022-05-30 20:35:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-30 20:35:51 +0000 |
| commit | 6afaffb9c2a9e84858e552286858584bd328413e (patch) | |
| tree | 21bb3390a24bdc93a287d439c49a5e39eddc8e56 | |
| parent | bf0193d5801c7155f4fb6d3bd546a2cdd762cc3c (diff) | |
| download | rust-6afaffb9c2a9e84858e552286858584bd328413e.tar.gz rust-6afaffb9c2a9e84858e552286858584bd328413e.zip | |
Check for `can_have_side_effects()` and `in_external_macro()` inside `suggest_missing_semicolon()`
| -rw-r--r-- | compiler/rustc_typeck/src/check/coercion.rs | 2 | ||||
| -rw-r--r-- | compiler/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 407a0267f13..d6a8659d54b 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 40b667beaac..76add2fb9c2 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( |
