Skip to content

Commit b263b7e

Browse files
authored
Rollup merge of #102338 - compiler-errors:assoc-ty-binding-in-assoc-ty-binding, r=cjgillot
Deny associated type bindings within associated type bindings Fixes #102335 This was made worse by #100865, which unified the way we generate substs for GATs and non-generic associated types. However, the issue was not _caused_ by #100865, evidenced by the test I added for GATs: ```rust trait T { type A: S<C<(), i32 = ()> = ()>; //~^ ERROR associated type bindings are not allowed here } trait Q {} trait S { type C<T>: Q; } fn main() {} ``` ^ which passes on beta (where GATs are stable) and presumably ever since GATs support was added to `create_substs_for_associated_item` in astconv.
2 parents 9436ffc + ca2e0bb commit b263b7e

File tree

9 files changed

+82
-5
lines changed

9 files changed

+82
-5
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -595,16 +595,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
595595
"create_substs_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
596596
span, item_def_id, item_segment
597597
);
598-
self.create_substs_for_ast_path(
598+
let (args, _) = self.create_substs_for_ast_path(
599599
span,
600600
item_def_id,
601601
parent_substs,
602602
item_segment,
603603
item_segment.args(),
604604
item_segment.infer_args,
605605
None,
606-
)
607-
.0
606+
);
607+
608+
let assoc_bindings = self.create_assoc_bindings_for_generic_args(item_segment.args());
609+
if let Some(b) = assoc_bindings.first() {
610+
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
611+
}
612+
613+
args
608614
}
609615

610616
/// Instantiates the path for the given trait reference, assuming that it's
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(associated_const_equality)]
2+
3+
trait T {
4+
type A: S<C<X = 0i32> = 34>;
5+
//~^ ERROR associated type bindings are not allowed here
6+
}
7+
8+
trait S {
9+
const C: i32;
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0229]: associated type bindings are not allowed here
2+
--> $DIR/issue-102335-const.rs:4:17
3+
|
4+
LL | type A: S<C<X = 0i32> = 34>;
5+
| ^^^^^^^^ associated type not allowed here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0229`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait T {
2+
type A: S<C<i32 = u32> = ()>;
3+
//~^ ERROR associated type bindings are not allowed here
4+
}
5+
6+
trait Q {}
7+
8+
trait S {
9+
type C: Q;
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0229]: associated type bindings are not allowed here
2+
--> $DIR/issue-102335-ty.rs:2:17
3+
|
4+
LL | type A: S<C<i32 = u32> = ()>;
5+
| ^^^^^^^^^ associated type not allowed here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0229`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait T {
2+
type A: S<C<(), i32 = ()> = ()>;
3+
//~^ ERROR associated type bindings are not allowed here
4+
}
5+
6+
trait Q {}
7+
8+
trait S {
9+
type C<T>: Q;
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0229]: associated type bindings are not allowed here
2+
--> $DIR/issue-102335-gat.rs:2:21
3+
|
4+
LL | type A: S<C<(), i32 = ()> = ()>;
5+
| ^^^^^^^^ associated type not allowed here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0229`.

src/test/ui/suggestions/issue-85347.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::ops::Deref;
22
trait Foo {
33
type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
44
//~^ ERROR this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
5+
//~| ERROR associated type bindings are not allowed here
56
//~| HELP add missing
67
}
78

src/test/ui/suggestions/issue-85347.stderr

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ help: add missing lifetime argument
1414
LL | type Bar<'a>: Deref<Target = <Self>::Bar<'a, Target = Self>>;
1515
| +++
1616

17-
error: aborting due to previous error
17+
error[E0229]: associated type bindings are not allowed here
18+
--> $DIR/issue-85347.rs:3:46
19+
|
20+
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
21+
| ^^^^^^^^^^^^^ associated type not allowed here
22+
23+
error: aborting due to 2 previous errors
1824

19-
For more information about this error, try `rustc --explain E0107`.
25+
Some errors have detailed explanations: E0107, E0229.
26+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)