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`.