Skip to content

Commit

Permalink
Unrolled build for rust-lang#122366
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#122366 - oli-obk:opaques_defined_by_overflow, r=lcnr

Fix stack overflow with recursive associated types

fixes rust-lang#122364
  • Loading branch information
rust-timer committed Mar 12, 2024
2 parents 7de1a1f + 783490d commit 465c5e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_ty_utils/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
continue;
}

if !self.seen.insert(assoc.def_id.expect_local()) {
return;
}

let impl_args = alias_ty.args.rebase_onto(
self.tcx,
impl_trait_ref.def_id,
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/impl-trait/associated-type-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait Foo {
type Bar;
fn foo(self) -> Self::Bar;
}

impl Foo for Box<dyn Foo> {
//~^ ERROR: the value of the associated type `Bar` in `Foo` must be specified
type Bar = <Self as Foo>::Bar;
fn foo(self) -> <Self as Foo>::Bar {
(*self).foo()
}
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/impl-trait/associated-type-cycle.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0191]: the value of the associated type `Bar` in `Foo` must be specified
--> $DIR/associated-type-cycle.rs:6:22
|
LL | type Bar;
| -------- `Bar` defined here
...
LL | impl Foo for Box<dyn Foo> {
| ^^^ help: specify the associated type: `Foo<Bar = Type>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0191`.

0 comments on commit 465c5e3

Please sign in to comment.