diff options
| author | yukang <moorekang@gmail.com> | 2025-01-17 12:15:25 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2025-02-22 11:50:50 +0800 |
| commit | 774ab462d692615d65dc79bb36685ac5cfebd7d4 (patch) | |
| tree | bfe14022de1859afe66775945722e5902ad527d2 | |
| parent | d6d9c2e7516c687553480a4e171f89dfc22009dd (diff) | |
| download | rust-774ab462d692615d65dc79bb36685ac5cfebd7d4.tar.gz rust-774ab462d692615d65dc79bb36685ac5cfebd7d4.zip | |
code cleanup and do not suggest for external macro except we get better solution
| -rw-r--r-- | compiler/rustc_hir_typeck/src/coercion.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 11 |
2 files changed, 6 insertions, 9 deletions
diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 2217eb33062..afa7175238c 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1883,9 +1883,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { fcx.err_ctxt().report_mismatched_types(cause, fcx.param_env, expected, found, ty_err); let due_to_block = matches!(fcx.tcx.hir_node(block_or_return_id), hir::Node::Block(..)); - - let parent_id = fcx.tcx.parent_hir_id(block_or_return_id); - let parent = fcx.tcx.hir_node(parent_id); + let parent = fcx.tcx.parent_hir_node(block_or_return_id); if let Some(expr) = expression && let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure { body, .. }), diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index a31abef4375..8f2665212b8 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -790,16 +790,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } } - ExprKind::Path(..) | ExprKind::Lit(_) if parent_is_closure => { + ExprKind::Path(..) | ExprKind::Lit(_) + if parent_is_closure + && !expression.span.in_external_macro(self.tcx.sess.source_map()) => + { err.span_suggestion_verbose( expression.span.shrink_to_lo(), "consider ignoring the value", "_ = ", - if in_external_macro(self.tcx.sess, expression.span) { - Applicability::MaybeIncorrect - } else { - Applicability::MachineApplicable - }, + Applicability::MachineApplicable, ); } _ => (), |
