]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-31299.rs
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
[rust.git] / src / test / ui / issues / issue-31299.rs
1 // run-pass
2 // Regression test for #31299. This was generating an overflow error
3 // because of eager normalization:
4 //
5 // proving `M: Sized` requires
6 // - proving `PtrBack<Vec<M>>: Sized` requires
7 //   - normalizing `Vec<<Vec<M> as Front>::Back>>: Sized` requires
8 //     - proving `Vec<M>: Front` requires
9 //       - `M: Sized` <-- cycle!
10 //
11 // If we skip the normalization step, though, everything goes fine.
12 //
13 // This could be fixed by implementing lazy normalization everywhere.
14 //
15 // However, we want this to work before then. For that, when checking
16 // whether a type is Sized we only check that the tails are Sized. As
17 // PtrBack does not have a tail, we don't need to normalize anything
18 // and this compiles
19
20 trait Front {
21     type Back;
22 }
23
24 impl<T> Front for Vec<T> {
25     type Back = Vec<T>;
26 }
27
28 struct PtrBack<T: Front>(Vec<T::Back>);
29
30 struct M(PtrBack<Vec<M>>);
31
32 #[allow(unused_must_use)]
33 fn main() {
34     std::mem::size_of::<M>();
35 }