Skip to content

Commit 0d09c4d

Browse files
committed
Auto merge of #148043 - lqd:revert-146121, r=wesleywiser
Revert "fix: Filter suggestion parts that match existing code" As requested by `@wesleywiser` in #147973 (comment) this is a revert of #146121 due to the handful of diagnostics ICEs that have been since reported, and found in the beta crater run. This should thus also be backported to beta so the ICEs don't make it to next week's stable. Works around (after backport) - #146261 - #146706 - #146834 but I didn't add a test for this allowed-by-default lint - as well as the crater run regressions from #147973 of which I only added the MCVE as a test. The proper fix would likely be #147849 but it's still currently at the MCP stage. In the meantime, this PR would still emit the same overlapping suggestions, but still use a debug-assert... r? `@wesleywiser`
2 parents 75948c8 + dd83c57 commit 0d09c4d

File tree

8 files changed

+81
-21
lines changed

8 files changed

+81
-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

tests/crashes/146261.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This is part of series of regression tests for some diagnostics ICEs encountered in the wild with
2+
// suggestions having overlapping parts under https://github.com/rust-lang/rust/pull/146121.
3+
4+
//@ needs-rustc-debug-assertions
5+
//@ known-bug: #146261
6+
7+
enum U {
8+
B(),
9+
}
10+
11+
fn main() {
12+
A(U::C)
13+
}

tests/crashes/146706.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This is part of series of regression tests for some diagnostics ICEs encountered in the wild with
2+
// suggestions having overlapping parts under https://github.com/rust-lang/rust/pull/146121.
3+
4+
//@ needs-rustc-debug-assertions
5+
//@ known-bug: #146706
6+
7+
type Alias<'a, T> = Foo<T>;
8+
9+
enum Foo<T> {
10+
Bar { t: T },
11+
}
12+
13+
fn main() {
14+
Alias::Bar::<u32> { t: 0 };
15+
}

tests/crashes/147973.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This is part of series of regression tests for some diagnostics ICEs encountered in the wild with
2+
// suggestions having overlapping parts under https://github.com/rust-lang/rust/pull/146121.
3+
// This is one MCVE from the beta crater run regressions from issue 147973.
4+
5+
//@ needs-rustc-debug-assertions
6+
//@ known-bug: #147973
7+
8+
//@ aux-build: overlapping_spans_helper.rs
9+
extern crate overlapping_spans_helper;
10+
11+
fn main() {
12+
let _name = Some(1);
13+
overlapping_spans_helper::do_loop!(_name);
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Auxiliary lib for the issue 147973 regression test with ICEs due to overlapping spans.
2+
3+
#[macro_export]
4+
macro_rules! identity {
5+
($x:ident) => {
6+
$x
7+
};
8+
}
9+
10+
#[macro_export]
11+
macro_rules! do_loop {
12+
($x:ident) => {
13+
for $crate::identity!($x) in $x {}
14+
};
15+
}

0 commit comments

Comments
 (0)