Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: Filter suggestion parts that match existing code
  • Loading branch information
Muscraft committed Sep 4, 2025
commit b307a1146b4af3b5808510e44a13f56f2b0252e9
21 changes: 11 additions & 10 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ impl CodeSuggestion {
"all spans must be disjoint",
);

// Account for cases where we are suggesting the same code that's already
// there. This shouldn't happen often, but in some cases for multipart
// suggestions it's much easier to handle it here than in the origin.
substitution.parts.retain(|p| is_different(sm, &p.snippet, p.span));

// Find the bounding span.
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;
let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?;
Expand Down Expand Up @@ -476,16 +481,12 @@ impl CodeSuggestion {
_ => 1,
})
.sum();
if !is_different(sm, &part.snippet, part.span) {
// Account for cases where we are suggesting the same code that's already
// there. This shouldn't happen often, but in some cases for multipart
// suggestions it's much easier to handle it here than in the origin.
} else {
line_highlight.push(SubstitutionHighlight {
start: (cur_lo.col.0 as isize + acc) as usize,
end: (cur_lo.col.0 as isize + acc + len) as usize,
});
}

line_highlight.push(SubstitutionHighlight {
start: (cur_lo.col.0 as isize + acc) as usize,
end: (cur_lo.col.0 as isize + acc + len) as usize,
});

buf.push_str(&part.snippet);
let cur_hi = sm.lookup_char_pos(part.span.hi());
// Account for the difference between the width of the current code and the
Expand Down
12 changes: 4 additions & 8 deletions src/tools/clippy/tests/ui/bool_assert_comparison.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,8 @@ LL | assert_eq!(a!(), true);
|
help: replace it with `assert!(..)`
|
LL | true
...
LL |
LL ~ assert!(a!());
LL - assert_eq!(a!(), true);
LL + assert!(a!());
|

error: used `assert_eq!` with a literal bool
Expand All @@ -286,10 +284,8 @@ LL | assert_eq!(true, b!());
|
help: replace it with `assert!(..)`
|
LL | true
...
LL |
LL ~ assert!(b!());
LL - assert_eq!(true, b!());
LL + assert!(b!());
|

error: used `debug_assert_eq!` with a literal bool
Expand Down
Loading