Skip to content

Commit b307a11

Browse files
committed
fix: Filter suggestion parts that match existing code
1 parent f196f50 commit b307a11

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
@@ -388,6 +388,11 @@ impl CodeSuggestion {
388388
"all spans must be disjoint",
389389
);
390390

391+
// Account for cases where we are suggesting the same code that's already
392+
// there. This shouldn't happen often, but in some cases for multipart
393+
// suggestions it's much easier to handle it here than in the origin.
394+
substitution.parts.retain(|p| is_different(sm, &p.snippet, p.span));
395+
391396
// Find the bounding span.
392397
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;
393398
let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?;
@@ -476,16 +481,12 @@ impl CodeSuggestion {
476481
_ => 1,
477482
})
478483
.sum();
479-
if !is_different(sm, &part.snippet, part.span) {
480-
// Account for cases where we are suggesting the same code that's already
481-
// there. This shouldn't happen often, but in some cases for multipart
482-
// suggestions it's much easier to handle it here than in the origin.
483-
} else {
484-
line_highlight.push(SubstitutionHighlight {
485-
start: (cur_lo.col.0 as isize + acc) as usize,
486-
end: (cur_lo.col.0 as isize + acc + len) as usize,
487-
});
488-
}
484+
485+
line_highlight.push(SubstitutionHighlight {
486+
start: (cur_lo.col.0 as isize + acc) as usize,
487+
end: (cur_lo.col.0 as isize + acc + len) as usize,
488+
});
489+
489490
buf.push_str(&part.snippet);
490491
let cur_hi = sm.lookup_char_pos(part.span.hi());
491492
// 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)