From 4909258ae885a3762b6202f9f57a54d756b927ec Mon Sep 17 00:00:00 2001 From: long-long-float Date: Thu, 25 Jan 2024 00:12:50 +0900 Subject: Check in push_suggestion --- compiler/rustc_errors/src/diagnostic.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'compiler/rustc_errors/src') 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 @@ impl Diagnostic { /// 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); } -- cgit 1.4.1-3-g733a5 From 4e7941c2c57441d2fe92a21c2951cab2926f5656 Mon Sep 17 00:00:00 2001 From: long-long-float Date: Fri, 9 Feb 2024 01:03:38 +0900 Subject: Check with overlaps_or_adjacent --- compiler/rustc_errors/src/diagnostic.rs | 11 +++++++---- compiler/rustc_span/src/lib.rs | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index b37aa4cf7c0..026b0222665 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -519,10 +519,13 @@ impl Diagnostic { /// 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())); + let in_derive = suggestion.substitutions.iter().any(|subst| { + subst.parts.iter().any(|part| { + let span = part.span; + let call_site = span.ctxt().outer_expn_data().call_site; + span.in_derive_expansion() && span.overlaps_or_adjacent(call_site) + }) + }); if in_derive { // Ignore if spans is from derive macro. return; diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index ea6766ea583..228d33bdba2 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -627,6 +627,13 @@ impl Span { span.lo < other.hi && other.lo < span.hi } + /// Returns `true` if `self` touches or adjoins `other`. + pub fn overlaps_or_adjacent(self, other: Span) -> bool { + let span = self.data(); + let other = other.data(); + span.lo <= other.hi && other.lo <= span.hi + } + /// Returns `true` if the spans are equal with regards to the source text. /// /// Use this instead of `==` when either span could be generated code, -- cgit 1.4.1-3-g733a5 From 1e59e662258fc301dd7b396ac0e3686568a71164 Mon Sep 17 00:00:00 2001 From: long-long-float Date: Sun, 11 Feb 2024 02:43:55 +0900 Subject: Fix to use for loop --- compiler/rustc_errors/src/diagnostic.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 026b0222665..c48a8e12a00 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -519,16 +519,15 @@ impl Diagnostic { /// 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| { + for subst in &suggestion.substitutions { + for part in &subst.parts { let span = part.span; let call_site = span.ctxt().outer_expn_data().call_site; - span.in_derive_expansion() && span.overlaps_or_adjacent(call_site) - }) - }); - if in_derive { - // Ignore if spans is from derive macro. - return; + if span.in_derive_expansion() && span.overlaps_or_adjacent(call_site) { + // Ignore if spans is from derive macro. + return; + } + } } if let Ok(suggestions) = &mut self.suggestions { -- cgit 1.4.1-3-g733a5