Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcdffd6

Browse files
committedApr 1, 2024
Emit suggestions when equality constraints are wronlgy used
1 parent eff958c commit fcdffd6

File tree

17 files changed

+710
-29
lines changed

17 files changed

+710
-29
lines changed
 

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

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use rustc_hir as hir;
1515
use rustc_hir::def_id::{DefId, LocalDefId};
1616
use rustc_infer::traits::FulfillmentError;
1717
use rustc_middle::query::Key;
18-
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TyCtxt, TypeVisitableExt};
18+
use rustc_middle::ty::{
19+
self, suggest_constraining_type_param, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt,
20+
};
1921
use rustc_session::parse::feature_err;
2022
use rustc_span::edit_distance::find_best_match_for_name;
2123
use rustc_span::symbol::{sym, Ident};
@@ -1029,12 +1031,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
10291031
/// Emits an error regarding forbidden type binding associations
10301032
pub fn prohibit_assoc_item_binding(
10311033
tcx: TyCtxt<'_>,
1032-
span: Span,
1033-
segment: Option<(&hir::PathSegment<'_>, Span)>,
1034+
binding: &hir::TypeBinding<'_>,
1035+
segment: Option<(DefId, &hir::PathSegment<'_>, Span)>,
10341036
) {
1035-
tcx.dcx().emit_err(AssocTypeBindingNotAllowed {
1036-
span,
1037-
fn_trait_expansion: if let Some((segment, span)) = segment
1037+
let mut err = tcx.dcx().create_err(AssocTypeBindingNotAllowed {
1038+
span: binding.span,
1039+
fn_trait_expansion: if let Some((_, segment, span)) = segment
10381040
&& segment.args().parenthesized == hir::GenericArgsParentheses::ParenSugar
10391041
{
10401042
Some(ParenthesizedFnTraitExpansion {
@@ -1045,6 +1047,110 @@ pub fn prohibit_assoc_item_binding(
10451047
None
10461048
},
10471049
});
1050+
1051+
// Emit a suggestion to use the type arg directly
1052+
// if there's a generic param with a matching name
1053+
// otherwise suggest removal of type binding
1054+
if let Some((def_id, segment, _)) = segment
1055+
&& segment.args().parenthesized == hir::GenericArgsParentheses::No
1056+
&& let hir::TypeBindingKind::Equality { term } = binding.kind
1057+
{
1058+
// Suggests removal of the offending binding
1059+
let suggest_removal = |e: &mut Diag<'_>| {
1060+
let bindings = segment.args().bindings;
1061+
let args = segment.args().args;
1062+
let binding_span = binding.span;
1063+
1064+
// Compute the span to remove based on the the position
1065+
// of the binding. We do that as follows:
1066+
// 1. Find the index of the binding in the list of bindings
1067+
// 2. Locate the spans preceding and following the binding.
1068+
// If it's the first binding the preceding span would be
1069+
// that of the last arg
1070+
// 3. Using this information work out whether the span
1071+
// to remove will start from the end of the preceding span,
1072+
// end at the start of the next span or will simply be the
1073+
// span encomassing everything within the generics brackets
1074+
1075+
let Some(binding_index) = bindings.iter().position(|b| b.hir_id == binding.hir_id)
1076+
else {
1077+
bug!("a type binding exists but its HIR ID not found in generics");
1078+
};
1079+
1080+
let preceding_span = if binding_index > 0 {
1081+
Some(bindings[binding_index - 1].span)
1082+
} else {
1083+
args.last().map(|a| a.span())
1084+
};
1085+
1086+
let next_span = if binding_index < bindings.len() - 1 {
1087+
Some(bindings[binding_index + 1].span)
1088+
} else {
1089+
None
1090+
};
1091+
1092+
let removal_span = match (preceding_span, next_span) {
1093+
(Some(prec), _) => binding_span.with_lo(prec.hi()),
1094+
(None, Some(next)) => binding_span.with_hi(next.lo()),
1095+
(None, None) => {
1096+
let Some(generics_span) = segment.args().span_ext() else {
1097+
bug!("a type binding exists but generic span is empty");
1098+
};
1099+
1100+
generics_span
1101+
}
1102+
};
1103+
1104+
// Now emit the suggestion
1105+
if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(removal_span) {
1106+
e.span_suggestion_verbose(
1107+
removal_span,
1108+
"consider removing this type binding",
1109+
suggestion,
1110+
Applicability::MaybeIncorrect,
1111+
);
1112+
}
1113+
};
1114+
1115+
// Suggests replacing the type binding with normal
1116+
// type argument (i.e. replacing <T = A> with <T>)
1117+
let suggest_direct_use = |e: &mut Diag<'_>, sp: Span, is_ty: bool| {
1118+
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(sp) {
1119+
let ty_or_const = if is_ty { "generic" } else { "const" };
1120+
e.span_suggestion_verbose(
1121+
binding.span,
1122+
format!("to use `{snippet}` as a {ty_or_const} argument specify it directly"),
1123+
snippet,
1124+
Applicability::MaybeIncorrect,
1125+
);
1126+
}
1127+
};
1128+
1129+
// Check if the type has a generic param with the
1130+
// same name as the assoc type name in type binding
1131+
let generics = tcx.generics_of(def_id);
1132+
let binding_ident_lower = binding.ident.as_str().to_lowercase();
1133+
let matching_param =
1134+
generics.params.iter().find(|p| p.name.as_str().to_lowercase() == binding_ident_lower);
1135+
1136+
// Now emit the appropriate suggestion
1137+
if let Some(matching_param) = matching_param {
1138+
match (&matching_param.kind, term) {
1139+
(GenericParamDefKind::Type { .. }, hir::Term::Ty(ty)) => {
1140+
suggest_direct_use(&mut err, ty.span, true);
1141+
}
1142+
(GenericParamDefKind::Const { .. }, hir::Term::Const(c)) => {
1143+
let span = tcx.hir().span(c.hir_id);
1144+
suggest_direct_use(&mut err, span, false);
1145+
}
1146+
_ => suggest_removal(&mut err),
1147+
}
1148+
} else {
1149+
suggest_removal(&mut err);
1150+
}
1151+
}
1152+
1153+
err.emit();
10481154
}
10491155

10501156
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
@@ -322,7 +322,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
322322
ty::BoundConstness::NotConst,
323323
);
324324
if let Some(b) = item_segment.args().bindings.first() {
325-
prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span)));
325+
prohibit_assoc_item_binding(self.tcx(), b, Some((def_id, item_segment, span)));
326326
}
327327
args
328328
}
@@ -619,7 +619,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
619619
ty::BoundConstness::NotConst,
620620
);
621621
if let Some(b) = item_segment.args().bindings.first() {
622-
prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span)));
622+
prohibit_assoc_item_binding(self.tcx(), b, Some((item_def_id, item_segment, span)));
623623
}
624624
args
625625
}
@@ -758,7 +758,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
758758
constness,
759759
);
760760
if let Some(b) = trait_segment.args().bindings.first() {
761-
prohibit_assoc_item_binding(self.tcx(), b.span, Some((trait_segment, span)));
761+
prohibit_assoc_item_binding(self.tcx(), b, Some((trait_def_id, trait_segment, span)));
762762
}
763763
ty::TraitRef::new(self.tcx(), trait_def_id, generic_args)
764764
}
@@ -1724,7 +1724,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17241724
for segment in segments {
17251725
// Only emit the first error to avoid overloading the user with error messages.
17261726
if let Some(b) = segment.args().bindings.first() {
1727-
prohibit_assoc_item_binding(self.tcx(), b.span, None);
1727+
prohibit_assoc_item_binding(self.tcx(), b, None);
17281728
return true;
17291729
}
17301730
}

‎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 outside of type parameter declarations
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: to use `Qux` as a generic argument specify it directly
131+
|
132+
LL | impl Tr2<i32, 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 const 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: to use `42` as a const argument specify it directly
248+
|
249+
LL | impl Tr3<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 const 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 const 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)
Please sign in to comment.