]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/user-annotations/normalization-2.rs
Auto merge of #106646 - Amanieu:ilp32-object, r=Mark-Simulacrum
[rust.git] / tests / ui / nll / user-annotations / normalization-2.rs
1 // Make sure we honor region constraints when normalizing type annotations.
2
3 // check-fail
4
5 #![feature(more_qualified_paths)]
6
7 trait Trait {
8     type Assoc;
9 }
10
11 impl<T> Trait for T
12 where
13     T: 'static,
14 {
15     type Assoc = MyTy<()>;
16 }
17
18 enum MyTy<T> {
19     Unit,
20     Tuple(),
21     Struct {},
22     Dumb(T),
23 }
24
25 impl<T> MyTy<T> {
26     const CONST: () = ();
27     fn method<X>() {}
28     fn method2<X>(&self) {}
29 }
30
31 trait TraitAssoc {
32     const TRAIT_CONST: ();
33     fn trait_method<X>(&self);
34 }
35 impl<T> TraitAssoc for T {
36     const TRAIT_CONST: () = ();
37     fn trait_method<X>(&self) {}
38 }
39
40 type Ty<'a> = <&'a () as Trait>::Assoc;
41
42 fn test_local<'a>() {
43     let _: Ty<'a> = MyTy::Unit;
44     //~^ ERROR lifetime may not live long enough
45 }
46
47 fn test_closure_sig<'a, 'b>() {
48     |_: Ty<'a>| {};
49     //~^ ERROR lifetime may not live long enough
50     || -> Option<Ty<'b>> { None };
51     //~^ ERROR lifetime may not live long enough
52 }
53
54 fn test_path<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h>() {
55     <Ty<'a>>::method::<Ty<'static>>;
56     //~^ ERROR lifetime may not live long enough
57     <Ty<'static>>::method::<Ty<'b>>;
58     //~^ ERROR lifetime may not live long enough
59
60     <Ty<'c>>::trait_method::<Ty<'static>>;
61     //~^ ERROR lifetime may not live long enough
62     <Ty<'static>>::trait_method::<Ty<'d>>;
63     //~^ ERROR lifetime may not live long enough
64
65     <Ty<'e>>::CONST;
66     //~^ ERROR lifetime may not live long enough
67     <Ty<'f>>::TRAIT_CONST;
68     //~^ ERROR lifetime may not live long enough
69
70     <Ty<'static>>::method::<Ty<'static>>;
71     <Ty<'static>>::trait_method::<Ty<'static>>;
72     <Ty<'static>>::CONST;
73     <Ty<'static>>::TRAIT_CONST;
74
75     MyTy::Unit::<Ty<'g>>;
76     //~^ ERROR lifetime may not live long enough
77     MyTy::<Ty<'h>>::Unit;
78     //~^ ERROR lifetime may not live long enough
79 }
80
81 fn test_call<'a, 'b, 'c>() {
82     <Ty<'a>>::method::<Ty<'static>>();
83     //~^ ERROR lifetime may not live long enough
84     <Ty<'static>>::method::<Ty<'b>>();
85     //~^ ERROR lifetime may not live long enough
86 }
87
88 fn test_variants<'a, 'b, 'c>() {
89     <Ty<'a>>::Struct {};
90     //~^ ERROR lifetime may not live long enough
91     <Ty<'b>>::Tuple();
92     //~^ ERROR lifetime may not live long enough
93     <Ty<'c>>::Unit;
94     //~^ ERROR lifetime may not live long enough
95 }
96
97 fn test_method_call<'a, 'b>(x: MyTy<()>) {
98     x.method2::<Ty<'a>>();
99     //~^ ERROR lifetime may not live long enough
100     x.trait_method::<Ty<'b>>();
101     //~^ ERROR lifetime may not live long enough
102 }
103
104 fn test_struct_path<'a, 'b, 'c, 'd>() {
105     struct Struct<T> { x: Option<T>, }
106
107     trait Project {
108         type Struct;
109         type Enum;
110     }
111     impl<T> Project for T {
112         type Struct = Struct<()>;
113         type Enum = MyTy<()>;
114     }
115
116     // Resolves to enum variant
117     MyTy::<Ty<'a>>::Struct {}; // without SelfTy
118     //~^ ERROR lifetime may not live long enough
119     <Ty<'b> as Project>::Enum::Struct {}; // with SelfTy
120     //~^ ERROR lifetime may not live long enough
121
122     // Resolves to struct and associated type respectively
123     Struct::<Ty<'c>> { x: None, }; // without SelfTy
124     //~^ ERROR lifetime may not live long enough
125     <Ty<'d> as Project>::Struct { x: None, }; // with SelfTy
126     //~^ ERROR lifetime may not live long enough
127 }
128
129 fn test_pattern<'a, 'b, 'c, 'd, 'e, 'f>() {
130     use MyTy::*;
131     match MyTy::Unit {
132         Struct::<Ty<'a>> {..} => {},
133         //~^ ERROR lifetime may not live long enough
134         Tuple::<Ty<'b>> (..) => {},
135         //~^ ERROR lifetime may not live long enough
136         Unit::<Ty<'c>> => {},
137         //~^ ERROR lifetime may not live long enough
138         Dumb(_) => {},
139     };
140     match MyTy::Unit {
141         <Ty<'d>>::Struct {..} => {},
142         //~^ ERROR lifetime may not live long enough
143         <Ty<'e>>::Tuple (..) => {},
144         //~^ ERROR lifetime may not live long enough
145         <Ty<'f>>::Unit => {},
146         //~^ ERROR lifetime may not live long enough
147         Dumb(_) => {},
148     };
149 }
150
151
152 fn main() {}