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 274ad2a

Browse files
committedMar 23, 2024
Emit suggestions when equality constraints are wronlgy used
1 parent eff958c commit 274ad2a

File tree

17 files changed

+421
-25
lines changed

17 files changed

+421
-25
lines changed
 

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

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ 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, GenericParamCount, 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};
22-
use rustc_span::{Span, Symbol, DUMMY_SP};
24+
use rustc_span::{BytePos, Span, Symbol, DUMMY_SP};
2325
use rustc_trait_selection::traits::object_safety_violations_for_assoc_item;
2426

2527
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
@@ -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,78 @@ pub fn prohibit_assoc_item_binding(
10451047
None
10461048
},
10471049
});
1050+
1051+
// Emit a suggestion if possible
1052+
if let Some((def_id, segment, _)) = segment
1053+
&& segment.args().parenthesized == hir::GenericArgsParentheses::No
1054+
&& let hir::TypeBindingKind::Equality { term: binding_arg_ty } = binding.kind
1055+
{
1056+
// Suggests removal of the offending equality constraint
1057+
let suggest_removal = |e: &mut Diag<'_>| {
1058+
let mut suggestion_span = binding.span.with_hi(binding.span.hi() + BytePos(1)); // Include the comma or the angle bracket at the end
1059+
if segment.args().bindings.len() == 1 {
1060+
// If it is the only binding specified
1061+
// include the starting angle bracket as well
1062+
suggestion_span = suggestion_span.with_lo(suggestion_span.lo() - BytePos(1))
1063+
}
1064+
if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(suggestion_span) {
1065+
e.span_suggestion_verbose(
1066+
suggestion_span,
1067+
"try removing this type binding",
1068+
suggestion,
1069+
Applicability::MaybeIncorrect,
1070+
);
1071+
}
1072+
};
1073+
1074+
// Suggests replacing the quality constraint with
1075+
// normal type argument
1076+
let suggest_direct_use = |e: &mut Diag<'_>, sp: Span, is_ty: bool| {
1077+
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(sp) {
1078+
let ty_or_const = if is_ty { "generic" } else { "const" };
1079+
e.span_suggestion_verbose(
1080+
binding.span,
1081+
format!("to use `{snippet}` as a {ty_or_const} argument specify it directly"),
1082+
snippet,
1083+
Applicability::MaybeIncorrect,
1084+
);
1085+
}
1086+
};
1087+
1088+
// Get a sense of what generic args the type expects
1089+
let generics = tcx.generics_of(def_id);
1090+
let GenericParamCount { mut types, consts, .. } = generics.own_counts();
1091+
if generics.has_self && types > 0 {
1092+
types -= 1 // Ignore the `Self` type
1093+
}
1094+
1095+
// Now emit suggestion
1096+
if types == 0 && consts == 0 {
1097+
err.note(format!("`{0}` is not a generic type", segment.ident));
1098+
suggest_removal(&mut err);
1099+
} else {
1100+
match binding_arg_ty {
1101+
hir::Term::Ty(ty) => {
1102+
if types > 0 {
1103+
suggest_direct_use(&mut err, ty.span, true);
1104+
} else {
1105+
suggest_removal(&mut err);
1106+
}
1107+
}
1108+
hir::Term::Const(c) if consts > 0 => {
1109+
if consts > 0 {
1110+
let span = tcx.hir().span(c.hir_id);
1111+
suggest_direct_use(&mut err, span, false);
1112+
} else {
1113+
suggest_removal(&mut err);
1114+
}
1115+
}
1116+
_ => {}
1117+
}
1118+
}
1119+
}
1120+
1121+
err.emit();
10481122
}
10491123

10501124
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ 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+
= note: `C` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | type A: S<C<X = 0i32> = 34>;
11+
| ~~~~~~~~~~
612

713
error[E0229]: associated type bindings are not allowed here
814
--> $DIR/invalid_associated_const.rs:4:17
915
|
1016
LL | type A: S<C<X = 0i32> = 34>;
1117
| ^^^^^^^^ associated type not allowed here
1218
|
19+
= note: `C` is not a generic type
1320
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
21+
help: try removing this type binding
22+
|
23+
LL | type A: S<C<X = 0i32> = 34>;
24+
| ~~~~~~~~~~
1425

1526
error: aborting due to 2 previous errors
1627

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ 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+
= note: `C` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | type A: S<C<X = 0i32> = 34>;
11+
| ~~~~~~~~~~
612

713
error[E0229]: associated type bindings are not allowed here
814
--> $DIR/issue-102467.rs:7:17
915
|
1016
LL | type A: S<C<X = 0i32> = 34>;
1117
| ^^^^^^^^ associated type not allowed here
1218
|
19+
= note: `C` is not a generic type
1320
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
21+
help: try removing this type binding
22+
|
23+
LL | type A: S<C<X = 0i32> = 34>;
24+
| ~~~~~~~~~~
1425

1526
error: aborting due to 2 previous errors
1627

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ 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+
= note: `C` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | type A: S<C<X = 0i32> = 34>;
11+
| ~~~~~~~~~~
612

713
error[E0229]: associated type bindings are not allowed here
814
--> $DIR/issue-102335-const.rs:4:17
915
|
1016
LL | type A: S<C<X = 0i32> = 34>;
1117
| ^^^^^^^^ associated type not allowed here
1218
|
19+
= note: `C` is not a generic type
1320
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
21+
help: try removing this type binding
22+
|
23+
LL | type A: S<C<X = 0i32> = 34>;
24+
| ~~~~~~~~~~
1425

1526
error: aborting due to 2 previous errors
1627

‎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: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,53 @@
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+
= note: `C` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
11+
| ~~~~~~~~~~~
612

713
error[E0229]: associated type bindings are not allowed here
814
--> $DIR/issue-102335-ty.rs:2:17
915
|
10-
LL | type A: S<C<i32 = u32> = ()>;
16+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
17+
| ^^^^^^^^^ associated type not allowed here
18+
|
19+
= note: `C` is not a generic type
20+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
21+
help: try removing this type binding
22+
|
23+
LL | type A: S<C<i32 = u32> = ()>; // Just one erroneous equality constraint
24+
| ~~~~~~~~~~~
25+
26+
error[E0229]: associated type bindings are not allowed here
27+
--> $DIR/issue-102335-ty.rs:8:17
28+
|
29+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
30+
| ^^^^^^^^^ associated type not allowed here
31+
|
32+
= note: `C` is not a generic type
33+
help: try removing this type binding
34+
|
35+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
36+
| ~~~~~~~~~~
37+
38+
error[E0229]: associated type bindings are not allowed here
39+
--> $DIR/issue-102335-ty.rs:8:17
40+
|
41+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
1142
| ^^^^^^^^^ associated type not allowed here
1243
|
44+
= note: `C` is not a generic type
1345
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
46+
help: try removing this type binding
47+
|
48+
LL | type A: S<C<i32 = u32, X = i32> = ()>; // More than one erroneous equality constraints
49+
| ~~~~~~~~~~
1450

15-
error: aborting due to 2 previous errors
51+
error: aborting due to 4 previous errors
1652

1753
For more information about this error, try `rustc --explain E0229`.
Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,69 @@
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

44
pub trait Foo {
55
type A;
66
fn boo(&self) -> <Self as Foo>::A;
77
}
88

99
struct Bar;
10+
struct Qux;
1011

1112
impl Foo for isize {
1213
type A = usize;
1314
fn boo(&self) -> usize { 42 }
1415
}
1516

16-
fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {}
17+
fn baz<I: Foo>(_x: &<I as Foo<A=Bar>>::A) {}
1718
//~^ ERROR associated type bindings are not allowed here
1819

20+
21+
trait Tr1<T1> {
22+
}
23+
24+
impl Tr1<T1 = String> for Bar {
25+
//~^ ERROR associated type bindings are not allowed here
26+
//~| ERROR trait takes 1 generic argument but 0 generic arguments were supplied
27+
}
28+
29+
30+
trait Tr2<T1, T2, T3> {
31+
}
32+
33+
// E0229 is emitted only for the first erroneous equality
34+
// constraint (T2) not for any subequent ones (e.g. T3)
35+
impl Tr2<i32, T2 = Qux, T3 = usize> for Bar {
36+
//~^ ERROR associated type bindings are not allowed here
37+
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied
38+
}
39+
40+
struct GenericStruct<T> { _t: T }
41+
42+
impl Tr2<i32, Qux, T3 = GenericStruct<i32>> for Bar {
43+
//~^ ERROR associated type bindings are not allowed here
44+
//~| ERROR trait takes 3 generic arguments but 2 generic arguments were supplied
45+
}
46+
47+
48+
// Covers the case when the type has a const param
49+
trait Tr3<const N: i32, T2, T3> {
50+
}
51+
52+
impl Tr3<N = 42, T2 = Qux, T3 = usize> for Bar {
53+
//~^ ERROR associated type bindings are not allowed here
54+
//~| ERROR associated const equality is incomplete
55+
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
56+
}
57+
58+
59+
// Covers the case when the type
60+
// in question has no generic params
61+
trait Tr4 {
62+
}
63+
64+
impl Tr4<T = Qux, T2 = usize> for Bar {
65+
//~^ ERROR associated type bindings are not allowed here
66+
}
67+
68+
1969
pub fn main() {}
Lines changed: 146 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,150 @@
1+
error[E0658]: associated const equality is incomplete
2+
--> $DIR/associated-types-eq-2.rs:52:10
3+
|
4+
LL | impl Tr3<N = 42, T2 = Qux, T3 = usize> for Bar {
5+
| ^^^^^^
6+
|
7+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
8+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0229]: associated type bindings are not allowed here
12+
--> $DIR/associated-types-eq-2.rs:17:31
13+
|
14+
LL | fn baz<I: Foo>(_x: &<I as Foo<A=Bar>>::A) {}
15+
| ^^^^^ associated type not allowed here
16+
|
17+
= note: `Foo` is not a generic type
18+
help: try removing this type binding
19+
|
20+
LL | fn baz<I: Foo>(_x: &<I as Foo<A=Bar>>::A) {}
21+
| ~~~~~~~
22+
23+
error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
24+
--> $DIR/associated-types-eq-2.rs:24:6
25+
|
26+
LL | impl Tr1<T1 = String> for Bar {
27+
| ^^^ expected 1 generic argument
28+
|
29+
note: trait defined here, with 1 generic parameter: `T1`
30+
--> $DIR/associated-types-eq-2.rs:21:7
31+
|
32+
LL | trait Tr1<T1> {
33+
| ^^^ --
34+
help: add missing generic argument
35+
|
36+
LL | impl Tr1<T1, T1 = String> for Bar {
37+
| +++
38+
39+
error[E0229]: associated type bindings are not allowed here
40+
--> $DIR/associated-types-eq-2.rs:24:10
41+
|
42+
LL | impl Tr1<T1 = String> for Bar {
43+
| ^^^^^^^^^^^ associated type not allowed here
44+
|
45+
help: to use `String` as a generic argument specify it directly
46+
|
47+
LL | impl Tr1<String> for Bar {
48+
| ~~~~~~
49+
50+
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
51+
--> $DIR/associated-types-eq-2.rs:35:6
52+
|
53+
LL | impl Tr2<i32, T2 = Qux, T3 = usize> for Bar {
54+
| ^^^ --- supplied 1 generic argument
55+
| |
56+
| expected 3 generic arguments
57+
|
58+
note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3`
59+
--> $DIR/associated-types-eq-2.rs:30:7
60+
|
61+
LL | trait Tr2<T1, T2, T3> {
62+
| ^^^ -- -- --
63+
help: add missing generic arguments
64+
|
65+
LL | impl Tr2<i32, T2, T3, T2 = Qux, T3 = usize> for Bar {
66+
| ++++++++
67+
68+
error[E0229]: associated type bindings are not allowed here
69+
--> $DIR/associated-types-eq-2.rs:35:15
70+
|
71+
LL | impl Tr2<i32, T2 = Qux, T3 = usize> for Bar {
72+
| ^^^^^^^^ associated type not allowed here
73+
|
74+
help: to use `Qux` as a generic argument specify it directly
75+
|
76+
LL | impl Tr2<i32, Qux, T3 = usize> for Bar {
77+
| ~~~
78+
79+
error[E0107]: trait takes 3 generic arguments but 2 generic arguments were supplied
80+
--> $DIR/associated-types-eq-2.rs:42:6
81+
|
82+
LL | impl Tr2<i32, Qux, T3 = GenericStruct<i32>> for Bar {
83+
| ^^^ --- --- supplied 2 generic arguments
84+
| |
85+
| expected 3 generic arguments
86+
|
87+
note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3`
88+
--> $DIR/associated-types-eq-2.rs:30:7
89+
|
90+
LL | trait Tr2<T1, T2, T3> {
91+
| ^^^ -- -- --
92+
help: add missing generic argument
93+
|
94+
LL | impl Tr2<i32, Qux, T3, T3 = GenericStruct<i32>> for Bar {
95+
| ++++
96+
197
error[E0229]: associated type bindings are not allowed here
2-
--> $DIR/associated-types-eq-2.rs:16:30
98+
--> $DIR/associated-types-eq-2.rs:42:20
99+
|
100+
LL | impl Tr2<i32, Qux, T3 = GenericStruct<i32>> for Bar {
101+
| ^^^^^^^^^^^^^^^^^^^^^^^ associated type not allowed here
102+
|
103+
help: to use `GenericStruct<i32>` as a generic argument specify it directly
104+
|
105+
LL | impl Tr2<i32, Qux, GenericStruct<i32>> for Bar {
106+
| ~~~~~~~~~~~~~~~~~~
107+
108+
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
109+
--> $DIR/associated-types-eq-2.rs:52:6
110+
|
111+
LL | impl Tr3<N = 42, T2 = Qux, T3 = usize> for Bar {
112+
| ^^^ expected 3 generic arguments
113+
|
114+
note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3`
115+
--> $DIR/associated-types-eq-2.rs:49:7
116+
|
117+
LL | trait Tr3<const N: i32, T2, T3> {
118+
| ^^^ ------------ -- --
119+
help: add missing generic arguments
120+
|
121+
LL | impl Tr3<N, T2, T3, N = 42, T2 = Qux, T3 = usize> for Bar {
122+
| ++++++++++
123+
124+
error[E0229]: associated type bindings are not allowed here
125+
--> $DIR/associated-types-eq-2.rs:52:10
126+
|
127+
LL | impl Tr3<N = 42, T2 = Qux, T3 = usize> for Bar {
128+
| ^^^^^^ associated type not allowed here
129+
|
130+
help: to use `42` as a const argument specify it directly
131+
|
132+
LL | impl Tr3<42, T2 = Qux, T3 = usize> for Bar {
133+
| ~~
134+
135+
error[E0229]: associated type bindings are not allowed here
136+
--> $DIR/associated-types-eq-2.rs:64:10
137+
|
138+
LL | impl Tr4<T = Qux, T2 = usize> for Bar {
139+
| ^^^^^^^ associated type not allowed here
140+
|
141+
= note: `Tr4` is not a generic type
142+
help: try removing this type binding
3143
|
4-
LL | fn baz<I: Foo>(x: &<I as Foo<A=Bar>>::A) {}
5-
| ^^^^^ associated type not allowed here
144+
LL | impl Tr4<T = Qux, T2 = usize> for Bar {
145+
| ~~~~~~~~
6146

7-
error: aborting due to 1 previous error
147+
error: aborting due to 11 previous errors
8148

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

‎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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,38 @@ 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+
= note: `Foo` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
11+
| ~~~~~~~
612

713
error[E0229]: associated type bindings are not allowed here
814
--> $DIR/E0229.rs:13:25
915
|
1016
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
1117
| ^^^^^ associated type not allowed here
1218
|
19+
= note: `Foo` is not a generic type
1320
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
21+
help: try removing this type binding
22+
|
23+
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
24+
| ~~~~~~~
1425

1526
error[E0229]: associated type bindings are not allowed here
1627
--> $DIR/E0229.rs:13:25
1728
|
1829
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
1930
| ^^^^^ associated type not allowed here
2031
|
32+
= note: `Foo` is not a generic type
2133
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
34+
help: try removing this type binding
35+
|
36+
LL | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
37+
| ~~~~~~~
2238

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ 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+
= note: `C` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | type A: S<C<(), i32 = ()> = ()>;
11+
| ~~~~~~~~~
612

713
error[E0229]: associated type bindings are not allowed here
814
--> $DIR/issue-102335-gat.rs:2:21
915
|
1016
LL | type A: S<C<(), i32 = ()> = ()>;
1117
| ^^^^^^^^ associated type not allowed here
1218
|
19+
= note: `C` is not a generic type
1320
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
21+
help: try removing this type binding
22+
|
23+
LL | type A: S<C<(), i32 = ()> = ()>;
24+
| ~~~~~~~~~
1425

1526
error: aborting due to 2 previous errors
1627

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ 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+
= note: `Foo` is not a generic type
8+
help: try removing this type binding
9+
|
10+
LL | fn bar(foo: Foo<Target = usize>) {}
11+
| ~~~~~~~~~~~~~~~~
612

713
error: aborting due to 1 previous error
814

‎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 try 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 try removing this type binding
1012
}
1113

1214
fn main() {}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ 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+
= note: `Bar` is not a generic type
24+
help: try removing this type binding
25+
|
26+
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
27+
| ~~~~~~~~~~~~~~~
2228

2329
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
2430
--> $DIR/issue-85347.rs:3:42
@@ -43,7 +49,12 @@ error[E0229]: associated type bindings are not allowed here
4349
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
4450
| ^^^^^^^^^^^^^ associated type not allowed here
4551
|
52+
= note: `Bar` is not a generic type
4653
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
54+
help: try removing this type binding
55+
|
56+
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
57+
| ~~~~~~~~~~~~~~~
4758

4859
error: aborting due to 4 previous errors
4960

0 commit comments

Comments
 (0)
Please sign in to comment.