summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-31299.rs
blob: 78c3252d32e81d7a3409a2bef633aa476124150f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// run-pass
// Regression test for #31299. This was generating an overflow error
// because of eager normalization:
//
// proving `M: Sized` requires
// - proving `PtrBack<Vec<M>>: Sized` requires
//   - normalizing `Vec<<Vec<M> as Front>::Back>>: Sized` requires
//     - proving `Vec<M>: Front` requires
//       - `M: Sized` <-- cycle!
//
// If we skip the normalization step, though, everything goes fine.
//
// This could be fixed by implementing lazy normalization everywhere.
//
// However, we want this to work before then. For that, when checking
// whether a type is Sized we only check that the tails are Sized. As
// PtrBack does not have a tail, we don't need to normalize anything
// and this compiles

trait Front {
    type Back;
}

impl<T> Front for Vec<T> {
    type Back = Vec<T>;
}

struct PtrBack<T: Front>(#[allow(unused_tuple_struct_fields)] Vec<T::Back>);

struct M(#[allow(unused_tuple_struct_fields)] PtrBack<Vec<M>>);

#[allow(unused_must_use)]
fn main() {
    std::mem::size_of::<M>();
}