Check for can_have_side_effects()
and in_external_macro()
inside suggest_missing_semicolon()
This commit is contained in:
parent
bf0193d580
commit
6afaffb9c2
@ -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);
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user