Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,18 @@ 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| {
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 let Ok(suggestions) = &mut self.suggestions {
suggestions.push(suggestion);
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down