diff options
| author | Scott Schafer <schaferjscott@gmail.com> | 2025-08-27 20:33:50 -0600 |
|---|---|---|
| committer | Scott Schafer <schaferjscott@gmail.com> | 2025-09-04 17:42:13 -0600 |
| commit | b307a1146b4af3b5808510e44a13f56f2b0252e9 (patch) | |
| tree | a36a76fad1e97c81e6ae7cdda470d4a1824a98ee /compiler/rustc_errors/src | |
| parent | f196f50d6609eecfe94989a317a8779637288d94 (diff) | |
| download | rust-b307a1146b4af3b5808510e44a13f56f2b0252e9.tar.gz rust-b307a1146b4af3b5808510e44a13f56f2b0252e9.zip | |
fix: Filter suggestion parts that match existing code
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 7d8577ac2c2..8869799ce90 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -388,6 +388,11 @@ impl CodeSuggestion { "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()?; let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?; @@ -476,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 |
