Skip to content

Commit b480a92

Browse files
compiler-errorsworkingjubilee
authored andcommitted
Use underline suggestions for purely 'additive' replacements
1 parent 6dfeab5 commit b480a92

File tree

110 files changed

+369
-535
lines changed

Some content is hidden

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

110 files changed

+369
-535
lines changed

compiler/rustc_errors/src/emitter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,8 @@ impl HumanEmitter {
19821982
{
19831983
debug!(?complete, ?parts, ?highlights);
19841984

1985-
let has_deletion = parts.iter().any(|p| p.is_deletion(sm) || p.is_replacement(sm));
1985+
let has_deletion =
1986+
parts.iter().any(|p| p.is_deletion(sm) || p.is_destructive_replacement(sm));
19861987
let is_multiline = complete.lines().count() > 1;
19871988

19881989
if i == 0 {

compiler/rustc_errors/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ impl SubstitutionPart {
230230
!self.snippet.is_empty() && self.replaces_meaningful_content(sm)
231231
}
232232

233+
/// Whether this is a replacement that overwrites source with a snippet
234+
/// in a way that isn't a superset of the original string. For example,
235+
/// replacing "abc" with "abcde" is not destructive, but replacing it
236+
/// it with "abx" is, since the "c" character is lost.
237+
pub fn is_destructive_replacement(&self, sm: &SourceMap) -> bool {
238+
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()))
242+
}
243+
233244
fn replaces_meaningful_content(&self, sm: &SourceMap) -> bool {
234245
sm.span_to_snippet(self.span)
235246
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())

tests/ui/associated-types/defaults-suitability.current.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ LL | type Baz = T;
134134
| --- required by a bound in this associated type
135135
help: consider further restricting type parameter `T` with trait `Clone`
136136
|
137-
LL - Self::Baz: Clone,
138-
LL + Self::Baz: Clone, T: std::clone::Clone
139-
|
137+
LL | Self::Baz: Clone, T: std::clone::Clone
138+
| ~~~~~~~~~~~~~~~~~~~~~~
140139

141140
error: aborting due to 8 previous errors
142141

tests/ui/associated-types/defaults-suitability.next.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ LL | type Baz = T;
134134
| --- required by a bound in this associated type
135135
help: consider further restricting type parameter `T` with trait `Clone`
136136
|
137-
LL - Self::Baz: Clone,
138-
LL + Self::Baz: Clone, T: std::clone::Clone
139-
|
137+
LL | Self::Baz: Clone, T: std::clone::Clone
138+
| ~~~~~~~~~~~~~~~~~~~~~~
140139

141140
error: aborting due to 8 previous errors
142141

tests/ui/associated-types/issue-38821.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ LL | impl<T: NotNull> IntoNullable for T {
1313
| unsatisfied trait bound introduced here
1414
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
1515
|
16-
LL - Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
17-
LL + Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
18-
|
16+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
17+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1918

2019
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
2120
--> $DIR/issue-38821.rs:40:1
@@ -38,9 +37,8 @@ LL | impl<T: NotNull> IntoNullable for T {
3837
| unsatisfied trait bound introduced here
3938
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
4039
|
41-
LL - Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
42-
LL + Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
43-
|
40+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
41+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4442

4543
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4644
--> $DIR/issue-38821.rs:23:10

tests/ui/associated-types/issue-54108.current.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ LL | type Size: Add<Output = Self::Size>;
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Encoder::Size`
1313
help: consider further restricting the associated type
1414
|
15-
LL - T: SubEncoder,
16-
LL + T: SubEncoder, <T as SubEncoder>::ActualSize: Add
17-
|
15+
LL | T: SubEncoder, <T as SubEncoder>::ActualSize: Add
16+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1817

1918
error: aborting due to 1 previous error
2019

tests/ui/associated-types/issue-54108.next.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ LL | type Size: Add<Output = Self::Size>;
1212
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `Encoder::Size`
1313
help: consider further restricting the associated type
1414
|
15-
LL - T: SubEncoder,
16-
LL + T: SubEncoder, <T as SubEncoder>::ActualSize: Add
17-
|
15+
LL | T: SubEncoder, <T as SubEncoder>::ActualSize: Add
16+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1817

1918
error: aborting due to 1 previous error
2019

tests/ui/attributes/rustc_confusables.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ LL | x.inser();
3535
|
3636
help: there is a method `insert` with a similar name
3737
|
38-
LL - x.inser();
39-
LL + x.insert();
40-
|
38+
LL | x.insert();
39+
| ~~~~~~
4140

4241
error[E0599]: no method named `foo` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
4342
--> $DIR/rustc_confusables.rs:15:7

tests/ui/attributes/rustc_confusables_std_cases.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ LL | let mut x = VecDeque::new();
3838
| ----- earlier `x` shadowed here with type `VecDeque`
3939
help: you might have meant to use `push_back`
4040
|
41-
LL - x.push(1);
42-
LL + x.push_back(1);
43-
|
41+
LL | x.push_back(1);
42+
| ~~~~~~~~~
4443

4544
error[E0599]: no method named `length` found for struct `Vec<{integer}>` in the current scope
4645
--> $DIR/rustc_confusables_std_cases.rs:15:7
@@ -98,9 +97,8 @@ note: method defined here
9897
--> $SRC_DIR/alloc/src/string.rs:LL:COL
9998
help: you might have meant to use `push_str`
10099
|
101-
LL - String::new().push("");
102-
LL + String::new().push_str("");
103-
|
100+
LL | String::new().push_str("");
101+
| ~~~~~~~~
104102

105103
error[E0599]: no method named `append` found for struct `String` in the current scope
106104
--> $DIR/rustc_confusables_std_cases.rs:24:19

tests/ui/borrowck/issue-115259-suggest-iter-mut.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | self.layers.iter().fold(0, |result, mut layer| result + layer.proce
88
|
99
help: you may want to use `iter_mut` here
1010
|
11-
LL - self.layers.iter().fold(0, |result, mut layer| result + layer.process())
12-
LL + self.layers.iter_mut().fold(0, |result, mut layer| result + layer.process())
13-
|
11+
LL | self.layers.iter_mut().fold(0, |result, mut layer| result + layer.process())
12+
| ~~~~~~~~
1413

1514
error: aborting due to 1 previous error
1615

tests/ui/borrowck/issue-62387-suggest-iter-mut-2.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | vec.iter().flat_map(|container| container.things()).cloned().co
88
|
99
help: you may want to use `iter_mut` here
1010
|
11-
LL - vec.iter().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>();
12-
LL + vec.iter_mut().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>();
13-
|
11+
LL | vec.iter_mut().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>();
12+
| ~~~~~~~~
1413

1514
error: aborting due to 1 previous error
1615

tests/ui/borrowck/issue-62387-suggest-iter-mut.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | v.iter().for_each(|a| a.double());
88
|
99
help: you may want to use `iter_mut` here
1010
|
11-
LL - v.iter().for_each(|a| a.double());
12-
LL + v.iter_mut().for_each(|a| a.double());
13-
|
11+
LL | v.iter_mut().for_each(|a| a.double());
12+
| ~~~~~~~~
1413

1514
error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
1615
--> $DIR/issue-62387-suggest-iter-mut.rs:25:39
@@ -22,9 +21,8 @@ LL | v.iter().rev().rev().for_each(|a| a.double());
2221
|
2322
help: you may want to use `iter_mut` here
2423
|
25-
LL - v.iter().rev().rev().for_each(|a| a.double());
26-
LL + v.iter_mut().rev().rev().for_each(|a| a.double());
27-
|
24+
LL | v.iter_mut().rev().rev().for_each(|a| a.double());
25+
| ~~~~~~~~
2826

2927
error: aborting due to 2 previous errors
3028

tests/ui/c-variadic/issue-86053-1.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize
6363
|
6464
help: a trait with a similar name exists
6565
|
66-
LL - self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
67-
LL + self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) {
68-
|
66+
LL | self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) {
67+
| ~~
6968
help: you might be missing a type parameter
7069
|
7170
LL | fn ordering4 < 'a , 'b, F > ( a : , self , self , self ,

tests/ui/cfg/cfg-method-receiver.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ LL | cbor_map! { #[cfg(test)] 4};
1616
= note: this error originates in the macro `cbor_map` (in Nightly builds, run with -Z macro-backtrace for more info)
1717
help: you must specify a concrete type for this numeric value, like `i32`
1818
|
19-
LL - cbor_map! { #[cfg(test)] 4};
20-
LL + cbor_map! { #[cfg(test)] 4_i32};
21-
|
19+
LL | cbor_map! { #[cfg(test)] 4_i32};
20+
| ~~~~~
2221

2322
error: aborting due to 2 previous errors
2423

tests/ui/check-cfg/diagnotics.cargo.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ LL | #[cfg(featur = "foo")]
1717
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
1818
help: there is a config with a similar name and value
1919
|
20-
LL - #[cfg(featur = "foo")]
21-
LL + #[cfg(feature = "foo")]
22-
|
20+
LL | #[cfg(feature = "foo")]
21+
| ~~~~~~~
2322

2423
warning: unexpected `cfg` condition name: `featur`
2524
--> $DIR/diagnotics.rs:17:7

tests/ui/check-cfg/diagnotics.rustc.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ LL | #[cfg(featur = "foo")]
1919
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
2020
help: there is a config with a similar name and value
2121
|
22-
LL - #[cfg(featur = "foo")]
23-
LL + #[cfg(feature = "foo")]
24-
|
22+
LL | #[cfg(feature = "foo")]
23+
| ~~~~~~~
2524

2625
warning: unexpected `cfg` condition name: `featur`
2726
--> $DIR/diagnotics.rs:17:7

tests/ui/closures/2229_closure_analysis/bad-pattern.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ LL | let PAT = v1;
108108
= note: the matched value is of type `u32`
109109
help: introduce a variable instead
110110
|
111-
LL - let PAT = v1;
112-
LL + let PAT_var = v1;
113-
|
111+
LL | let PAT_var = v1;
112+
| ~~~~~~~
114113

115114
error: aborting due to 7 previous errors
116115

tests/ui/closures/issue-78720.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ LL | _func: F,
1515
|
1616
help: a trait with a similar name exists
1717
|
18-
LL - _func: F,
19-
LL + _func: Fn,
20-
|
18+
LL | _func: Fn,
19+
| ~~
2120
help: you might be missing a type parameter
2221
|
2322
LL | struct Map2<Segment2, F> {

tests/ui/compare-method/bad-self-type.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ LL | fn poll(self, _: &mut Context<'_>) -> Poll<()> {
88
found signature `fn(MyFuture, &mut Context<'_>) -> Poll<_>`
99
help: change the self-receiver type to match the trait
1010
|
11-
LL - fn poll(self, _: &mut Context<'_>) -> Poll<()> {
12-
LL + fn poll(self: Pin<&mut MyFuture>, _: &mut Context<'_>) -> Poll<()> {
13-
|
11+
LL | fn poll(self: Pin<&mut MyFuture>, _: &mut Context<'_>) -> Poll<()> {
12+
| ~~~~~~~~~~~~~~~~~~~~~~~~
1413

1514
error[E0053]: method `foo` has an incompatible type for trait
1615
--> $DIR/bad-self-type.rs:22:18

tests/ui/const-generics/ensure_is_evaluatable.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ LL | [(); N + 1]:,
1414
| ^^^^^ required by this bound in `bar`
1515
help: try adding a `where` bound
1616
|
17-
LL - [(); M + 1]:,
18-
LL + [(); M + 1]:, [(); N + 1]:
19-
|
17+
LL | [(); M + 1]:, [(); N + 1]:
18+
| ~~~~~~~~~~~~~~
2019

2120
error: aborting due to 1 previous error
2221

tests/ui/const-generics/fn_with_two_const_inputs.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ LL | [(); N + 1]:,
1414
| ^^^^^ required by this bound in `bar`
1515
help: try adding a `where` bound
1616
|
17-
LL - [(); both(N + 1, M + 1)]:,
18-
LL + [(); both(N + 1, M + 1)]:, [(); N + 1]:
19-
|
17+
LL | [(); both(N + 1, M + 1)]:, [(); N + 1]:
18+
| ~~~~~~~~~~~~~~
2019

2120
error: aborting due to 1 previous error
2221

tests/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ LL | fn assert_impl<T: Trait>() {}
1616
| ^^^^^ required by this bound in `assert_impl`
1717
help: try adding a `where` bound
1818
|
19-
LL - EvaluatableU128<{N as u128}>:, {
20-
LL + EvaluatableU128<{N as u128}>:, [(); { O as u128 } as usize]: {
21-
|
19+
LL | EvaluatableU128<{N as u128}>:, [(); { O as u128 } as usize]: {
20+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2221

2322
error[E0308]: mismatched types
2423
--> $DIR/abstract-const-as-cast-3.rs:17:5
@@ -52,9 +51,8 @@ LL | fn assert_impl<T: Trait>() {}
5251
| ^^^^^ required by this bound in `assert_impl`
5352
help: try adding a `where` bound
5453
|
55-
LL - EvaluatableU128<{N as u128}>:, {
56-
LL + EvaluatableU128<{N as u128}>:, [(); { O as u128 } as usize]: {
57-
|
54+
LL | EvaluatableU128<{N as u128}>:, [(); { O as u128 } as usize]: {
55+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5856

5957
error[E0308]: mismatched types
6058
--> $DIR/abstract-const-as-cast-3.rs:20:5
@@ -116,9 +114,8 @@ LL | fn assert_impl<T: Trait>() {}
116114
| ^^^^^ required by this bound in `assert_impl`
117115
help: try adding a `where` bound
118116
|
119-
LL - EvaluatableU128<{N as _}>:, {
120-
LL + EvaluatableU128<{N as _}>:, [(); { O as u128 } as usize]: {
121-
|
117+
LL | EvaluatableU128<{N as _}>:, [(); { O as u128 } as usize]: {
118+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122119

123120
error[E0308]: mismatched types
124121
--> $DIR/abstract-const-as-cast-3.rs:35:5
@@ -152,9 +149,8 @@ LL | fn assert_impl<T: Trait>() {}
152149
| ^^^^^ required by this bound in `assert_impl`
153150
help: try adding a `where` bound
154151
|
155-
LL - EvaluatableU128<{N as _}>:, {
156-
LL + EvaluatableU128<{N as _}>:, [(); { O as u128 } as usize]: {
157-
|
152+
LL | EvaluatableU128<{N as _}>:, [(); { O as u128 } as usize]: {
153+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158154

159155
error[E0308]: mismatched types
160156
--> $DIR/abstract-const-as-cast-3.rs:38:5

tests/ui/const-generics/generic_const_exprs/assoc_const_unification/doesnt_unify_evaluatable.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ LL | bar::<{ T::ASSOC }>();
66
|
77
help: try adding a `where` bound
88
|
9-
LL - fn foo<T: Trait, U: Trait>() where [(); U::ASSOC]:, {
10-
LL + fn foo<T: Trait, U: Trait>() where [(); U::ASSOC]:, [(); { T::ASSOC }]: {
11-
|
9+
LL | fn foo<T: Trait, U: Trait>() where [(); U::ASSOC]:, [(); { T::ASSOC }]: {
10+
| ~~~~~~~~~~~~~~~~~~~~~
1211

1312
error: aborting due to 1 previous error
1413

tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ LL | foo::<_, L>([(); L + 1 + L]);
2626
|
2727
help: try adding a `where` bound
2828
|
29-
LL - [(); (L - 1) + 1 + L]:,
30-
LL + [(); (L - 1) + 1 + L]:, [(); L + 1 + L]:
31-
|
29+
LL | [(); (L - 1) + 1 + L]:, [(); L + 1 + L]:
30+
| ~~~~~~~~~~~~~~~~~~
3231

3332
error: unconstrained generic constant
3433
--> $DIR/issue_114151.rs:17:17

tests/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ LL | foo::<_, L>([(); L + 1 + L]);
1515
|
1616
help: try adding a `where` bound
1717
|
18-
LL - [(); (L - 1) + 1 + L]:,
19-
LL + [(); (L - 1) + 1 + L]:, [(); L + 1 + L]:
20-
|
18+
LL | [(); (L - 1) + 1 + L]:, [(); L + 1 + L]:
19+
| ~~~~~~~~~~~~~~~~~~
2120

2221
error: aborting due to 2 previous errors
2322

tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ LL | let f: F = async { 1 };
99
|
1010
help: a trait with a similar name exists
1111
|
12-
LL - let f: F = async { 1 };
13-
LL + let f: Fn = async { 1 };
14-
|
12+
LL | let f: Fn = async { 1 };
13+
| ~~
1514
help: you might be missing a type parameter
1615
|
1716
LL | fn f<T, F>(

0 commit comments

Comments
 (0)