1
Fork 0

Trim suggestion part before generating highlights

This commit is contained in:
Michael Goulet 2025-02-21 00:29:56 +00:00
parent 0a7ab1d6df
commit 160905b625
36 changed files with 106 additions and 113 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -14,9 +14,9 @@ LL | | };
= help: to override `-D warnings` add `#[allow(clippy::async_yields_async)]`
help: consider awaiting this value
|
LL ~ async {
LL + 3
LL + }.await
LL | async {
LL | 3
LL ~ }.await
|
error: an async construct yields a type which is itself awaitable
@ -46,9 +46,9 @@ LL | | };
|
help: consider awaiting this value
|
LL ~ async {
LL + 3
LL + }.await
LL | async {
LL | 3
LL ~ }.await
|
error: an async construct yields a type which is itself awaitable

View file

@ -152,7 +152,7 @@ LL | f as usize
help: did you mean to invoke the function?
|
LL | f() as usize
|
| ++
error: casting function pointer `T::static_method` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:62:5
@ -163,7 +163,7 @@ LL | T::static_method as usize
help: did you mean to invoke the function?
|
LL | T::static_method() as usize
|
| ++
error: casting function pointer `(clos as fn(u32) -> u32)` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:69:13

View file

@ -9,7 +9,7 @@ LL | true
help: add `return` as shown
|
LL | return true
|
| ++++++
error: missing `return` statement
--> tests/ui/implicit_return.rs:19:15
@ -122,7 +122,7 @@ LL | format!("test {}", "test")
help: add `return` as shown
|
LL | return format!("test {}", "test")
|
| ++++++
error: missing `return` statement
--> tests/ui/implicit_return.rs:90:5
@ -133,7 +133,7 @@ LL | m!(true, false)
help: add `return` as shown
|
LL | return m!(true, false)
|
| ++++++
error: missing `return` statement
--> tests/ui/implicit_return.rs:96:13
@ -169,10 +169,8 @@ LL | | }
|
help: add `return` as shown
|
LL ~ return loop {
LL + m!(true);
LL + }
|
LL | return loop {
| ++++++
error: missing `return` statement
--> tests/ui/implicit_return.rs:130:5
@ -183,7 +181,7 @@ LL | true
help: add `return` as shown
|
LL | return true
|
| ++++++
error: aborting due to 16 previous errors

View file

@ -196,11 +196,9 @@ LL | | }
| |_________^
help: try
|
LL ~ for n in vec![
LL +
LL + Some(1),
LL + Some(2),
LL + Some(3)
LL | for n in vec![
...
LL | Some(3)
LL ~ ].iter().flatten() {
|

View file

@ -12,7 +12,7 @@ LL | | /// 200 characters so I needed to write something longeeeeeeer.
= help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]`
help: add an empty line
|
LL ~ /// A very short summary.
LL | /// A very short summary.
LL + ///
|

View file

@ -12,8 +12,8 @@ LL | | //! 200 characters so I needed to write something longeeeeeeer.
= help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]`
help: add an empty line
|
LL ~ //! A very short summary.
LL + //!
LL | //! A very short summary.
LL ~ //!
LL ~ //! A much longer explanation that goes into a lot more detail about
|

View file

@ -7,9 +7,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: aborting due to 1 previous error

View file

@ -7,9 +7,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error[E0658]: the `#[coverage]` attribute is an experimental feature
--> $DIR/bad-attr-ice.rs:11:1

View file

@ -7,9 +7,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:17:5
@ -20,9 +20,9 @@ LL | #![coverage]
help: the following are the possible correct uses
|
LL | #![coverage(off)]
|
| +++++
LL | #![coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:21:1
@ -33,9 +33,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:29:5
@ -46,9 +46,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:26:1
@ -59,9 +59,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:39:5
@ -72,9 +72,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:44:5
@ -85,9 +85,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:35:1
@ -98,9 +98,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:53:5
@ -111,9 +111,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:58:5
@ -124,9 +124,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:50:1
@ -137,9 +137,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:64:1
@ -150,9 +150,9 @@ LL | #[coverage]
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
| +++++
LL | #[coverage(on)]
|
| ++++
error[E0788]: coverage attribute not allowed here
--> $DIR/word-only.rs:21:1

View file

@ -11,7 +11,7 @@ LL | extern crate test as alloc;
help: you can use `as` to change the binding name of the import
|
LL | extern crate test as other_alloc;
|
| ++++++
error: aborting due to 1 previous error

View file

@ -11,7 +11,7 @@ LL | mod alloc {
help: you can use `as` to change the binding name of the import
|
LL | extern crate alloc as other_alloc;
|
| ++++++++++++++
error: aborting due to 1 previous error

View file

@ -12,11 +12,8 @@ LL | | )) {}
= note: `#[warn(anonymous_parameters)]` on by default
help: try naming the parameter or explicitly ignoring it
|
LL ~ fn test(x: u32, _: (
LL +
LL +
LL ~ )) {}
|
LL | fn test(x: u32, _: (
| ++
warning: 1 warning emitted

View file

@ -11,8 +11,8 @@ note: method defined here
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: provide the argument
|
LL ~ needlesArr.iter().fold(|x, y| {
LL +
LL | needlesArr.iter().fold(|x, y| {
LL |
LL ~ }, /* f */);
|

View file

@ -8,7 +8,7 @@ LL | extern crate std;
help: you can use `as` to change the binding name of the import
|
LL | extern crate std as other_std;
|
| ++++++++++++
error: aborting due to 1 previous error

View file

@ -10,7 +10,7 @@ LL | extern crate issue_45829_b as bar;
help: you can use `as` to change the binding name of the import
|
LL | extern crate issue_45829_b as other_bar;
|
| ++++++
error: aborting due to 1 previous error

View file

@ -10,7 +10,7 @@ LL | extern crate issue_45829_b as issue_45829_a;
help: you can use `as` to change the binding name of the import
|
LL | extern crate issue_45829_b as other_issue_45829_a;
|
| ++++++
error: aborting due to 1 previous error

View file

@ -15,7 +15,7 @@ LL | m!();
help: you can use `as` to change the binding name of the import
|
LL | extern crate std as other_core;
|
| ++++++
error: aborting due to 1 previous error

View file

@ -15,7 +15,7 @@ LL | m!();
help: you can use `as` to change the binding name of the import
|
LL | extern crate std as other_empty;
|
| ++++++
error: aborting due to 1 previous error

View file

@ -21,7 +21,7 @@ LL | m!();
help: you can use `as` to change the binding name of the import
|
LL | extern crate std as other_non_existent;
|
| ++++++
error: aborting due to 2 previous errors

View file

@ -7,9 +7,9 @@ LL | #[rustc_on_unimplemented]
help: the following are the possible correct uses
|
LL | #[rustc_on_unimplemented = "message"]
|
| +++++++++++
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
|
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0230]: there is no parameter `C` on trait `BadAnnotation2`
--> $DIR/bad-annotation.rs:22:1

View file

@ -8,7 +8,7 @@ LL | extern crate core;
help: you can use `as` to change the binding name of the import
|
LL | extern crate core as other_core;
|
| +++++++++++++
error: `#[panic_handler]` function required, but not found

View file

@ -37,7 +37,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match ref_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -100,7 +100,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match res_u32_never {
LL + Ok(_) => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -374,7 +374,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match slice_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: `&[]` not covered
@ -415,7 +415,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match *slice_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -462,7 +462,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match array_0_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern

View file

@ -46,7 +46,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match ref_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -76,7 +76,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match res_u32_never {
LL + Ok(_) => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered
@ -321,7 +321,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match slice_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: `&[!, ..]` not covered
@ -376,7 +376,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match *slice_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty
@ -390,7 +390,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match array_0_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -502,7 +502,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match *ref_tuple_half_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern

View file

@ -37,7 +37,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match ref_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -67,7 +67,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match res_u32_never {
LL + Ok(_) => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered
@ -312,7 +312,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match slice_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered
@ -367,7 +367,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match *slice_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty
@ -381,7 +381,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match array_0_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -493,7 +493,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match *ref_tuple_half_never {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern

View file

@ -36,7 +36,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match return_never_rpit(x) {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern
@ -118,7 +118,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match return_never_tait(x) {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: unreachable pattern

View file

@ -154,7 +154,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match 7usize {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: aborting due to 12 previous errors

View file

@ -15,7 +15,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match a {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: aborting due to 1 previous error

View file

@ -4,7 +4,7 @@ error[E0259]: the name `std` is defined multiple times
help: you can use `as` to change the binding name of the import
|
LL | extern crate std as other_std;
|
| ++++++++++++
error: aborting due to 1 previous error

View file

@ -38,7 +38,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match NonExhaustiveEnum::Unit {
LL + NonExhaustiveEnum::Unit | NonExhaustiveEnum::Tuple(_) | NonExhaustiveEnum::Struct { .. } => todo!(),
LL + }
LL ~ }
|
error[E0004]: non-exhaustive patterns: `NormalEnum::Unit`, `NormalEnum::Tuple(_)` and `NormalEnum::Struct { .. }` not covered
@ -65,7 +65,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match NormalEnum::Unit {
LL + NormalEnum::Unit | NormalEnum::Tuple(_) | NormalEnum::Struct { .. } => todo!(),
LL + }
LL ~ }
|
error: aborting due to 3 previous errors

View file

@ -103,7 +103,7 @@
</tspan>
<tspan x="10px" y="748px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="766px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> Enum::Tuple</tspan><tspan class="fg-ansi256-010">(/* i32 */)</tspan><tspan>;</tspan>
<tspan x="10px" y="766px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> Enum::Tuple(</tspan><tspan class="fg-ansi256-010">/* i32 */</tspan><tspan>);</tspan>
</tspan>
<tspan x="10px" y="784px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-010">+++++++++</tspan>
</tspan>
@ -581,7 +581,7 @@
</tspan>
<tspan x="10px" y="5050px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-009">- </tspan><tspan> Enum::</tspan><tspan class="fg-ansi256-009">tuple</tspan><tspan>();</tspan>
</tspan>
<tspan x="10px" y="5068px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-010">+ </tspan><tspan> Enum::</tspan><tspan class="fg-ansi256-010">Tuple(/* i32 */)</tspan><tspan>;</tspan>
<tspan x="10px" y="5068px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-010">+ </tspan><tspan> Enum::</tspan><tspan class="fg-ansi256-010">Tuple</tspan><tspan>(</tspan><tspan class="fg-ansi256-010">/* i32 */</tspan><tspan>);</tspan>
</tspan>
<tspan x="10px" y="5086px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Before After
Before After

View file

@ -22,8 +22,8 @@ LL | | } else {
|
help: consider returning the local binding `s`
|
LL ~ let s: String = if let Some(s) = opt_str {
LL + s
LL | let s: String = if let Some(s) = opt_str {
LL ~ s
LL ~
|
@ -54,8 +54,8 @@ LL | | } else {
|
help: consider returning the local binding `s`
|
LL ~ let s: String = if let Some(s) = opt_str {
LL + s
LL | let s: String = if let Some(s) = opt_str {
LL ~ s
LL ~
|
@ -71,8 +71,8 @@ LL | String::new()
|
help: consider returning the local binding `s`
|
LL ~ let s = if let Some(s) = opt_str {
LL + s
LL | let s = if let Some(s) = opt_str {
LL ~ s
LL ~ } else {
|

View file

@ -69,7 +69,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match x {
LL + UninhabitedVariants::Tuple(_) => todo!(),
LL + }
LL ~ }
|
error: aborting due to 5 previous errors

View file

@ -9,7 +9,7 @@ help: ensure that all possible cases are being handled by adding a match arm wit
|
LL ~ match empty_opaque() {
LL + _ => todo!(),
LL + }
LL ~ }
|
error: aborting due to 1 previous error

View file

@ -14,8 +14,8 @@ LL | fn deserialize_token<D: Deserializer<'a>>(_x: D, _y: &'a str) -> &'a st
|
help: consider returning the local binding `_y`
|
LL ~ fn deserialize_token<D: Deserializer<'a>>(_x: D, _y: &'a str) -> &'a str {
LL + _y
LL | fn deserialize_token<D: Deserializer<'a>>(_x: D, _y: &'a str) -> &'a str {
LL ~ _y
LL ~
|