Skip to content

Commit 4e7941c

Browse files
Check with overlaps_or_adjacent
1 parent 8cc5084 commit 4e7941c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,13 @@ impl Diagnostic {
519519

520520
/// Helper for pushing to `self.suggestions`, if available (not disable).
521521
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
522-
let in_derive = suggestion
523-
.substitutions
524-
.iter()
525-
.any(|subst| subst.parts.iter().any(|part| part.span.in_derive_expansion()));
522+
let in_derive = suggestion.substitutions.iter().any(|subst| {
523+
subst.parts.iter().any(|part| {
524+
let span = part.span;
525+
let call_site = span.ctxt().outer_expn_data().call_site;
526+
span.in_derive_expansion() && span.overlaps_or_adjacent(call_site)
527+
})
528+
});
526529
if in_derive {
527530
// Ignore if spans is from derive macro.
528531
return;

compiler/rustc_span/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ impl Span {
627627
span.lo < other.hi && other.lo < span.hi
628628
}
629629

630+
/// Returns `true` if `self` touches or adjoins `other`.
631+
pub fn overlaps_or_adjacent(self, other: Span) -> bool {
632+
let span = self.data();
633+
let other = other.data();
634+
span.lo <= other.hi && other.lo <= span.hi
635+
}
636+
630637
/// Returns `true` if the spans are equal with regards to the source text.
631638
///
632639
/// Use this instead of `==` when either span could be generated code,

0 commit comments

Comments
 (0)