Skip to content

Commit c956a76

Browse files
lqdcuviper
authored andcommitted
Revert "Auto merge of #146121 - Muscraft:filter-suggestion-parts, r=petrochenkov"
This reverts commit 99317ef, reversing changes made to 9cd272d. (cherry picked from commit a2b4833)
1 parent 21ffe30 commit c956a76

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
@@ -2354,6 +2354,7 @@ impl HumanEmitter {
23542354
.sum();
23552355
let underline_start = (span_start_pos + start) as isize + offset;
23562356
let underline_end = (span_start_pos + start + sub_len) as isize + offset;
2357+
assert!(underline_start >= 0 && underline_end >= 0);
23572358
let padding: usize = max_line_num_len + 3;
23582359
for p in underline_start..underline_end {
23592360
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
@@ -381,17 +381,6 @@ impl CodeSuggestion {
381381
// Assumption: all spans are in the same file, and all spans
382382
// are disjoint. Sort in ascending order.
383383
substitution.parts.sort_by_key(|part| part.span.lo());
384-
// Verify the assumption that all spans are disjoint
385-
assert_eq!(
386-
substitution.parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
387-
None,
388-
"all spans must be disjoint",
389-
);
390-
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));
395384

396385
// Find the bounding span.
397386
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;
@@ -481,12 +470,16 @@ impl CodeSuggestion {
481470
_ => 1,
482471
})
483472
.sum();
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-
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+
}
490483
buf.push_str(&part.snippet);
491484
let cur_hi = sm.lookup_char_pos(part.span.hi());
492485
// 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)