Skip to content

Commit 44d0e41

Browse files
authored
Unrolled build for rust-lang#127878
Rollup merge of rust-lang#127878 - estebank:assoc-item-removal, r=fmease Fix associated item removal suggestion We were previously telling people to write what was already there, instead of removal (treating it as a `help`). We now properly suggest to remove the code that needs to be removed. ``` error[E0229]: associated item constraints are not allowed here --> $DIR/E0229.rs:13:25 | LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} | ^^^^^^^ associated item constraint not allowed here | help: consider removing this associated item binding | LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} LL + fn baz<I>(x: &<I as Foo>::A) {} | ```
2 parents 4bb2f27 + e38032f commit 44d0e41

File tree

13 files changed

+101
-64
lines changed

13 files changed

+101
-64
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,12 @@ pub fn prohibit_assoc_item_constraint(
12571257
};
12581258

12591259
// Now emit the suggestion
1260-
if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(removal_span) {
1261-
e.span_suggestion_verbose(
1262-
removal_span,
1263-
format!("consider removing this associated item {}", constraint.kind.descr()),
1264-
suggestion,
1265-
Applicability::MaybeIncorrect,
1266-
);
1267-
}
1260+
e.span_suggestion_verbose(
1261+
removal_span,
1262+
format!("consider removing this associated item {}", constraint.kind.descr()),
1263+
"",
1264+
Applicability::MaybeIncorrect,
1265+
);
12681266
};
12691267

12701268
// Suggest replacing the associated item binding with a generic argument.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0432]: unresolved import `inner`
2+
--> $DIR/ice-unresolved-import-100241.rs:9:13
3+
|
4+
LL | pub use inner::S;
5+
| ^^^^^ maybe a missing crate `inner`?
6+
|
7+
= help: consider adding `extern crate inner` to use the `inner` crate
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0432`.

tests/rustdoc-ui/invalid_associated_const.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | type A: S<C<X = 0i32> = 34>;
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | type A: S<C<X = 0i32> = 34>;
10-
| ~~~~~~~~~~
9+
LL - type A: S<C<X = 0i32> = 34>;
10+
LL + type A: S<C = 34>;
11+
|
1112

1213
error[E0229]: associated item constraints are not allowed here
1314
--> $DIR/invalid_associated_const.rs:4:17
@@ -18,8 +19,9 @@ LL | type A: S<C<X = 0i32> = 34>;
1819
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1920
help: consider removing this associated item binding
2021
|
21-
LL | type A: S<C<X = 0i32> = 34>;
22-
| ~~~~~~~~~~
22+
LL - type A: S<C<X = 0i32> = 34>;
23+
LL + type A: S<C = 34>;
24+
|
2325

2426
error: aborting due to 2 previous errors
2527

tests/rustdoc-ui/issue-102467.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | type A: S<C<X = 0i32> = 34>;
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | type A: S<C<X = 0i32> = 34>;
10-
| ~~~~~~~~~~
9+
LL - type A: S<C<X = 0i32> = 34>;
10+
LL + type A: S<C = 34>;
11+
|
1112

1213
error[E0229]: associated item constraints are not allowed here
1314
--> $DIR/issue-102467.rs:7:17
@@ -18,8 +19,9 @@ LL | type A: S<C<X = 0i32> = 34>;
1819
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1920
help: consider removing this associated item binding
2021
|
21-
LL | type A: S<C<X = 0i32> = 34>;
22-
| ~~~~~~~~~~
22+
LL - type A: S<C<X = 0i32> = 34>;
23+
LL + type A: S<C = 34>;
24+
|
2325

2426
error: aborting due to 2 previous errors
2527

tests/ui/associated-consts/issue-102335-const.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | type A: S<C<X = 0i32> = 34>;
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | type A: S<C<X = 0i32> = 34>;
10-
| ~~~~~~~~~~
9+
LL - type A: S<C<X = 0i32> = 34>;
10+
LL + type A: S<C = 34>;
11+
|
1112

1213
error[E0229]: associated item constraints are not allowed here
1314
--> $DIR/issue-102335-const.rs:4:17
@@ -18,8 +19,9 @@ LL | type A: S<C<X = 0i32> = 34>;
1819
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1920
help: consider removing this associated item binding
2021
|
21-
LL | type A: S<C<X = 0i32> = 34>;
22-
| ~~~~~~~~~~
22+
LL - type A: S<C<X = 0i32> = 34>;
23+
LL + type A: S<C = 34>;
24+
|
2325

2426
error: aborting due to 2 previous errors
2527

tests/ui/associated-type-bounds/issue-102335-ty.stderr

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
10-
| ~~~~~~~~~~~
9+
LL - type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
10+
LL + type A: S<C = ()>; // Just one erroneous equality constraint
11+
|
1112

1213
error[E0229]: associated item constraints are not allowed here
1314
--> $DIR/issue-102335-ty.rs:2:17
@@ -18,8 +19,9 @@ LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
1819
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1920
help: consider removing this associated item binding
2021
|
21-
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
22-
| ~~~~~~~~~~~
22+
LL - type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
23+
LL + type A: S<C = ()>; // Just one erroneous equality constraint
24+
|
2325

2426
error[E0229]: associated item constraints are not allowed here
2527
--> $DIR/issue-102335-ty.rs:8:17
@@ -29,8 +31,9 @@ LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equal
2931
|
3032
help: consider removing this associated item binding
3133
|
32-
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
33-
| ~~~~~~~~~~
34+
LL - type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
35+
LL + type A: S<C<X = i32> = ()>; // More than one erroneous equality constraints
36+
|
3437

3538
error[E0229]: associated item constraints are not allowed here
3639
--> $DIR/issue-102335-ty.rs:8:17
@@ -41,8 +44,9 @@ LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equal
4144
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4245
help: consider removing this associated item binding
4346
|
44-
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
45-
| ~~~~~~~~~~
47+
LL - type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
48+
LL + type A: S<C<X = i32> = ()>; // More than one erroneous equality constraints
49+
|
4650

4751
error: aborting due to 4 previous errors
4852

tests/ui/associated-type-bounds/no-gat-position.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | fn next<'a>(&'a mut self) -> Option<Self::Item<'a, As1: Copy>>;
66
|
77
help: consider removing this associated item constraint
88
|
9-
LL | fn next<'a>(&'a mut self) -> Option<Self::Item<'a, As1: Copy>>;
10-
| ~~~~~~~~~~~
9+
LL - fn next<'a>(&'a mut self) -> Option<Self::Item<'a, As1: Copy>>;
10+
LL + fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
11+
|
1112

1213
error: aborting due to 1 previous error
1314

tests/ui/associated-types/associated-types-eq-2.stderr

+24-16
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ LL | impl Tr1<A = usize> for usize {
5050
|
5151
help: consider removing this associated item binding
5252
|
53-
LL | impl Tr1<A = usize> for usize {
54-
| ~~~~~~~~~~~
53+
LL - impl Tr1<A = usize> for usize {
54+
LL + impl Tr1 for usize {
55+
|
5556

5657
error[E0046]: not all trait items implemented, missing: `A`
5758
--> $DIR/associated-types-eq-2.rs:20:1
@@ -70,8 +71,9 @@ LL | fn baz<I: Tr1>(_x: &<I as Tr1<A=Bar>>::A) {}
7071
|
7172
help: consider removing this associated item binding
7273
|
73-
LL | fn baz<I: Tr1>(_x: &<I as Tr1<A=Bar>>::A) {}
74-
| ~~~~~~~
74+
LL - fn baz<I: Tr1>(_x: &<I as Tr1<A=Bar>>::A) {}
75+
LL + fn baz<I: Tr1>(_x: &<I as Tr1>::A) {}
76+
|
7577

7678
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
7779
--> $DIR/associated-types-eq-2.rs:40:6
@@ -128,8 +130,9 @@ LL | impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
128130
|
129131
help: consider removing this associated item binding
130132
|
131-
LL | impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
132-
| ~~~~~~~~~~
133+
LL - impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
134+
LL + impl Tr2<i32, T3 = usize> for Qux {
135+
|
133136

134137
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
135138
--> $DIR/associated-types-eq-2.rs:54:6
@@ -157,8 +160,9 @@ LL | impl Tr2<i32, X = Qux, Y = usize> for Bar {
157160
|
158161
help: consider removing this associated item binding
159162
|
160-
LL | impl Tr2<i32, X = Qux, Y = usize> for Bar {
161-
| ~~~~~~~~~
163+
LL - impl Tr2<i32, X = Qux, Y = usize> for Bar {
164+
LL + impl Tr2<i32, Y = usize> for Bar {
165+
|
162166

163167
error[E0107]: trait takes 3 generic arguments but 2 generic arguments were supplied
164168
--> $DIR/associated-types-eq-2.rs:61:6
@@ -228,8 +232,9 @@ LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
228232
|
229233
help: consider removing this associated item binding
230234
|
231-
LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
232-
| ~~~~~~~
235+
LL - impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
236+
LL + impl Tr3<T2 = Qux, T3 = usize> for Qux {
237+
|
233238

234239
error[E0229]: associated item constraints are not allowed here
235240
--> $DIR/associated-types-eq-2.rs:92:10
@@ -239,8 +244,9 @@ LL | impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
239244
|
240245
help: consider removing this associated item binding
241246
|
242-
LL | impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
243-
| ~~~~~~~~
247+
LL - impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
248+
LL + impl Tr3<T2 = Qux, T3 = usize> for Bar {
249+
|
244250

245251
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
246252
--> $DIR/associated-types-eq-2.rs:98:6
@@ -268,8 +274,9 @@ LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
268274
|
269275
help: consider removing this associated item binding
270276
|
271-
LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
272-
| ~~~~~~~~~
277+
LL - impl Tr3<42, T2 = 42, T3 = usize> for Bar {
278+
LL + impl Tr3<42, T3 = usize> for Bar {
279+
|
273280

274281
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
275282
--> $DIR/associated-types-eq-2.rs:106:6
@@ -295,8 +302,9 @@ LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
295302
|
296303
help: consider removing this associated item binding
297304
|
298-
LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
299-
| ~~~~~~~
305+
LL - impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
306+
LL + impl Tr3<Y = Qux, Z = usize> for Bar {
307+
|
300308

301309
error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
302310
--> $DIR/associated-types-eq-2.rs:117:13

tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ LL | impl Super1<'_, bar(..): Send> for () {}
1515
|
1616
help: consider removing this associated item constraint
1717
|
18-
LL | impl Super1<'_, bar(..): Send> for () {}
19-
| ~~~~~~~~~~~~~~~
18+
LL - impl Super1<'_, bar(..): Send> for () {}
19+
LL + impl Super1<'_> for () {}
20+
|
2021

2122
error[E0046]: not all trait items implemented, missing: `bar`
2223
--> $DIR/rtn-in-impl-signature.rs:10:1

tests/ui/error-codes/E0229.stderr

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
10-
| ~~~~~~~~~
9+
LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
10+
LL + fn baz<I>(x: &<I as Foo>::A) {}
11+
|
1112

1213
error[E0229]: associated item constraints are not allowed here
1314
--> $DIR/E0229.rs:13:25
@@ -18,8 +19,9 @@ LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
1819
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1920
help: consider removing this associated item binding
2021
|
21-
LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
22-
| ~~~~~~~~~
22+
LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
23+
LL + fn baz<I>(x: &<I as Foo>::A) {}
24+
|
2325

2426
error[E0229]: associated item constraints are not allowed here
2527
--> $DIR/E0229.rs:13:25
@@ -30,8 +32,9 @@ LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
3032
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3133
help: consider removing this associated item binding
3234
|
33-
LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
34-
| ~~~~~~~~~
35+
LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
36+
LL + fn baz<I>(x: &<I as Foo>::A) {}
37+
|
3538

3639
error[E0277]: the trait bound `I: Foo` is not satisfied
3740
--> $DIR/E0229.rs:13:15

tests/ui/generic-associated-types/issue-102335-gat.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | type A: S<C<(), i32 = ()> = ()>;
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | type A: S<C<(), i32 = ()> = ()>;
10-
| ~~~~~~~~~~
9+
LL - type A: S<C<(), i32 = ()> = ()>;
10+
LL + type A: S<C<()> = ()>;
11+
|
1112

1213
error[E0229]: associated item constraints are not allowed here
1314
--> $DIR/issue-102335-gat.rs:2:21
@@ -18,8 +19,9 @@ LL | type A: S<C<(), i32 = ()> = ()>;
1819
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1920
help: consider removing this associated item binding
2021
|
21-
LL | type A: S<C<(), i32 = ()> = ()>;
22-
| ~~~~~~~~~~
22+
LL - type A: S<C<(), i32 = ()> = ()>;
23+
LL + type A: S<C<()> = ()>;
24+
|
2325

2426
error: aborting due to 2 previous errors
2527

tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | fn bar(foo: Foo<Target = usize>) {}
66
|
77
help: consider removing this associated item binding
88
|
9-
LL | fn bar(foo: Foo<Target = usize>) {}
10-
| ~~~~~~~~~~~~~~~~
9+
LL - fn bar(foo: Foo<Target = usize>) {}
10+
LL + fn bar(foo: Foo) {}
11+
|
1112

1213
error: aborting due to 1 previous error
1314

tests/ui/suggestions/issue-85347.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
2222
|
2323
help: consider removing this associated item binding
2424
|
25-
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
26-
| ~~~~~~~~~~~~~~~
25+
LL - type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
26+
LL + type Bar<'a>: Deref<Target = <Self>::Bar>;
27+
|
2728

2829
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
2930
--> $DIR/issue-85347.rs:3:42
@@ -51,8 +52,9 @@ LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
5152
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5253
help: consider removing this associated item binding
5354
|
54-
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
55-
| ~~~~~~~~~~~~~~~
55+
LL - type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
56+
LL + type Bar<'a>: Deref<Target = <Self>::Bar>;
57+
|
5658

5759
error: aborting due to 4 previous errors
5860

0 commit comments

Comments
 (0)