about summary refs log tree commit diff
path: root/compiler/rustc_errors
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-02-21 00:29:56 +0000
committerMichael Goulet <michael@errs.io>2025-02-21 00:54:01 +0000
commit160905b6253f42967ed4aef4b98002944c7df24c (patch)
treef9b1d1c27a5beb012e272ecfdecfda62f8419a7b /compiler/rustc_errors
parent0a7ab1d6df4a2cfac819b0bada85b9142ac8ba26 (diff)
downloadrust-160905b6253f42967ed4aef4b98002944c7df24c.tar.gz
rust-160905b6253f42967ed4aef4b98002944c7df24c.zip
Trim suggestion part before generating highlights
Diffstat (limited to 'compiler/rustc_errors')
-rw-r--r--compiler/rustc_errors/src/emitter.rs7
-rw-r--r--compiler/rustc_errors/src/lib.rs7
2 files changed, 7 insertions, 7 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 634afacf539..f7f84239308 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -2216,12 +2216,7 @@ impl HumanEmitter {
             if let DisplaySuggestion::Diff | DisplaySuggestion::Underline | DisplaySuggestion::Add =
                 show_code_change
             {
-                for mut part in parts {
-                    // If this is a replacement of, e.g. `"a"` into `"ab"`, adjust the
-                    // suggestion and snippet to look as if we just suggested to add
-                    // `"b"`, which is typically much easier for the user to understand.
-                    part.trim_trivial_replacements(sm);
-
+                for part in parts {
                     let snippet = if let Ok(snippet) = sm.span_to_snippet(part.span) {
                         snippet
                     } else {
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 0016dacc8b2..ceed0cd94fc 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -403,7 +403,12 @@ impl CodeSuggestion {
                 // or deleted code in order to point at the correct column *after* substitution.
                 let mut acc = 0;
                 let mut only_capitalization = false;
-                for part in &substitution.parts {
+                for part in &mut substitution.parts {
+                    // If this is a replacement of, e.g. `"a"` into `"ab"`, adjust the
+                    // suggestion and snippet to look as if we just suggested to add
+                    // `"b"`, which is typically much easier for the user to understand.
+                    part.trim_trivial_replacements(sm);
+
                     only_capitalization |= is_case_difference(sm, &part.snippet, part.span);
                     let cur_lo = sm.lookup_char_pos(part.span.lo());
                     if prev_hi.line == cur_lo.line {