Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny associated type bindings within associated type bindings #102338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,16 +595,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"create_substs_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
span, item_def_id, item_segment
);
self.create_substs_for_ast_path(
let (args, _) = self.create_substs_for_ast_path(
span,
item_def_id,
parent_substs,
item_segment,
item_segment.args(),
item_segment.infer_args,
None,
)
.0
);

let assoc_bindings = self.create_assoc_bindings_for_generic_args(item_segment.args());
if let Some(b) = assoc_bindings.first() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seems wasteful to convert all bindings, just to err on the first one later. This could as well be implemented as
if let Some(b) = item_segment.args().bindings.first()
Probably better as a follow-up, as there are several instances of this pattern in the file.

Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
}

args
}

/// Instantiates the path for the given trait reference, assuming that it's
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/associated-consts/issue-102335-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(associated_const_equality)]

trait T {
type A: S<C<X = 0i32> = 34>;
//~^ ERROR associated type bindings are not allowed here
}

trait S {
const C: i32;
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/associated-consts/issue-102335-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0229]: associated type bindings are not allowed here
--> $DIR/issue-102335-const.rs:4:17
|
LL | type A: S<C<X = 0i32> = 34>;
| ^^^^^^^^ associated type not allowed here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0229`.
12 changes: 12 additions & 0 deletions src/test/ui/associated-type-bounds/issue-102335-ty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
trait T {
type A: S<C<i32 = u32> = ()>;
//~^ ERROR associated type bindings are not allowed here
}

trait Q {}

trait S {
type C: Q;
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/associated-type-bounds/issue-102335-ty.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0229]: associated type bindings are not allowed here
--> $DIR/issue-102335-ty.rs:2:17
|
LL | type A: S<C<i32 = u32> = ()>;
| ^^^^^^^^^ associated type not allowed here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0229`.
12 changes: 12 additions & 0 deletions src/test/ui/generic-associated-types/issue-102335-gat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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() {}
9 changes: 9 additions & 0 deletions src/test/ui/generic-associated-types/issue-102335-gat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0229]: associated type bindings are not allowed here
--> $DIR/issue-102335-gat.rs:2:21
|
LL | type A: S<C<(), i32 = ()> = ()>;
| ^^^^^^^^ associated type not allowed here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0229`.
1 change: 1 addition & 0 deletions src/test/ui/suggestions/issue-85347.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::ops::Deref;
trait Foo {
type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
//~^ ERROR this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
//~| ERROR associated type bindings are not allowed here
//~| HELP add missing
}

Expand Down
11 changes: 9 additions & 2 deletions src/test/ui/suggestions/issue-85347.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ help: add missing lifetime argument
LL | type Bar<'a>: Deref<Target = <Self>::Bar<'a, Target = Self>>;
| +++

error: aborting due to previous error
error[E0229]: associated type bindings are not allowed here
--> $DIR/issue-85347.rs:3:46
|
LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>;
| ^^^^^^^^^^^^^ associated type not allowed here

error: aborting due to 2 previous errors

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