diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 8bc82b9f54926..4ad19a01f0245 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -535,7 +535,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } } - + ty::Adt(def, _) => { + let ty = def.sized_constraint(self.tcx()).0; + if !(ty.len() == 1 && matches!(ty[0].kind(), ty::Error(_))) { + candidates.vec.push(AutoImplCandidate) + } + } _ => candidates.vec.push(AutoImplCandidate), } } diff --git a/tests/ui/traits/issue-105231.rs b/tests/ui/traits/issue-105231.rs new file mode 100644 index 0000000000000..0252cd207f5ca --- /dev/null +++ b/tests/ui/traits/issue-105231.rs @@ -0,0 +1,8 @@ +struct A(B); +//~^ ERROR: recursive types `A` and `B` have infinite size +struct B(A>); +trait Foo {} +impl Foo for T where T: Send {} +impl Foo for B {} + +fn main() {} diff --git a/tests/ui/traits/issue-105231.stderr b/tests/ui/traits/issue-105231.stderr new file mode 100644 index 0000000000000..a335395e7108d --- /dev/null +++ b/tests/ui/traits/issue-105231.stderr @@ -0,0 +1,19 @@ +error[E0072]: recursive types `A` and `B` have infinite size + --> $DIR/issue-105231.rs:1:1 + | +LL | struct A(B); + | ^^^^^^^^^^^ ---- recursive without indirection +LL | +LL | struct B(A>); + | ^^^^^^^^^^^ ------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL ~ struct A(Box>); +LL | +LL ~ struct B(Box>>); + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`.