Skip to content

Commit ccec268

Browse files
Consider add-prefix replacements too
1 parent 9940da0 commit ccec268

File tree

44 files changed

+222
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+222
-330
lines changed

compiler/rustc_errors/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ impl SubstitutionPart {
236236
/// it with "abx" is, since the "c" character is lost.
237237
pub fn is_destructive_replacement(&self, sm: &SourceMap) -> bool {
238238
self.is_replacement(sm)
239-
&& !sm
240-
.span_to_snippet(self.span)
241-
.is_ok_and(|snippet| self.snippet.trim_start().starts_with(snippet.trim_start()))
239+
&& !sm.span_to_snippet(self.span).is_ok_and(|snippet| {
240+
self.snippet.trim_start().starts_with(snippet.trim_start())
241+
|| self.snippet.trim_end().ends_with(snippet.trim_end())
242+
})
242243
}
243244

244245
fn replaces_meaningful_content(&self, sm: &SourceMap) -> bool {

tests/ui/closures/2229_closure_analysis/issue-118144.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | V(x) = func_arg;
88
|
99
help: consider dereferencing to access the inner value using the Deref trait
1010
|
11-
LL - V(x) = func_arg;
12-
LL + V(x) = &*func_arg;
13-
|
11+
LL | V(x) = &*func_arg;
12+
| ~~~~~~~~~~
1413

1514
error: aborting due to 1 previous error
1615

tests/ui/empty/empty-struct-braces-expr.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ LL | let xe3 = XE::Empty3;
125125
|
126126
help: there is a variant with a similar name
127127
|
128-
LL - let xe3 = XE::Empty3;
129-
LL + let xe3 = XE::XEmpty3;
130-
|
128+
LL | let xe3 = XE::XEmpty3;
129+
| ~~~~~~~
131130

132131
error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
133132
--> $DIR/empty-struct-braces-expr.rs:26:19

tests/ui/env-macro/error-recovery-issue-55897.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ LL | use env;
3030
|
3131
help: consider importing this module instead
3232
|
33-
LL - use env;
34-
LL + use std::env;
35-
|
33+
LL | use std::env;
34+
| ~~~~~~~~
3635

3736
error: aborting due to 4 previous errors
3837

tests/ui/error-codes/E0027.stderr

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ LL | Dog { age: x } => {}
66
|
77
help: include the missing field in the pattern
88
|
9-
LL - Dog { age: x } => {}
10-
LL + Dog { age: x, name } => {}
11-
|
9+
LL | Dog { age: x, name } => {}
10+
| ~~~~~~~~
1211
help: if you don't care about this missing field, you can explicitly ignore it
1312
|
14-
LL - Dog { age: x } => {}
15-
LL + Dog { age: x, name: _ } => {}
16-
|
13+
LL | Dog { age: x, name: _ } => {}
14+
| ~~~~~~~~~~~
1715
help: or always ignore missing fields here
1816
|
19-
LL - Dog { age: x } => {}
20-
LL + Dog { age: x, .. } => {}
21-
|
17+
LL | Dog { age: x, .. } => {}
18+
| ~~~~~~
2219

2320
error[E0027]: pattern does not mention field `age`
2421
--> $DIR/E0027.rs:15:9

tests/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ LL | extern "rust-call" fn call(self, args: ()) -> () {}
9595
found signature `extern "rust-call" fn(Foo, ()) -> ()`
9696
help: change the self-receiver type to match the trait
9797
|
98-
LL - extern "rust-call" fn call(self, args: ()) -> () {}
99-
LL + extern "rust-call" fn call(&self, args: ()) -> () {}
100-
|
98+
LL | extern "rust-call" fn call(&self, args: ()) -> () {}
99+
| ~~~~~
101100

102101
error[E0183]: manual implementations of `FnOnce` are experimental
103102
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:18:6

tests/ui/imports/suggest-import-issue-120074.edition2015.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ LL | println!("Hello, {}!", crate::bar::do_the_thing);
66
|
77
help: a similar path exists
88
|
9-
LL - println!("Hello, {}!", crate::bar::do_the_thing);
10-
LL + println!("Hello, {}!", crate::foo::bar::do_the_thing);
11-
|
9+
LL | println!("Hello, {}!", crate::foo::bar::do_the_thing);
10+
| ~~~~~~~~
1211
help: consider importing this module
1312
|
1413
LL + use foo::bar;

tests/ui/imports/suggest-import-issue-120074.edition2021.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ LL | println!("Hello, {}!", crate::bar::do_the_thing);
66
|
77
help: a similar path exists
88
|
9-
LL - println!("Hello, {}!", crate::bar::do_the_thing);
10-
LL + println!("Hello, {}!", crate::foo::bar::do_the_thing);
11-
|
9+
LL | println!("Hello, {}!", crate::foo::bar::do_the_thing);
10+
| ~~~~~~~~
1211
help: consider importing this module
1312
|
1413
LL + use foo::bar;

tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ LL | T::A(a) | T::B(a) => a,
1010
found enum `T`
1111
help: consider dereferencing the boxed value
1212
|
13-
LL - let y = match x {
14-
LL + let y = match *x {
15-
|
13+
LL | let y = match *x {
14+
| ~~
1615

1716
error[E0308]: mismatched types
1817
--> $DIR/issue-57741.rs:20:19
@@ -26,9 +25,8 @@ LL | T::A(a) | T::B(a) => a,
2625
found enum `T`
2726
help: consider dereferencing the boxed value
2827
|
29-
LL - let y = match x {
30-
LL + let y = match *x {
31-
|
28+
LL | let y = match *x {
29+
| ~~
3230

3331
error[E0308]: mismatched types
3432
--> $DIR/issue-57741.rs:27:9
@@ -42,9 +40,8 @@ LL | S::A { a } | S::B { b: a } => a,
4240
found enum `S`
4341
help: consider dereferencing the boxed value
4442
|
45-
LL - let y = match x {
46-
LL + let y = match *x {
47-
|
43+
LL | let y = match *x {
44+
| ~~
4845

4946
error[E0308]: mismatched types
5047
--> $DIR/issue-57741.rs:27:22
@@ -58,9 +55,8 @@ LL | S::A { a } | S::B { b: a } => a,
5855
found enum `S`
5956
help: consider dereferencing the boxed value
6057
|
61-
LL - let y = match x {
62-
LL + let y = match *x {
63-
|
58+
LL | let y = match *x {
59+
| ~~
6460

6561
error: aborting due to 4 previous errors
6662

tests/ui/let-else/let-else-deref-coercion.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | let Bar::Present(z) = self else {
88
|
99
help: consider dereferencing to access the inner value using the Deref trait
1010
|
11-
LL - let Bar::Present(z) = self else {
12-
LL + let Bar::Present(z) = &**self else {
13-
|
11+
LL | let Bar::Present(z) = &**self else {
12+
| ~~~~~~~
1413

1514
error[E0308]: mismatched types
1615
--> $DIR/let-else-deref-coercion.rs:68:13
@@ -22,9 +21,8 @@ LL | let Bar(z) = x;
2221
|
2322
help: consider dereferencing to access the inner value using the Deref trait
2423
|
25-
LL - let Bar(z) = x;
26-
LL + let Bar(z) = &**x;
27-
|
24+
LL | let Bar(z) = &**x;
25+
| ~~~~
2826

2927
error: aborting due to 2 previous errors
3028

tests/ui/lexer/lex-bad-char-literals-1.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ LL | "\●"
3232
= help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals>
3333
help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal
3434
|
35-
LL - "\●"
36-
LL + r"\●"
37-
|
35+
LL | r"\●"
36+
| ~~~~~
3837

3938
error: aborting due to 4 previous errors
4039

tests/ui/lifetimes/borrowck-let-suggestion.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ LL | x.use_mut();
1212
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1313
help: consider consuming the `Vec<i32>` when turning it into an `Iterator`
1414
|
15-
LL - let mut x = vec![1].iter();
16-
LL + let mut x = vec![1].into_iter();
17-
|
15+
LL | let mut x = vec![1].into_iter();
16+
| ~~~~~~~~~
1817
help: consider using a `let` binding to create a longer lived value
1918
|
2019
LL ~ let binding = vec![1];

tests/ui/lint/lint-strict-provenance-lossy-casts.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ LL | let addr_32bit = &x as *const u8 as u32;
2525
= help: if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_provenance()` instead
2626
help: use `.addr()` to obtain the address of a pointer
2727
|
28-
LL - let addr_32bit = &x as *const u8 as u32;
29-
LL + let addr_32bit = (&x as *const u8).addr() as u32;
30-
|
28+
LL | let addr_32bit = (&x as *const u8).addr() as u32;
29+
| + ~~~~~~~~~~~~~~~
3130

3231
error: under strict provenance it is considered bad style to cast pointer `*const u8` to integer `usize`
3332
--> $DIR/lint-strict-provenance-lossy-casts.rs:14:20

tests/ui/match/issue-56685.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ LL | #![deny(unused_variables)]
1111
| ^^^^^^^^^^^^^^^^
1212
help: if this is intentional, prefix it with an underscore
1313
|
14-
LL - E::A(x) | E::B(x) => {}
15-
LL + E::A(_x) | E::B(_x) => {}
16-
|
14+
LL | E::A(_x) | E::B(_x) => {}
15+
| ~~ ~~
1716

1817
error: unused variable: `x`
1918
--> $DIR/issue-56685.rs:25:14
@@ -23,9 +22,8 @@ LL | F::A(x, y) | F::B(x, y) => { y },
2322
|
2423
help: if this is intentional, prefix it with an underscore
2524
|
26-
LL - F::A(x, y) | F::B(x, y) => { y },
27-
LL + F::A(_x, y) | F::B(_x, y) => { y },
28-
|
25+
LL | F::A(_x, y) | F::B(_x, y) => { y },
26+
| ~~ ~~
2927

3028
error: unused variable: `a`
3129
--> $DIR/issue-56685.rs:27:14
@@ -47,9 +45,8 @@ LL | let _ = if let F::A(x, y) | F::B(x, y) = F::A(1, 2) {
4745
|
4846
help: if this is intentional, prefix it with an underscore
4947
|
50-
LL - let _ = if let F::A(x, y) | F::B(x, y) = F::A(1, 2) {
51-
LL + let _ = if let F::A(_x, y) | F::B(_x, y) = F::A(1, 2) {
52-
|
48+
LL | let _ = if let F::A(_x, y) | F::B(_x, y) = F::A(1, 2) {
49+
| ~~ ~~
5350

5451
error: unused variable: `x`
5552
--> $DIR/issue-56685.rs:39:20
@@ -59,9 +56,8 @@ LL | while let F::A(x, y) | F::B(x, y) = F::A(1, 2) {
5956
|
6057
help: if this is intentional, prefix it with an underscore
6158
|
62-
LL - while let F::A(x, y) | F::B(x, y) = F::A(1, 2) {
63-
LL + while let F::A(_x, y) | F::B(_x, y) = F::A(1, 2) {
64-
|
59+
LL | while let F::A(_x, y) | F::B(_x, y) = F::A(1, 2) {
60+
| ~~ ~~
6561

6662
error: aborting due to 6 previous errors
6763

tests/ui/mismatched_types/issue-112036.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | fn drop(self) {}
88
found signature `fn(Foo)`
99
help: change the self-receiver type to match the trait
1010
|
11-
LL - fn drop(self) {}
12-
LL + fn drop(&mut self) {}
13-
|
11+
LL | fn drop(&mut self) {}
12+
| ~~~~~~~~~
1413

1514
error: aborting due to 1 previous error
1615

tests/ui/namespace/namespace-mix.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ LL | check(m1::S);
1010
= note: can't use a type alias as a constructor
1111
help: a tuple struct with a similar name exists
1212
|
13-
LL - check(m1::S);
14-
LL + check(m1::TS);
15-
|
13+
LL | check(m1::TS);
14+
| ~~
1615
help: consider importing one of these constants instead
1716
|
1817
LL + use m2::S;
@@ -39,9 +38,8 @@ LL | pub struct TS();
3938
= note: can't use a type alias as a constructor
4039
help: a tuple struct with a similar name exists
4140
|
42-
LL - check(xm1::S);
43-
LL + check(xm1::TS);
44-
|
41+
LL | check(xm1::TS);
42+
| ~~
4543
help: consider importing one of these constants instead
4644
|
4745
LL + use m2::S;
@@ -66,9 +64,8 @@ LL | check(m7::V);
6664
= note: can't use a type alias as a constructor
6765
help: a tuple variant with a similar name exists
6866
|
69-
LL - check(m7::V);
70-
LL + check(m7::TV);
71-
|
67+
LL | check(m7::TV);
68+
| ~~
7269
help: consider importing one of these constants instead
7370
|
7471
LL + use m8::V;
@@ -95,9 +92,8 @@ LL | TV(),
9592
= note: can't use a type alias as a constructor
9693
help: a tuple variant with a similar name exists
9794
|
98-
LL - check(xm7::V);
99-
LL + check(xm7::TV);
100-
|
95+
LL | check(xm7::TV);
96+
| ~~
10197
help: consider importing one of these constants instead
10298
|
10399
LL + use m8::V;

tests/ui/object-pointer-types.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ LL | x.owned();
99
|
1010
help: there is a method `to_owned` with a similar name
1111
|
12-
LL - x.owned();
13-
LL + x.to_owned();
14-
|
12+
LL | x.to_owned();
13+
| ~~~~~~~~
1514

1615
error[E0599]: no method named `owned` found for mutable reference `&mut dyn Foo` in the current scope
1716
--> $DIR/object-pointer-types.rs:17:7

tests/ui/parser/bad-char-literals.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ LL | ''';
66
|
77
help: escape the character
88
|
9-
LL - ''';
10-
LL + '\'';
11-
|
9+
LL | '\'';
10+
| ~~
1211

1312
error: character constant must be escaped: `\n`
1413
--> $DIR/bad-char-literals.rs:10:6

tests/ui/parser/bad-escape-suggest-raw-string.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ LL | let bad = "ab\[c";
77
= help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals>
88
help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal
99
|
10-
LL - let bad = "ab\[c";
11-
LL + let bad = r"ab\[c";
12-
|
10+
LL | let bad = r"ab\[c";
11+
| ~~~~~~~~
1312

1413
error: aborting due to 1 previous error
1514

tests/ui/parser/byte-literals.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ LL | b''';
3939
|
4040
help: escape the character
4141
|
42-
LL - b''';
43-
LL + b'\'';
44-
|
42+
LL | b'\'';
43+
| ~~
4544

4645
error: non-ASCII character in byte literal
4746
--> $DIR/byte-literals.rs:10:7

tests/ui/parser/issues/issue-65257-invalid-var-decl-recovery.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ LL | mut n = 0;
5454
|
5555
help: missing keyword
5656
|
57-
LL - mut n = 0;
58-
LL + let mut n = 0;
59-
|
57+
LL | let mut n = 0;
58+
| ~~~~~~~
6059

6160
error: invalid variable declaration
6261
--> $DIR/issue-65257-invalid-var-decl-recovery.rs:16:5
@@ -66,9 +65,8 @@ LL | mut var;
6665
|
6766
help: missing keyword
6867
|
69-
LL - mut var;
70-
LL + let mut var;
71-
|
68+
LL | let mut var;
69+
| ~~~~~~~
7270

7371
error[E0308]: mismatched types
7472
--> $DIR/issue-65257-invalid-var-decl-recovery.rs:20:33

0 commit comments

Comments
 (0)