diff options
| author | Ralf Jung <post@ralfj.de> | 2025-09-08 10:27:05 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-08 10:27:05 +0000 |
| commit | 3430751d7edcbc375663f4d7d10072709df52e44 (patch) | |
| tree | 9ed7d1c3b1d7943ded851dd74b3ddb1e95042394 /compiler/rustc_errors/src/lib.rs | |
| parent | 211461a4d50fa282bbb29abd53ee4eb1808a9224 (diff) | |
| parent | 24ce839fb953d1172a19479edcb2f75877cf153e (diff) | |
| download | rust-3430751d7edcbc375663f4d7d10072709df52e44.tar.gz rust-3430751d7edcbc375663f4d7d10072709df52e44.zip | |
Merge pull request #4573 from RalfJung/rustup
Rustup
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index a56e0f3fae1..8869799ce90 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -381,6 +381,17 @@ impl CodeSuggestion { // Assumption: all spans are in the same file, and all spans // are disjoint. Sort in ascending order. substitution.parts.sort_by_key(|part| part.span.lo()); + // Verify the assumption that all spans are disjoint + assert_eq!( + substitution.parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)), + None, + "all spans must be disjoint", + ); + + // Account for cases where we are suggesting the same code that's already + // there. This shouldn't happen often, but in some cases for multipart + // suggestions it's much easier to handle it here than in the origin. + substitution.parts.retain(|p| is_different(sm, &p.snippet, p.span)); // Find the bounding span. let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?; @@ -470,16 +481,12 @@ impl CodeSuggestion { _ => 1, }) .sum(); - if !is_different(sm, &part.snippet, part.span) { - // Account for cases where we are suggesting the same code that's already - // there. This shouldn't happen often, but in some cases for multipart - // suggestions it's much easier to handle it here than in the origin. - } else { - line_highlight.push(SubstitutionHighlight { - start: (cur_lo.col.0 as isize + acc) as usize, - end: (cur_lo.col.0 as isize + acc + len) as usize, - }); - } + + line_highlight.push(SubstitutionHighlight { + start: (cur_lo.col.0 as isize + acc) as usize, + end: (cur_lo.col.0 as isize + acc + len) as usize, + }); + buf.push_str(&part.snippet); let cur_hi = sm.lookup_char_pos(part.span.hi()); // Account for the difference between the width of the current code and the |
