]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/issues/issue-31299.rs
New upstream version 1.30.0~beta.7+dfsg1
[rustc.git] / src / test / ui / run-pass / issues / issue-31299.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // run-pass
12 // Regression test for #31299. This was generating an overflow error
13 // because of eager normalization:
14 //
15 // proving `M: Sized` requires
16 // - proving `PtrBack<Vec<M>>: Sized` requires
17 // - normalizing `Vec<<Vec<M> as Front>::Back>>: Sized` requires
18 // - proving `Vec<M>: Front` requires
19 // - `M: Sized` <-- cycle!
20 //
21 // If we skip the normalization step, though, everything goes fine.
22 //
23 // This could be fixed by implementing lazy normalization everywhere.
24 //
25 // However, we want this to work before then. For that, when checking
26 // whether a type is Sized we only check that the tails are Sized. As
27 // PtrBack does not have a tail, we don't need to normalize anything
28 // and this compiles
29
30 trait Front {
31 type Back;
32 }
33
34 impl<T> Front for Vec<T> {
35 type Back = Vec<T>;
36 }
37
38 struct PtrBack<T: Front>(Vec<T::Back>);
39
40 struct M(PtrBack<Vec<M>>);
41
42 fn main() {
43 std::mem::size_of::<M>();
44 }