diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2024-03-12 09:04:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-12 09:04:02 -0700 |
| commit | 0b313752486a8a6d3374330b20d6b62953776e2b (patch) | |
| tree | 1b04380b681f2476404592c6655b8af737f0533e | |
| parent | 778c76c6a700f96303684b647ee2e692f0c36319 (diff) | |
| parent | 783490da703617b030b29301c844c93fe672f777 (diff) | |
| download | rust-0b313752486a8a6d3374330b20d6b62953776e2b.tar.gz rust-0b313752486a8a6d3374330b20d6b62953776e2b.zip | |
Rollup merge of #122366 - oli-obk:opaques_defined_by_overflow, r=lcnr
Fix stack overflow with recursive associated types fixes #122364
| -rw-r--r-- | compiler/rustc_ty_utils/src/opaque_types.rs | 4 | ||||
| -rw-r--r-- | tests/ui/impl-trait/associated-type-cycle.rs | 14 | ||||
| -rw-r--r-- | tests/ui/impl-trait/associated-type-cycle.stderr | 12 |
3 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 96d00dc05fd..fc16edc6d13 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -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, diff --git a/tests/ui/impl-trait/associated-type-cycle.rs b/tests/ui/impl-trait/associated-type-cycle.rs new file mode 100644 index 00000000000..4c1fc1a0fa6 --- /dev/null +++ b/tests/ui/impl-trait/associated-type-cycle.rs @@ -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() {} diff --git a/tests/ui/impl-trait/associated-type-cycle.stderr b/tests/ui/impl-trait/associated-type-cycle.stderr new file mode 100644 index 00000000000..7eef8d1e338 --- /dev/null +++ b/tests/ui/impl-trait/associated-type-cycle.stderr @@ -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`. |
