Skip to content

Commit 160905b

Browse files
Trim suggestion part before generating highlights
1 parent 0a7ab1d commit 160905b

36 files changed

+106
-113
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,12 +2216,7 @@ impl HumanEmitter {
22162216
if let DisplaySuggestion::Diff | DisplaySuggestion::Underline | DisplaySuggestion::Add =
22172217
show_code_change
22182218
{
2219-
for mut part in parts {
2220-
// If this is a replacement of, e.g. `"a"` into `"ab"`, adjust the
2221-
// suggestion and snippet to look as if we just suggested to add
2222-
// `"b"`, which is typically much easier for the user to understand.
2223-
part.trim_trivial_replacements(sm);
2224-
2219+
for part in parts {
22252220
let snippet = if let Ok(snippet) = sm.span_to_snippet(part.span) {
22262221
snippet
22272222
} else {

compiler/rustc_errors/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@ impl CodeSuggestion {
403403
// or deleted code in order to point at the correct column *after* substitution.
404404
let mut acc = 0;
405405
let mut only_capitalization = false;
406-
for part in &substitution.parts {
406+
for part in &mut substitution.parts {
407+
// If this is a replacement of, e.g. `"a"` into `"ab"`, adjust the
408+
// suggestion and snippet to look as if we just suggested to add
409+
// `"b"`, which is typically much easier for the user to understand.
410+
part.trim_trivial_replacements(sm);
411+
407412
only_capitalization |= is_case_difference(sm, &part.snippet, part.span);
408413
let cur_lo = sm.lookup_char_pos(part.span.lo());
409414
if prev_hi.line == cur_lo.line {

src/tools/clippy/tests/ui/async_yields_async.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ LL | | };
1414
= help: to override `-D warnings` add `#[allow(clippy::async_yields_async)]`
1515
help: consider awaiting this value
1616
|
17-
LL ~ async {
18-
LL + 3
19-
LL + }.await
17+
LL | async {
18+
LL | 3
19+
LL ~ }.await
2020
|
2121

2222
error: an async construct yields a type which is itself awaitable
@@ -46,9 +46,9 @@ LL | | };
4646
|
4747
help: consider awaiting this value
4848
|
49-
LL ~ async {
50-
LL + 3
51-
LL + }.await
49+
LL | async {
50+
LL | 3
51+
LL ~ }.await
5252
|
5353

5454
error: an async construct yields a type which is itself awaitable

src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ LL | f as usize
152152
help: did you mean to invoke the function?
153153
|
154154
LL | f() as usize
155-
|
155+
| ++
156156

157157
error: casting function pointer `T::static_method` to `usize`
158158
--> tests/ui/fn_to_numeric_cast_any.rs:62:5
@@ -163,7 +163,7 @@ LL | T::static_method as usize
163163
help: did you mean to invoke the function?
164164
|
165165
LL | T::static_method() as usize
166-
|
166+
| ++
167167

168168
error: casting function pointer `(clos as fn(u32) -> u32)` to `usize`
169169
--> tests/ui/fn_to_numeric_cast_any.rs:69:13

src/tools/clippy/tests/ui/implicit_return.stderr

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | true
99
help: add `return` as shown
1010
|
1111
LL | return true
12-
|
12+
| ++++++
1313

1414
error: missing `return` statement
1515
--> tests/ui/implicit_return.rs:19:15
@@ -122,7 +122,7 @@ LL | format!("test {}", "test")
122122
help: add `return` as shown
123123
|
124124
LL | return format!("test {}", "test")
125-
|
125+
| ++++++
126126

127127
error: missing `return` statement
128128
--> tests/ui/implicit_return.rs:90:5
@@ -133,7 +133,7 @@ LL | m!(true, false)
133133
help: add `return` as shown
134134
|
135135
LL | return m!(true, false)
136-
|
136+
| ++++++
137137

138138
error: missing `return` statement
139139
--> tests/ui/implicit_return.rs:96:13
@@ -169,10 +169,8 @@ LL | | }
169169
|
170170
help: add `return` as shown
171171
|
172-
LL ~ return loop {
173-
LL + m!(true);
174-
LL + }
175-
|
172+
LL | return loop {
173+
| ++++++
176174

177175
error: missing `return` statement
178176
--> tests/ui/implicit_return.rs:130:5
@@ -183,7 +181,7 @@ LL | true
183181
help: add `return` as shown
184182
|
185183
LL | return true
186-
|
184+
| ++++++
187185

188186
error: aborting due to 16 previous errors
189187

src/tools/clippy/tests/ui/manual_flatten.stderr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ LL | | }
196196
| |_________^
197197
help: try
198198
|
199-
LL ~ for n in vec![
200-
LL +
201-
LL + Some(1),
202-
LL + Some(2),
203-
LL + Some(3)
199+
LL | for n in vec![
200+
...
201+
LL | Some(3)
204202
LL ~ ].iter().flatten() {
205203
|
206204

src/tools/clippy/tests/ui/too_long_first_doc_paragraph-fix.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | | /// 200 characters so I needed to write something longeeeeeeer.
1212
= help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]`
1313
help: add an empty line
1414
|
15-
LL ~ /// A very short summary.
15+
LL | /// A very short summary.
1616
LL + ///
1717
|
1818

src/tools/clippy/tests/ui/too_long_first_doc_paragraph.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ LL | | //! 200 characters so I needed to write something longeeeeeeer.
1212
= help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]`
1313
help: add an empty line
1414
|
15-
LL ~ //! A very short summary.
16-
LL + //!
15+
LL | //! A very short summary.
16+
LL ~ //!
1717
LL ~ //! A much longer explanation that goes into a lot more detail about
1818
|
1919

tests/ui/coverage-attr/bad-attr-ice.feat.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LL | #[coverage]
77
help: the following are the possible correct uses
88
|
99
LL | #[coverage(off)]
10-
|
10+
| +++++
1111
LL | #[coverage(on)]
12-
|
12+
| ++++
1313

1414
error: aborting due to 1 previous error
1515

tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LL | #[coverage]
77
help: the following are the possible correct uses
88
|
99
LL | #[coverage(off)]
10-
|
10+
| +++++
1111
LL | #[coverage(on)]
12-
|
12+
| ++++
1313

1414
error[E0658]: the `#[coverage]` attribute is an experimental feature
1515
--> $DIR/bad-attr-ice.rs:11:1

0 commit comments

Comments
 (0)