Skip to content

Commit 8e40dde

Browse files
committed
tests
1 parent e6dc882 commit 8e40dde

File tree

4 files changed

+368
-0
lines changed

4 files changed

+368
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
struct MyTy<T>(T);
2+
impl<T> MyTy<T> {
3+
const INHERENT: bool = true;
4+
}
5+
6+
trait Trait {
7+
const TRAIT: bool;
8+
}
9+
impl<T> Trait for MyTy<T> {
10+
const TRAIT: bool = true;
11+
}
12+
13+
fn test<'a, 'b>() {
14+
MyTy::<&'static &'a ()>::INHERENT; //~ ERROR lifetime
15+
MyTy::<&'static &'b ()>::TRAIT; //~ ERROR lifetime
16+
}
17+
18+
fn test_normalization<'a, 'b>() {
19+
trait Project {
20+
type Assoc;
21+
}
22+
impl<T: 'static> Project for T {
23+
type Assoc = &'static &'static ();
24+
}
25+
MyTy::<<&'a () as Project>::Assoc>::INHERENT; //~ ERROR lifetime
26+
MyTy::<<&'b () as Project>::Assoc>::TRAIT; //~ ERROR lifetime
27+
}
28+
29+
fn main() {}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/associated-consts.rs:14:5
3+
|
4+
LL | fn test<'a, 'b>() {
5+
| -- lifetime `'a` defined here
6+
LL | MyTy::<&'static &'a ()>::INHERENT;
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
8+
9+
error: lifetime may not live long enough
10+
--> $DIR/associated-consts.rs:15:5
11+
|
12+
LL | fn test<'a, 'b>() {
13+
| -- lifetime `'b` defined here
14+
LL | MyTy::<&'static &'a ()>::INHERENT;
15+
LL | MyTy::<&'static &'b ()>::TRAIT;
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
17+
18+
help: the following changes may resolve your lifetime errors
19+
|
20+
= help: replace `'a` with `'static`
21+
= help: replace `'b` with `'static`
22+
23+
error: lifetime may not live long enough
24+
--> $DIR/associated-consts.rs:25:5
25+
|
26+
LL | fn test_normalization<'a, 'b>() {
27+
| -- lifetime `'a` defined here
28+
...
29+
LL | MyTy::<<&'a () as Project>::Assoc>::INHERENT;
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
31+
32+
error: lifetime may not live long enough
33+
--> $DIR/associated-consts.rs:26:5
34+
|
35+
LL | fn test_normalization<'a, 'b>() {
36+
| -- lifetime `'b` defined here
37+
...
38+
LL | MyTy::<<&'b () as Project>::Assoc>::TRAIT;
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
40+
41+
help: the following changes may resolve your lifetime errors
42+
|
43+
= help: replace `'a` with `'static`
44+
= help: replace `'b` with `'static`
45+
46+
error: aborting due to 4 previous errors
47+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Make sure we WF-check user anootations before normalization.
2+
//
3+
// FIXME: add tests for associated trait functions and closure signature.
4+
5+
// check-fail
6+
7+
#![feature(more_qualified_paths)]
8+
9+
trait Trait {
10+
type Assoc;
11+
}
12+
13+
impl<T> Trait for T {
14+
type Assoc = MyTy<()>;
15+
}
16+
17+
enum MyTy<T> {
18+
Unit,
19+
Tuple(),
20+
Struct {},
21+
Dumb(T),
22+
}
23+
24+
impl<T> MyTy<T> {
25+
fn method<X>() {}
26+
fn method2<X>(&self) {}
27+
}
28+
29+
type Ty<'a> = <&'static &'a () as Trait>::Assoc;
30+
31+
fn test_local<'a>() {
32+
let _: Ty<'a> = MyTy::Unit;
33+
//~^ ERROR lifetime may not live long enough
34+
}
35+
36+
fn test_closure_sig<'a, 'b>() {
37+
// FIXME: these should fail.
38+
|_: Ty<'a>| {};
39+
|| -> Option<Ty<'b>> { None };
40+
}
41+
42+
fn test_path<'a, 'b, 'c, 'd>() {
43+
<Ty<'a>>::method::<Ty<'static>>;
44+
//~^ ERROR lifetime may not live long enough
45+
<Ty<'static>>::method::<Ty<'b>>;
46+
//~^ ERROR lifetime may not live long enough
47+
48+
MyTy::Unit::<Ty<'c>>;
49+
//~^ ERROR lifetime may not live long enough
50+
}
51+
52+
fn test_call<'a, 'b, 'c>() {
53+
<Ty<'a>>::method::<Ty<'static>>();
54+
//~^ ERROR lifetime may not live long enough
55+
<Ty<'static>>::method::<Ty<'b>>();
56+
//~^ ERROR lifetime may not live long enough
57+
}
58+
59+
fn test_variants<'a, 'b, 'c>() {
60+
<Ty<'a>>::Struct {};
61+
//~^ ERROR lifetime may not live long enough
62+
<Ty<'b>>::Tuple();
63+
//~^ ERROR lifetime may not live long enough
64+
<Ty<'c>>::Unit;
65+
//~^ ERROR lifetime may not live long enough
66+
}
67+
68+
fn test_method_call<'a>(x: MyTy<()>) {
69+
x.method2::<Ty<'a>>();
70+
//~^ ERROR lifetime may not live long enough
71+
}
72+
73+
fn test_struct_path<'a, 'b, 'c, 'd>() {
74+
struct Struct<T> { x: Option<T>, }
75+
76+
trait Project {
77+
type Struct;
78+
type Enum;
79+
}
80+
impl<T> Project for T {
81+
type Struct = Struct<()>;
82+
type Enum = MyTy<()>;
83+
}
84+
85+
// Resolves to enum variant
86+
MyTy::<Ty<'a>>::Struct {}; // without SelfTy
87+
//~^ ERROR lifetime may not live long enough
88+
<Ty<'b> as Project>::Enum::Struct {}; // with SelfTy
89+
//~^ ERROR lifetime may not live long enough
90+
91+
// Resolves to struct and associated type respectively
92+
Struct::<Ty<'c>> { x: None, }; // without SelfTy
93+
//~^ ERROR lifetime may not live long enough
94+
<Ty<'d> as Project>::Struct { x: None, }; // with SelfTy
95+
//~^ ERROR lifetime may not live long enough
96+
}
97+
98+
fn test_pattern<'a, 'b, 'c>() {
99+
use MyTy::*;
100+
match MyTy::Unit {
101+
Struct::<Ty<'a>> {..} => {},
102+
//~^ ERROR lifetime may not live long enough
103+
Tuple::<Ty<'b>> (..) => {},
104+
//~^ ERROR lifetime may not live long enough
105+
Unit::<Ty<'c>> => {},
106+
//~^ ERROR lifetime may not live long enough
107+
Dumb(_) => {},
108+
};
109+
}
110+
111+
112+
fn main() {}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/normalization-3.rs:32:12
3+
|
4+
LL | fn test_local<'a>() {
5+
| -- lifetime `'a` defined here
6+
LL | let _: Ty<'a> = MyTy::Unit;
7+
| ^^^^^^ requires that `'a` must outlive `'static`
8+
9+
error: lifetime may not live long enough
10+
--> $DIR/normalization-3.rs:43:5
11+
|
12+
LL | fn test_path<'a, 'b, 'c, 'd>() {
13+
| -- lifetime `'a` defined here
14+
LL | <Ty<'a>>::method::<Ty<'static>>;
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
16+
17+
error: lifetime may not live long enough
18+
--> $DIR/normalization-3.rs:45:5
19+
|
20+
LL | fn test_path<'a, 'b, 'c, 'd>() {
21+
| -- lifetime `'b` defined here
22+
...
23+
LL | <Ty<'static>>::method::<Ty<'b>>;
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
25+
26+
error: lifetime may not live long enough
27+
--> $DIR/normalization-3.rs:48:5
28+
|
29+
LL | fn test_path<'a, 'b, 'c, 'd>() {
30+
| -- lifetime `'c` defined here
31+
...
32+
LL | MyTy::Unit::<Ty<'c>>;
33+
| ^^^^^^^^^^^^^^^^^^^^ requires that `'c` must outlive `'static`
34+
35+
help: the following changes may resolve your lifetime errors
36+
|
37+
= help: replace `'a` with `'static`
38+
= help: replace `'b` with `'static`
39+
= help: replace `'c` with `'static`
40+
41+
error: lifetime may not live long enough
42+
--> $DIR/normalization-3.rs:53:5
43+
|
44+
LL | fn test_call<'a, 'b, 'c>() {
45+
| -- lifetime `'a` defined here
46+
LL | <Ty<'a>>::method::<Ty<'static>>();
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
48+
49+
error: lifetime may not live long enough
50+
--> $DIR/normalization-3.rs:55:5
51+
|
52+
LL | fn test_call<'a, 'b, 'c>() {
53+
| -- lifetime `'b` defined here
54+
...
55+
LL | <Ty<'static>>::method::<Ty<'b>>();
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
57+
58+
help: the following changes may resolve your lifetime errors
59+
|
60+
= help: replace `'a` with `'static`
61+
= help: replace `'b` with `'static`
62+
63+
error: lifetime may not live long enough
64+
--> $DIR/normalization-3.rs:60:5
65+
|
66+
LL | fn test_variants<'a, 'b, 'c>() {
67+
| -- lifetime `'a` defined here
68+
LL | <Ty<'a>>::Struct {};
69+
| ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
70+
71+
error: lifetime may not live long enough
72+
--> $DIR/normalization-3.rs:62:5
73+
|
74+
LL | fn test_variants<'a, 'b, 'c>() {
75+
| -- lifetime `'b` defined here
76+
...
77+
LL | <Ty<'b>>::Tuple();
78+
| ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
79+
80+
error: lifetime may not live long enough
81+
--> $DIR/normalization-3.rs:64:5
82+
|
83+
LL | fn test_variants<'a, 'b, 'c>() {
84+
| -- lifetime `'c` defined here
85+
...
86+
LL | <Ty<'c>>::Unit;
87+
| ^^^^^^^^^^^^^^ requires that `'c` must outlive `'static`
88+
89+
help: the following changes may resolve your lifetime errors
90+
|
91+
= help: replace `'a` with `'static`
92+
= help: replace `'b` with `'static`
93+
= help: replace `'c` with `'static`
94+
95+
error: lifetime may not live long enough
96+
--> $DIR/normalization-3.rs:69:7
97+
|
98+
LL | fn test_method_call<'a>(x: MyTy<()>) {
99+
| -- lifetime `'a` defined here
100+
LL | x.method2::<Ty<'a>>();
101+
| ^^^^^^^ requires that `'a` must outlive `'static`
102+
103+
error: lifetime may not live long enough
104+
--> $DIR/normalization-3.rs:86:5
105+
|
106+
LL | fn test_struct_path<'a, 'b, 'c, 'd>() {
107+
| -- lifetime `'a` defined here
108+
...
109+
LL | MyTy::<Ty<'a>>::Struct {}; // without SelfTy
110+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
111+
112+
error: lifetime may not live long enough
113+
--> $DIR/normalization-3.rs:88:5
114+
|
115+
LL | fn test_struct_path<'a, 'b, 'c, 'd>() {
116+
| -- lifetime `'b` defined here
117+
...
118+
LL | <Ty<'b> as Project>::Enum::Struct {}; // with SelfTy
119+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
120+
121+
error: lifetime may not live long enough
122+
--> $DIR/normalization-3.rs:92:5
123+
|
124+
LL | fn test_struct_path<'a, 'b, 'c, 'd>() {
125+
| -- lifetime `'c` defined here
126+
...
127+
LL | Struct::<Ty<'c>> { x: None, }; // without SelfTy
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'c` must outlive `'static`
129+
130+
error: lifetime may not live long enough
131+
--> $DIR/normalization-3.rs:94:5
132+
|
133+
LL | fn test_struct_path<'a, 'b, 'c, 'd>() {
134+
| -- lifetime `'d` defined here
135+
...
136+
LL | <Ty<'d> as Project>::Struct { x: None, }; // with SelfTy
137+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'d` must outlive `'static`
138+
139+
help: the following changes may resolve your lifetime errors
140+
|
141+
= help: replace `'a` with `'static`
142+
= help: replace `'b` with `'static`
143+
= help: replace `'c` with `'static`
144+
= help: replace `'d` with `'static`
145+
146+
error: lifetime may not live long enough
147+
--> $DIR/normalization-3.rs:101:9
148+
|
149+
LL | fn test_pattern<'a, 'b, 'c>() {
150+
| -- lifetime `'a` defined here
151+
...
152+
LL | Struct::<Ty<'a>> {..} => {},
153+
| ^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
154+
155+
error: lifetime may not live long enough
156+
--> $DIR/normalization-3.rs:103:9
157+
|
158+
LL | fn test_pattern<'a, 'b, 'c>() {
159+
| -- lifetime `'b` defined here
160+
...
161+
LL | Tuple::<Ty<'b>> (..) => {},
162+
| ^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
163+
164+
error: lifetime may not live long enough
165+
--> $DIR/normalization-3.rs:105:9
166+
|
167+
LL | fn test_pattern<'a, 'b, 'c>() {
168+
| -- lifetime `'c` defined here
169+
...
170+
LL | Unit::<Ty<'c>> => {},
171+
| ^^^^^^^^^^^^^^ requires that `'c` must outlive `'static`
172+
173+
help: the following changes may resolve your lifetime errors
174+
|
175+
= help: replace `'a` with `'static`
176+
= help: replace `'b` with `'static`
177+
= help: replace `'c` with `'static`
178+
179+
error: aborting due to 17 previous errors
180+

0 commit comments

Comments
 (0)