Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 00ff515

Browse files
authoredApr 23, 2024··
Unrolled build for rust-lang#122591
Rollup merge of rust-lang#122591 - gurry:122162-impl-type-binding-suggestion, r=fmease Suggest using type args directly instead of equality constraint When type arguments are written erroneously using an equality constraint we suggest specifying them directly without the equality constraint. Fixes rust-lang#122162 Changes the diagnostic in the issue from: ```rust error[E0229]: associated type bindings are not allowed here 9 | impl std::cmp::PartialEq<Rhs = T> for S { | ^^^^^^^ associated type not allowed here | ``` to ```rust error[E0229]: associated type bindings are not allowed here 9 | impl std::cmp::PartialEq<Rhs = T> for S { | ^^^^^^^ associated type not allowed here | help: to use `T` as a generic argument specify it directly | | impl std::cmp::PartialEq<T> for S { | ~ ```
2 parents cd90d5c + f7ebad4 commit 00ff515

File tree

17 files changed

+707
-29
lines changed

17 files changed

+707
-29
lines changed
 

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 109 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::def::{DefKind, Res};
1717
use rustc_hir::def_id::{DefId, LocalDefId};
1818
use rustc_infer::traits::FulfillmentError;
1919
use rustc_middle::query::Key;
20+
use rustc_middle::ty::GenericParamDefKind;
2021
use rustc_middle::ty::{self, suggest_constraining_type_param};
2122
use rustc_middle::ty::{AdtDef, Ty, TyCtxt, TypeVisitableExt};
2223
use rustc_middle::ty::{Binder, TraitRef};
@@ -1200,12 +1201,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12001201
/// Emits an error regarding forbidden type binding associations
12011202
pub fn prohibit_assoc_item_binding(
12021203
tcx: TyCtxt<'_>,
1203-
span: Span,
1204-
segment: Option<(&hir::PathSegment<'_>, Span)>,
1204+
binding: &hir::TypeBinding<'_>,
1205+
segment: Option<(DefId, &hir::PathSegment<'_>, Span)>,
12051206
) -> ErrorGuaranteed {
1206-
tcx.dcx().emit_err(AssocTypeBindingNotAllowed {
1207-
span,
1208-
fn_trait_expansion: if let Some((segment, span)) = segment
1207+
let mut err = tcx.dcx().create_err(AssocTypeBindingNotAllowed {
1208+
span: binding.span,
1209+
fn_trait_expansion: if let Some((_, segment, span)) = segment
12091210
&& segment.args().parenthesized == hir::GenericArgsParentheses::ParenSugar
12101211
{
12111212
Some(ParenthesizedFnTraitExpansion {
@@ -1215,7 +1216,109 @@ pub fn prohibit_assoc_item_binding(
12151216
} else {
12161217
None
12171218
},
1218-
})
1219+
});
1220+
1221+
// Emit a suggestion to turn the assoc item binding into a generic arg
1222+
// if the relevant item has a generic param whose name matches the binding name;
1223+
// otherwise suggest the removal of the binding.
1224+
if let Some((def_id, segment, _)) = segment
1225+
&& segment.args().parenthesized == hir::GenericArgsParentheses::No
1226+
&& let hir::TypeBindingKind::Equality { term } = binding.kind
1227+
{
1228+
// Suggests removal of the offending binding
1229+
let suggest_removal = |e: &mut Diag<'_>| {
1230+
let bindings = segment.args().bindings;
1231+
let args = segment.args().args;
1232+
let binding_span = binding.span;
1233+
1234+
// Compute the span to remove based on the position
1235+
// of the binding. We do that as follows:
1236+
// 1. Find the index of the binding in the list of bindings
1237+
// 2. Locate the spans preceding and following the binding.
1238+
// If it's the first binding the preceding span would be
1239+
// that of the last arg
1240+
// 3. Using this information work out whether the span
1241+
// to remove will start from the end of the preceding span,
1242+
// the start of the next span or will simply be the
1243+
// span encomassing everything within the generics brackets
1244+
1245+
let Some(binding_index) = bindings.iter().position(|b| b.hir_id == binding.hir_id)
1246+
else {
1247+
bug!("a type binding exists but its HIR ID not found in generics");
1248+
};
1249+
1250+
let preceding_span = if binding_index > 0 {
1251+
Some(bindings[binding_index - 1].span)
1252+
} else {
1253+
args.last().map(|a| a.span())
1254+
};
1255+
1256+
let next_span = if binding_index < bindings.len() - 1 {
1257+
Some(bindings[binding_index + 1].span)
1258+
} else {
1259+
None
1260+
};
1261+
1262+
let removal_span = match (preceding_span, next_span) {
1263+
(Some(prec), _) => binding_span.with_lo(prec.hi()),
1264+
(None, Some(next)) => binding_span.with_hi(next.lo()),
1265+
(None, None) => {
1266+
let Some(generics_span) = segment.args().span_ext() else {
1267+
bug!("a type binding exists but generic span is empty");
1268+
};
1269+
1270+
generics_span
1271+
}
1272+
};
1273+
1274+
// Now emit the suggestion
1275+
if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(removal_span) {
1276+
e.span_suggestion_verbose(
1277+
removal_span,
1278+
"consider removing this type binding",
1279+
suggestion,
1280+
Applicability::MaybeIncorrect,
1281+
);
1282+
}
1283+
};
1284+
1285+
// Suggest replacing the associated item binding with a generic argument.
1286+
// i.e., replacing `<..., T = A, ...>` with `<..., A, ...>`.
1287+
let suggest_direct_use = |e: &mut Diag<'_>, sp: Span| {
1288+
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(sp) {
1289+
e.span_suggestion_verbose(
1290+
binding.span,
1291+
format!("to use `{snippet}` as a generic argument specify it directly"),
1292+
snippet,
1293+
Applicability::MaybeIncorrect,
1294+
);
1295+
}
1296+
};
1297+
1298+
// Check if the type has a generic param with the
1299+
// same name as the assoc type name in type binding
1300+
let generics = tcx.generics_of(def_id);
1301+
let matching_param =
1302+
generics.params.iter().find(|p| p.name.as_str() == binding.ident.as_str());
1303+
1304+
// Now emit the appropriate suggestion
1305+
if let Some(matching_param) = matching_param {
1306+
match (&matching_param.kind, term) {
1307+
(GenericParamDefKind::Type { .. }, hir::Term::Ty(ty)) => {
1308+
suggest_direct_use(&mut err, ty.span);
1309+
}
1310+
(GenericParamDefKind::Const { .. }, hir::Term::Const(c)) => {
1311+
let span = tcx.hir().span(c.hir_id);
1312+
suggest_direct_use(&mut err, span);
1313+
}
1314+
_ => suggest_removal(&mut err),
1315+
}
1316+
} else {
1317+
suggest_removal(&mut err);
1318+
}
1319+
}
1320+
1321+
err.emit()
12191322
}
12201323

12211324
pub(crate) fn fn_trait_to_string(

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub(crate) fn check_generic_arg_count(
454454
if gen_pos != GenericArgPosition::Type
455455
&& let Some(b) = gen_args.bindings.first()
456456
{
457-
prohibit_assoc_item_binding(tcx, b.span, None);
457+
prohibit_assoc_item_binding(tcx, b, None);
458458
}
459459

460460
let explicit_late_bound =

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
323323
ty::BoundConstness::NotConst,
324324
);
325325
if let Some(b) = item_segment.args().bindings.first() {
326-
prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span)));
326+
prohibit_assoc_item_binding(self.tcx(), b, Some((def_id, item_segment, span)));
327327
}
328328
args
329329
}
@@ -620,7 +620,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
620620
ty::BoundConstness::NotConst,
621621
);
622622
if let Some(b) = item_segment.args().bindings.first() {
623-
prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span)));
623+
prohibit_assoc_item_binding(self.tcx(), b, Some((item_def_id, item_segment, span)));
624624
}
625625
args
626626
}
@@ -765,7 +765,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
765765
constness,
766766
);
767767
if let Some(b) = trait_segment.args().bindings.first() {
768-
prohibit_assoc_item_binding(self.tcx(), b.span, Some((trait_segment, span)));
768+
prohibit_assoc_item_binding(self.tcx(), b, Some((trait_def_id, trait_segment, span)));
769769
}
770770
ty::TraitRef::new(self.tcx(), trait_def_id, generic_args)
771771
}
@@ -1544,7 +1544,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15441544
for segment in segments {
15451545
// Only emit the first error to avoid overloading the user with error messages.
15461546
if let Some(b) = segment.args().bindings.first() {
1547-
return Err(prohibit_assoc_item_binding(self.tcx(), b.span, None));
1547+
return Err(prohibit_assoc_item_binding(self.tcx(), b, None));
15481548
}
15491549
}
15501550

‎tests/rustdoc-ui/invalid_associated_const.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0229]: associated type bindings are not allowed here
33
|
44
LL | type A: S<C<X = 0i32> = 34>;
55
| ^^^^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | type A: S<C<X = 0i32> = 34>;
10+
| ~~~~~~~~~~
611

712
error[E0229]: associated type bindings are not allowed here
813
--> $DIR/invalid_associated_const.rs:4:17
@@ -11,6 +16,10 @@ LL | type A: S<C<X = 0i32> = 34>;
1116
| ^^^^^^^^ associated type not allowed here
1217
|
1318
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
help: consider removing this type binding
20+
|
21+
LL | type A: S<C<X = 0i32> = 34>;
22+
| ~~~~~~~~~~
1423

1524
error: aborting due to 2 previous errors
1625

‎tests/rustdoc-ui/issue-102467.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0229]: associated type bindings are not allowed here
33
|
44
LL | type A: S<C<X = 0i32> = 34>;
55
| ^^^^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | type A: S<C<X = 0i32> = 34>;
10+
| ~~~~~~~~~~
611

712
error[E0229]: associated type bindings are not allowed here
813
--> $DIR/issue-102467.rs:7:17
@@ -11,6 +16,10 @@ LL | type A: S<C<X = 0i32> = 34>;
1116
| ^^^^^^^^ associated type not allowed here
1217
|
1318
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
help: consider removing this type binding
20+
|
21+
LL | type A: S<C<X = 0i32> = 34>;
22+
| ~~~~~~~~~~
1423

1524
error: aborting due to 2 previous errors
1625

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0229]: associated type bindings are not allowed here
33
|
44
LL | type A: S<C<X = 0i32> = 34>;
55
| ^^^^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | type A: S<C<X = 0i32> = 34>;
10+
| ~~~~~~~~~~
611

712
error[E0229]: associated type bindings are not allowed here
813
--> $DIR/issue-102335-const.rs:4:17
@@ -11,6 +16,10 @@ LL | type A: S<C<X = 0i32> = 34>;
1116
| ^^^^^^^^ associated type not allowed here
1217
|
1318
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
help: consider removing this type binding
20+
|
21+
LL | type A: S<C<X = 0i32> = 34>;
22+
| ~~~~~~~~~~
1423

1524
error: aborting due to 2 previous errors
1625

‎tests/ui/associated-type-bounds/issue-102335-ty.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
trait T {
2-
type A: S<C<i32 = u32> = ()>;
2+
type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
3+
//~^ ERROR associated type bindings are not allowed here
4+
//~| ERROR associated type bindings are not allowed here
5+
}
6+
7+
trait T2 {
8+
type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
39
//~^ ERROR associated type bindings are not allowed here
410
//~| ERROR associated type bindings are not allowed here
511
}
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
11
error[E0229]: associated type bindings are not allowed here
22
--> $DIR/issue-102335-ty.rs:2:17
33
|
4-
LL | type A: S<C<i32 = u32> = ()>;
4+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
55
| ^^^^^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
10+
| ~~~~~~~~~~~
611

712
error[E0229]: associated type bindings are not allowed here
813
--> $DIR/issue-102335-ty.rs:2:17
914
|
10-
LL | type A: S<C<i32 = u32> = ()>;
15+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
16+
| ^^^^^^^^^ associated type not allowed here
17+
|
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
help: consider removing this type binding
20+
|
21+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
22+
| ~~~~~~~~~~~
23+
24+
error[E0229]: associated type bindings are not allowed here
25+
--> $DIR/issue-102335-ty.rs:8:17
26+
|
27+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
28+
| ^^^^^^^^^ associated type not allowed here
29+
|
30+
help: consider removing this type binding
31+
|
32+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
33+
| ~~~~~~~~~~
34+
35+
error[E0229]: associated type bindings are not allowed here
36+
--> $DIR/issue-102335-ty.rs:8:17
37+
|
38+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
1139
| ^^^^^^^^^ associated type not allowed here
1240
|
1341
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
42+
help: consider removing this type binding
43+
|
44+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
45+
| ~~~~~~~~~~
1446

15-
error: aborting due to 2 previous errors
47+
error: aborting due to 4 previous errors
1648

1749
For more information about this error, try `rustc --explain E0229`.
Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,125 @@
11
// Test equality constraints on associated types. Check we get an error when an
2-
// equality constraint is used in a qualified path.
2+
// equality constraint is used in an invalid context
33

4-
pub trait Foo {
4+
struct Bar;
5+
struct Qux;
6+
7+
// Tests for a a non generic trait
8+
pub trait Tr1 {
59
type A;
6-
fn boo(&self) -> <Self as Foo>::A;
10+
fn boo(&self) -> <Self as Tr1>::A;
711
}
812

9-
struct Bar;
10-
11-
impl Foo for isize {
13+
impl Tr1 for isize {
1214
type A = usize;
1315
fn boo(&self) -> usize { 42 }
1416
}
1517

16-
fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {}
18+
// Test for when the assoc type is
19+
// specified as an equality constraint
20+
impl Tr1<A = usize> for usize {
21+
//~^ ERROR associated type bindings are not allowed here
22+
//~| ERROR not all trait items implemented, missing: `A`
23+
fn boo(&self) -> usize { 42 }
24+
}
25+
26+
// Test for a wronngly used equality constraint in a func arg
27+
fn baz<I: Tr1>(_x: &<I as Tr1<A=Bar>>::A) {}
28+
//~^ ERROR associated type bindings are not allowed here
29+
30+
31+
32+
// Tests for a generic trait
33+
trait Tr2<T1, T2, T3> {
34+
}
35+
36+
// Test for when wrongly specifed equality constraint's ident
37+
// matches some generic param's ident
38+
// (Note: E0229 is emitted only for the first erroneous equality
39+
// constraint (T2) not for any subequent ones (e.g. T3))
40+
impl Tr2<i32, T2 = Qux, T3 = usize> for Bar {
41+
//~^ ERROR associated type bindings are not allowed here
42+
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied
43+
}
44+
45+
// Test for when equality constraint's ident matches a
46+
// generic param's ident but has different case
47+
impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
48+
//~^ ERROR associated type bindings are not allowed here
49+
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied
50+
}
51+
52+
// Test for when equality constraint's ident
53+
// matches none of the generic param idents
54+
impl Tr2<i32, X = Qux, Y = usize> for Bar {
55+
//~^ ERROR associated type bindings are not allowed here
56+
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied
57+
}
58+
59+
// Test for when the term in equality constraint is itself generic
60+
struct GenericTerm<T> { _t: T }
61+
impl Tr2<i32, Qux, T3 = GenericTerm<i32>> for Bar {
62+
//~^ ERROR associated type bindings are not allowed here
63+
//~| ERROR trait takes 3 generic arguments but 2 generic arguments were supplied
64+
}
65+
66+
67+
68+
// Tests for a trait with a const param
69+
trait Tr3<const N: i32, T2, T3> {
70+
}
71+
72+
// Test for when equality constraint's ident
73+
// matches the const param's ident
74+
// (Deliberately spread over multiple lines to test that
75+
// our suggestion spans are kosher in the face of such formatting)
76+
impl Tr3<N
1777
//~^ ERROR associated type bindings are not allowed here
78+
//~| ERROR associated const equality is incomplete
79+
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
80+
= 42, T2 = Qux, T3 = usize> for Bar {
81+
}
82+
83+
// Test for when equality constraint's ident
84+
// matches the const param's ident but has a different case
85+
impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
86+
//~^ ERROR associated type bindings are not allowed here
87+
//~| ERROR associated const equality is incomplete
88+
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
89+
}
90+
91+
// Test for when equality constraint's ident
92+
// matches the const param ident but the constraint is a type arg
93+
impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
94+
//~^ ERROR associated type bindings are not allowed here
95+
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
96+
}
97+
98+
// Test for when equality constraint's ident
99+
// matches a type param ident but the constraint is a const arg
100+
impl Tr3<42, T2 = 42, T3 = usize> for Bar {
101+
//~^ ERROR associated type bindings are not allowed here
102+
//~| ERROR associated const equality is incomplete
103+
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied
104+
}
105+
106+
// Test for when equality constraint's ident
107+
// matches none of the param idents
108+
impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
109+
//~^ ERROR associated type bindings are not allowed here
110+
//~| ERROR associated const equality is incomplete
111+
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
112+
}
113+
114+
115+
116+
// Test for the case when lifetimes are present
117+
struct St<'a, T> { v: &'a T }
118+
119+
impl<'a, T> St<'a , T = Qux> {
120+
//~^ ERROR associated type bindings are not allowed here
121+
//~| ERROR struct takes 1 generic argument but 0 generic arguments were supplied
122+
}
123+
18124

19125
pub fn main() {}
Lines changed: 361 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,365 @@
1+
error[E0658]: associated const equality is incomplete
2+
--> $DIR/associated-types-eq-2.rs:76:10
3+
|
4+
LL | impl Tr3<N
5+
| __________^
6+
LL | |
7+
LL | |
8+
LL | |
9+
LL | | = 42, T2 = Qux, T3 = usize> for Bar {
10+
| |____^
11+
|
12+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
13+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
14+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
15+
16+
error[E0658]: associated const equality is incomplete
17+
--> $DIR/associated-types-eq-2.rs:85:10
18+
|
19+
LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
20+
| ^^^^^^
21+
|
22+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
23+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
24+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
25+
26+
error[E0658]: associated const equality is incomplete
27+
--> $DIR/associated-types-eq-2.rs:100:14
28+
|
29+
LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
30+
| ^^^^^^^
31+
|
32+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
33+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
34+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
35+
36+
error[E0658]: associated const equality is incomplete
37+
--> $DIR/associated-types-eq-2.rs:108:10
38+
|
39+
LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
40+
| ^^^^^^
41+
|
42+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
43+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
44+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
45+
146
error[E0229]: associated type bindings are not allowed here
2-
--> $DIR/associated-types-eq-2.rs:16:30
47+
--> $DIR/associated-types-eq-2.rs:20:10
48+
|
49+
LL | impl Tr1<A = usize> for usize {
50+
| ^^^^^^^^^ associated type not allowed here
51+
|
52+
help: consider removing this type binding
53+
|
54+
LL | impl Tr1<A = usize> for usize {
55+
| ~~~~~~~~~~~
56+
57+
error[E0046]: not all trait items implemented, missing: `A`
58+
--> $DIR/associated-types-eq-2.rs:20:1
59+
|
60+
LL | type A;
61+
| ------ `A` from trait
62+
...
63+
LL | impl Tr1<A = usize> for usize {
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `A` in implementation
65+
66+
error[E0229]: associated type bindings are not allowed here
67+
--> $DIR/associated-types-eq-2.rs:27:31
68+
|
69+
LL | fn baz<I: Tr1>(_x: &<I as Tr1<A=Bar>>::A) {}
70+
| ^^^^^ associated type not allowed here
71+
|
72+
help: consider removing this type binding
73+
|
74+
LL | fn baz<I: Tr1>(_x: &<I as Tr1<A=Bar>>::A) {}
75+
| ~~~~~~~
76+
77+
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
78+
--> $DIR/associated-types-eq-2.rs:40:6
79+
|
80+
LL | impl Tr2<i32, T2 = Qux, T3 = usize> for Bar {
81+
| ^^^ --- supplied 1 generic argument
82+
| |
83+
| expected 3 generic arguments
84+
|
85+
note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3`
86+
--> $DIR/associated-types-eq-2.rs:33:7
87+
|
88+
LL | trait Tr2<T1, T2, T3> {
89+
| ^^^ -- -- --
90+
help: add missing generic arguments
91+
|
92+
LL | impl Tr2<i32, T2, T3, T2 = Qux, T3 = usize> for Bar {
93+
| ++++++++
94+
95+
error[E0229]: associated type bindings are not allowed here
96+
--> $DIR/associated-types-eq-2.rs:40:15
97+
|
98+
LL | impl Tr2<i32, T2 = Qux, T3 = usize> for Bar {
99+
| ^^^^^^^^ associated type not allowed here
100+
|
101+
help: to use `Qux` as a generic argument specify it directly
102+
|
103+
LL | impl Tr2<i32, Qux, T3 = usize> for Bar {
104+
| ~~~
105+
106+
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
107+
--> $DIR/associated-types-eq-2.rs:47:6
108+
|
109+
LL | impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
110+
| ^^^ --- supplied 1 generic argument
111+
| |
112+
| expected 3 generic arguments
113+
|
114+
note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3`
115+
--> $DIR/associated-types-eq-2.rs:33:7
116+
|
117+
LL | trait Tr2<T1, T2, T3> {
118+
| ^^^ -- -- --
119+
help: add missing generic arguments
120+
|
121+
LL | impl Tr2<i32, T2, T3, t2 = Qux, T3 = usize> for Qux {
122+
| ++++++++
123+
124+
error[E0229]: associated type bindings are not allowed here
125+
--> $DIR/associated-types-eq-2.rs:47:15
126+
|
127+
LL | impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
128+
| ^^^^^^^^ associated type not allowed here
129+
|
130+
help: consider removing this type binding
131+
|
132+
LL | impl Tr2<i32, t2 = Qux, T3 = usize> for Qux {
133+
| ~~~~~~~~~~
134+
135+
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
136+
--> $DIR/associated-types-eq-2.rs:54:6
137+
|
138+
LL | impl Tr2<i32, X = Qux, Y = usize> for Bar {
139+
| ^^^ --- supplied 1 generic argument
140+
| |
141+
| expected 3 generic arguments
142+
|
143+
note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3`
144+
--> $DIR/associated-types-eq-2.rs:33:7
145+
|
146+
LL | trait Tr2<T1, T2, T3> {
147+
| ^^^ -- -- --
148+
help: add missing generic arguments
149+
|
150+
LL | impl Tr2<i32, T2, T3, X = Qux, Y = usize> for Bar {
151+
| ++++++++
152+
153+
error[E0229]: associated type bindings are not allowed here
154+
--> $DIR/associated-types-eq-2.rs:54:15
155+
|
156+
LL | impl Tr2<i32, X = Qux, Y = usize> for Bar {
157+
| ^^^^^^^ associated type not allowed here
158+
|
159+
help: consider removing this type binding
160+
|
161+
LL | impl Tr2<i32, X = Qux, Y = usize> for Bar {
162+
| ~~~~~~~~~
163+
164+
error[E0107]: trait takes 3 generic arguments but 2 generic arguments were supplied
165+
--> $DIR/associated-types-eq-2.rs:61:6
166+
|
167+
LL | impl Tr2<i32, Qux, T3 = GenericTerm<i32>> for Bar {
168+
| ^^^ --- --- supplied 2 generic arguments
169+
| |
170+
| expected 3 generic arguments
171+
|
172+
note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3`
173+
--> $DIR/associated-types-eq-2.rs:33:7
174+
|
175+
LL | trait Tr2<T1, T2, T3> {
176+
| ^^^ -- -- --
177+
help: add missing generic argument
178+
|
179+
LL | impl Tr2<i32, Qux, T3, T3 = GenericTerm<i32>> for Bar {
180+
| ++++
181+
182+
error[E0229]: associated type bindings are not allowed here
183+
--> $DIR/associated-types-eq-2.rs:61:20
184+
|
185+
LL | impl Tr2<i32, Qux, T3 = GenericTerm<i32>> for Bar {
186+
| ^^^^^^^^^^^^^^^^^^^^^ associated type not allowed here
187+
|
188+
help: to use `GenericTerm<i32>` as a generic argument specify it directly
189+
|
190+
LL | impl Tr2<i32, Qux, GenericTerm<i32>> for Bar {
191+
| ~~~~~~~~~~~~~~~~
192+
193+
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
194+
--> $DIR/associated-types-eq-2.rs:76:6
195+
|
196+
LL | impl Tr3<N
197+
| ^^^ expected 3 generic arguments
198+
|
199+
note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3`
200+
--> $DIR/associated-types-eq-2.rs:69:7
201+
|
202+
LL | trait Tr3<const N: i32, T2, T3> {
203+
| ^^^ ------------ -- --
204+
help: add missing generic arguments
205+
|
206+
LL | impl Tr3<N, T2, T3, N
207+
| ++++++++++
208+
209+
error[E0229]: associated type bindings are not allowed here
210+
--> $DIR/associated-types-eq-2.rs:76:10
211+
|
212+
LL | impl Tr3<N
213+
| __________^
214+
LL | |
215+
LL | |
216+
LL | |
217+
LL | | = 42, T2 = Qux, T3 = usize> for Bar {
218+
| |____^ associated type not allowed here
219+
|
220+
help: to use `42` as a generic argument specify it directly
221+
|
222+
LL | impl Tr3<42, T2 = Qux, T3 = usize> for Bar {
223+
| ~~
224+
225+
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
226+
--> $DIR/associated-types-eq-2.rs:85:6
227+
|
228+
LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
229+
| ^^^ expected 3 generic arguments
230+
|
231+
note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3`
232+
--> $DIR/associated-types-eq-2.rs:69:7
233+
|
234+
LL | trait Tr3<const N: i32, T2, T3> {
235+
| ^^^ ------------ -- --
236+
help: add missing generic arguments
237+
|
238+
LL | impl Tr3<N, T2, T3, n = 42, T2 = Qux, T3 = usize> for Qux {
239+
| ++++++++++
240+
241+
error[E0229]: associated type bindings are not allowed here
242+
--> $DIR/associated-types-eq-2.rs:85:10
243+
|
244+
LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
245+
| ^^^^^^ associated type not allowed here
246+
|
247+
help: consider removing this type binding
248+
|
249+
LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
250+
| ~~~~~~~
251+
252+
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
253+
--> $DIR/associated-types-eq-2.rs:93:6
254+
|
255+
LL | impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
256+
| ^^^ expected 3 generic arguments
257+
|
258+
note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3`
259+
--> $DIR/associated-types-eq-2.rs:69:7
260+
|
261+
LL | trait Tr3<const N: i32, T2, T3> {
262+
| ^^^ ------------ -- --
263+
help: add missing generic arguments
264+
|
265+
LL | impl Tr3<N, T2, T3, N = u32, T2 = Qux, T3 = usize> for Bar {
266+
| ++++++++++
267+
268+
error[E0229]: associated type bindings are not allowed here
269+
--> $DIR/associated-types-eq-2.rs:93:10
270+
|
271+
LL | impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
272+
| ^^^^^^^ associated type not allowed here
273+
|
274+
help: consider removing this type binding
275+
|
276+
LL | impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
277+
| ~~~~~~~~
278+
279+
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
280+
--> $DIR/associated-types-eq-2.rs:100:6
281+
|
282+
LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
283+
| ^^^ -- supplied 1 generic argument
284+
| |
285+
| expected 3 generic arguments
286+
|
287+
note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3`
288+
--> $DIR/associated-types-eq-2.rs:69:7
289+
|
290+
LL | trait Tr3<const N: i32, T2, T3> {
291+
| ^^^ ------------ -- --
292+
help: add missing generic arguments
293+
|
294+
LL | impl Tr3<42, T2, T3, T2 = 42, T3 = usize> for Bar {
295+
| ++++++++
296+
297+
error[E0229]: associated type bindings are not allowed here
298+
--> $DIR/associated-types-eq-2.rs:100:14
299+
|
300+
LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
301+
| ^^^^^^^ associated type not allowed here
302+
|
303+
help: consider removing this type binding
304+
|
305+
LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
306+
| ~~~~~~~~~
307+
308+
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
309+
--> $DIR/associated-types-eq-2.rs:108:6
310+
|
311+
LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
312+
| ^^^ expected 3 generic arguments
313+
|
314+
note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3`
315+
--> $DIR/associated-types-eq-2.rs:69:7
316+
|
317+
LL | trait Tr3<const N: i32, T2, T3> {
318+
| ^^^ ------------ -- --
319+
help: add missing generic arguments
320+
|
321+
LL | impl Tr3<N, T2, T3, X = 42, Y = Qux, Z = usize> for Bar {
322+
| ++++++++++
323+
324+
error[E0229]: associated type bindings are not allowed here
325+
--> $DIR/associated-types-eq-2.rs:108:10
326+
|
327+
LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
328+
| ^^^^^^ associated type not allowed here
329+
|
330+
help: consider removing this type binding
331+
|
332+
LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
333+
| ~~~~~~~
334+
335+
error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
336+
--> $DIR/associated-types-eq-2.rs:119:13
337+
|
338+
LL | impl<'a, T> St<'a , T = Qux> {
339+
| ^^ expected 1 generic argument
340+
|
341+
note: struct defined here, with 1 generic parameter: `T`
342+
--> $DIR/associated-types-eq-2.rs:117:8
343+
|
344+
LL | struct St<'a, T> { v: &'a T }
345+
| ^^ -
346+
help: add missing generic argument
347+
|
348+
LL | impl<'a, T> St<'a, T , T = Qux> {
349+
| +++
350+
351+
error[E0229]: associated type bindings are not allowed here
352+
--> $DIR/associated-types-eq-2.rs:119:21
353+
|
354+
LL | impl<'a, T> St<'a , T = Qux> {
355+
| ^^^^^^^ associated type not allowed here
356+
|
357+
help: to use `Qux` as a generic argument specify it directly
3358
|
4-
LL | fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {}
5-
| ^^^^^ associated type not allowed here
359+
LL | impl<'a, T> St<'a , Qux> {
360+
| ~~~
6361

7-
error: aborting due to 1 previous error
362+
error: aborting due to 27 previous errors
8363

9-
For more information about this error, try `rustc --explain E0229`.
364+
Some errors have detailed explanations: E0046, E0107, E0229, E0658.
365+
For more information about an error, try `rustc --explain E0046`.

‎tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ error[E0229]: associated type bindings are not allowed here
2929
|
3030
LL | impl Foo<N = 3> for Bar {
3131
| ^^^^^ associated type not allowed here
32+
|
33+
help: to use `3` as a generic argument specify it directly
34+
|
35+
LL | impl Foo<3> for Bar {
36+
| ~
3237

3338
error: aborting due to 3 previous errors
3439

‎tests/ui/const-generics/parser-error-recovery/issue-89013.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ error[E0229]: associated type bindings are not allowed here
4141
|
4242
LL | impl Foo<N = const 3> for Bar {
4343
| ^^^^^^^^^^^ associated type not allowed here
44+
|
45+
help: to use `3` as a generic argument specify it directly
46+
|
47+
LL | impl Foo<3> for Bar {
48+
| ~
4449

4550
error: aborting due to 4 previous errors
4651

‎tests/ui/error-codes/E0229.stderr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0229]: associated type bindings are not allowed here
33
|
44
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
55
| ^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
10+
| ~~~~~~~
611

712
error[E0229]: associated type bindings are not allowed here
813
--> $DIR/E0229.rs:13:25
@@ -11,6 +16,10 @@ LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
1116
| ^^^^^ associated type not allowed here
1217
|
1318
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
help: consider removing this type binding
20+
|
21+
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
22+
| ~~~~~~~
1423

1524
error[E0229]: associated type bindings are not allowed here
1625
--> $DIR/E0229.rs:13:25
@@ -19,6 +28,10 @@ LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
1928
| ^^^^^ associated type not allowed here
2029
|
2130
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
31+
help: consider removing this type binding
32+
|
33+
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
34+
| ~~~~~~~
2235

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0229]: associated type bindings are not allowed here
33
|
44
LL | type A: S<C<(), i32 = ()> = ()>;
55
| ^^^^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | type A: S<C<(), i32 = ()> = ()>;
10+
| ~~~~~~~~~~
611

712
error[E0229]: associated type bindings are not allowed here
813
--> $DIR/issue-102335-gat.rs:2:21
@@ -11,6 +16,10 @@ LL | type A: S<C<(), i32 = ()> = ()>;
1116
| ^^^^^^^^ associated type not allowed here
1217
|
1318
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
help: consider removing this type binding
20+
|
21+
LL | type A: S<C<(), i32 = ()> = ()>;
22+
| ~~~~~~~~~~
1423

1524
error: aborting due to 2 previous errors
1625

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0229]: associated type bindings are not allowed here
33
|
44
LL | fn bar(foo: Foo<Target = usize>) {}
55
| ^^^^^^^^^^^^^^ associated type not allowed here
6+
|
7+
help: consider removing this type binding
8+
|
9+
LL | fn bar(foo: Foo<Target = usize>) {}
10+
| ~~~~~~~~~~~~~~~~
611

712
error: aborting due to 1 previous error
813

‎tests/ui/suggestions/issue-85347.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ use std::ops::Deref;
22
trait Foo {
33
type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
44
//~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
5-
//~| ERROR associated type bindings are not allowed here
65
//~| HELP add missing
7-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
86
//~| ERROR associated type bindings are not allowed here
7+
//~| HELP consider removing this type binding
8+
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
99
//~| HELP add missing
10+
//~| ERROR associated type bindings are not allowed here
11+
//~| HELP consider removing this type binding
1012
}
1113

1214
fn main() {}

‎tests/ui/suggestions/issue-85347.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ error[E0229]: associated type bindings are not allowed here
1919
|
2020
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
2121
| ^^^^^^^^^^^^^ associated type not allowed here
22+
|
23+
help: consider removing this type binding
24+
|
25+
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
26+
| ~~~~~~~~~~~~~~~
2227

2328
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
2429
--> $DIR/issue-85347.rs:3:42
@@ -44,6 +49,10 @@ LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
4449
| ^^^^^^^^^^^^^ associated type not allowed here
4550
|
4651
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
52+
help: consider removing this type binding
53+
|
54+
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
55+
| ~~~~~~~~~~~~~~~
4756

4857
error: aborting due to 4 previous errors
4958

0 commit comments

Comments
 (0)
This repository has been archived.