Skip to content

Commit e4abe76

Browse files
Auto merge of #146121 - Muscraft:filter-suggestion-parts, r=<try>
fix: Filter suggestion parts that match existing code try-job: aarch64-apple
2 parents 51ff895 + f696cd8 commit e4abe76

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ impl CodeSuggestion {
378378
})
379379
.cloned()
380380
.filter_map(|mut substitution| {
381+
// Account for cases where we are suggesting the same code that's already
382+
// there. This shouldn't happen often, but in some cases for multipart
383+
// suggestions it's much easier to handle it here than in the origin.
384+
substitution.parts.retain(|p| is_different(sm, &p.snippet, p.span));
385+
381386
// Assumption: all spans are in the same file, and all spans
382387
// are disjoint. Sort in ascending order.
383388
substitution.parts.sort_by_key(|part| part.span.lo());
@@ -470,16 +475,12 @@ impl CodeSuggestion {
470475
_ => 1,
471476
})
472477
.sum();
473-
if !is_different(sm, &part.snippet, part.span) {
474-
// Account for cases where we are suggesting the same code that's already
475-
// there. This shouldn't happen often, but in some cases for multipart
476-
// suggestions it's much easier to handle it here than in the origin.
477-
} else {
478-
line_highlight.push(SubstitutionHighlight {
479-
start: (cur_lo.col.0 as isize + acc) as usize,
480-
end: (cur_lo.col.0 as isize + acc + len) as usize,
481-
});
482-
}
478+
479+
line_highlight.push(SubstitutionHighlight {
480+
start: (cur_lo.col.0 as isize + acc) as usize,
481+
end: (cur_lo.col.0 as isize + acc + len) as usize,
482+
});
483+
483484
buf.push_str(&part.snippet);
484485
let cur_hi = sm.lookup_char_pos(part.span.hi());
485486
// Account for the difference between the width of the current code and the

src/tools/clippy/tests/ui/bool_assert_comparison.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,8 @@ LL | assert_eq!(a!(), true);
272272
|
273273
help: replace it with `assert!(..)`
274274
|
275-
LL | true
276-
...
277-
LL |
278-
LL ~ assert!(a!());
275+
LL - assert_eq!(a!(), true);
276+
LL + assert!(a!());
279277
|
280278

281279
error: used `assert_eq!` with a literal bool
@@ -286,10 +284,8 @@ LL | assert_eq!(true, b!());
286284
|
287285
help: replace it with `assert!(..)`
288286
|
289-
LL | true
290-
...
291-
LL |
292-
LL ~ assert!(b!());
287+
LL - assert_eq!(true, b!());
288+
LL + assert!(b!());
293289
|
294290

295291
error: used `debug_assert_eq!` with a literal bool

0 commit comments

Comments
 (0)