Skip to content

Commit 9940da0

Browse files
Use underline suggestions for purely 'additive' replacements
1 parent 6dce9f8 commit 9940da0

File tree

107 files changed

+361
-523
lines changed

Some content is hidden

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

107 files changed

+361
-523
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 2 additions & 3 deletions
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

0 commit comments

Comments
 (0)