Skip to content

Commit a2b4833

Browse files
committed
Revert "Auto merge of rust-lang#146121 - Muscraft:filter-suggestion-parts, r=petrochenkov"
This reverts commit 99317ef, reversing changes made to 9cd272d.
1 parent 11d2046 commit a2b4833

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,11 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
945945
None,
946946
"Span must not be empty and have no suggestion",
947947
);
948+
debug_assert_eq!(
949+
parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
950+
None,
951+
"suggestion must not have overlapping parts",
952+
);
948953

949954
self.push_suggestion(CodeSuggestion {
950955
substitutions: vec![Substitution { parts }],

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,7 @@ impl HumanEmitter {
23502350
.sum();
23512351
let underline_start = (span_start_pos + start) as isize + offset;
23522352
let underline_end = (span_start_pos + start + sub_len) as isize + offset;
2353+
assert!(underline_start >= 0 && underline_end >= 0);
23532354
let padding: usize = max_line_num_len + 3;
23542355
for p in underline_start..underline_end {
23552356
if let DisplaySuggestion::Underline = show_code_change

compiler/rustc_errors/src/lib.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,6 @@ impl CodeSuggestion {
400400
// Assumption: all spans are in the same file, and all spans
401401
// are disjoint. Sort in ascending order.
402402
substitution.parts.sort_by_key(|part| part.span.lo());
403-
// Verify the assumption that all spans are disjoint
404-
assert_eq!(
405-
substitution.parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
406-
None,
407-
"all spans must be disjoint",
408-
);
409-
410-
// Account for cases where we are suggesting the same code that's already
411-
// there. This shouldn't happen often, but in some cases for multipart
412-
// suggestions it's much easier to handle it here than in the origin.
413-
substitution.parts.retain(|p| is_different(sm, &p.snippet, p.span));
414403

415404
// Find the bounding span.
416405
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;
@@ -505,12 +494,16 @@ impl CodeSuggestion {
505494
_ => 1,
506495
})
507496
.sum();
508-
509-
line_highlight.push(SubstitutionHighlight {
510-
start: (cur_lo.col.0 as isize + acc) as usize,
511-
end: (cur_lo.col.0 as isize + acc + len) as usize,
512-
});
513-
497+
if !is_different(sm, &part.snippet, part.span) {
498+
// Account for cases where we are suggesting the same code that's already
499+
// there. This shouldn't happen often, but in some cases for multipart
500+
// suggestions it's much easier to handle it here than in the origin.
501+
} else {
502+
line_highlight.push(SubstitutionHighlight {
503+
start: (cur_lo.col.0 as isize + acc) as usize,
504+
end: (cur_lo.col.0 as isize + acc + len) as usize,
505+
});
506+
}
514507
buf.push_str(&part.snippet);
515508
let cur_hi = sm.lookup_char_pos(part.span.hi());
516509
// Account for the difference between the width of the current code and the

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

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

279281
error: used `assert_eq!` with a literal bool
@@ -284,8 +286,10 @@ LL | assert_eq!(true, b!());
284286
|
285287
help: replace it with `assert!(..)`
286288
|
287-
LL - assert_eq!(true, b!());
288-
LL + assert!(b!());
289+
LL | true
290+
...
291+
LL |
292+
LL ~ assert!(b!());
289293
|
290294

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

0 commit comments

Comments
 (0)