From 4909258ae885a3762b6202f9f57a54d756b927ec Mon Sep 17 00:00:00 2001 From: long-long-float Date: Thu, 25 Jan 2024 00:12:50 +0900 Subject: [PATCH] Check in push_suggestion --- compiler/rustc_errors/src/diagnostic.rs | 9 +++++++++ compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 5 ----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 8ad4925cff2..b37aa4cf7c0 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -519,6 +519,15 @@ pub fn disable_suggestions(&mut self) -> &mut Self { /// Helper for pushing to `self.suggestions`, if available (not disable). fn push_suggestion(&mut self, suggestion: CodeSuggestion) { + let in_derive = suggestion + .substitutions + .iter() + .any(|subst| subst.parts.iter().any(|part| part.span.in_derive_expansion())); + if in_derive { + // Ignore if spans is from derive macro. + return; + } + if let Ok(suggestions) = &mut self.suggestions { suggestions.push(suggestion); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index aeab3629ece..5395ffda1d1 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -2698,11 +2698,6 @@ pub(crate) fn suggest_cast( return false; } - if expr.span.in_derive_expansion() { - // Ignore if span is from derive macro. - return false; - } - let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) else { return false; };