Closed
Description
trait Front {
type Back;
}
impl<T> Front for Vec<T> {
type Back = Vec<T>;
}
struct PtrBack<T: Front>(*mut T::Back);
struct M(PtrBack<Vec<M>>);
fn main() {
println!("{}", std::mem::size_of::<M>());
}
This program prints 8
in Stable (1.5.0), but in Beta and Nightly compilation fails with:
<anon>:11:1: 11:27 error: recursive type `M` has infinite size [E0072]
<anon>:11 struct M(PtrBack<Vec<M>>);
^~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:11:1: 11:27 help: see the detailed explanation for E0072
<anon>:11:1: 11:27 help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `M` representable
<anon>:11:1: 11:27 note: type `M` is embedded within `PtrBack<collections::vec::Vec<M>>`...
<anon>:11:1: 11:27 note: ...which in turn is embedded within `PtrBack<collections::vec::Vec<M>>`...
<anon>:11:1: 11:27 note: ...which in turn is embedded within `M`, completing the cycle.
From 8 bytes to infinity would seem to be a serious memory usage regression.