Skip to content

Commit

Permalink
Check for can_have_side_effects() and in_external_macro() inside …
Browse files Browse the repository at this point in the history
…`suggest_missing_semicolon()`
  • Loading branch information
ChayimFriedman2 authored May 30, 2022
1 parent bf0193d commit 6afaffb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6afaffb

Please sign in to comment.