Skip to content

Commit 36ab1bf

Browse files
committed
Add more tests
1 parent e17989e commit 36ab1bf

8 files changed

+669
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Test for #124423, which causes an ice bug: only `variances_of` returns `&[ty::Variance]`
2+
//
3+
//@ compile-flags: -Z threads=16
4+
//@ compare-output-by-lines
5+
6+
use std::fmt::Debug;
7+
8+
fn elided(_: &impl Copy + 'a) -> _ { x }
9+
//~^ ERROR ambiguous `+` in a type
10+
//~| ERROR use of undeclared lifetime name `'a`
11+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for return types
12+
13+
fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
14+
//~^ ERROR ambiguous `+` in a type
15+
//~| ERROR at least one trait must be specified
16+
//~| ERROR use of undeclared lifetime name `'a`
17+
//~| ERROR use of undeclared lifetime name `'a`
18+
//~| ERROR use of undeclared lifetime name `'a`
19+
20+
fn elided2( impl 'b) -> impl 'a + 'a { x }
21+
//~^ ERROR expected one of `:` or `|`, found `'b`
22+
//~| ERROR expected identifier, found keyword `impl`
23+
//~| ERROR at least one trait must be specified
24+
//~| ERROR use of undeclared lifetime name `'a`
25+
//~| ERROR use of undeclared lifetime name `'a`
26+
27+
fn explicit2<'a>(_: &'a impl Copy + 'a) -> impl Copy + 'a { x }
28+
//~^ ERROR ambiguous `+` in a type
29+
30+
fn foo<'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
31+
//~^ ERROR ambiguous `+` in a type
32+
//~| ERROR at least one trait must be specified
33+
//~| ERROR use of undeclared lifetime name `'b`
34+
35+
fn elided3(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
36+
//~^ ERROR ambiguous `+` in a type
37+
//~| ERROR use of undeclared lifetime name `'a`
38+
//~| ERROR use of undeclared lifetime name `'a`
39+
//~| ERROR at least one trait is required for an object type
40+
41+
fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
42+
//~^ ERROR ambiguous `+` in a type
43+
//~| ERROR use of undeclared lifetime name `'a`
44+
//~| ERROR use of undeclared lifetime name `'a`
45+
//~| ERROR at least one trait is required for an object type
46+
//~| ERROR no function or associated item named `u32` found for struct `Box<_, _>` in the current scope
47+
48+
fn elided4(_: &impl Copy + 'a) -> new { x(x) }
49+
//~^ ERROR ambiguous `+` in a type
50+
//~| ERROR use of undeclared lifetime name `'a`
51+
//~| ERROR cannot find type `new` in this scope
52+
53+
trait LifetimeTrait<'a> {}
54+
55+
impl<'a> LifetimeTrait<'a> for &'a Box<dyn 'a> {}
56+
//~^ ERROR at least one trait is required for an object type
57+
58+
fn main() {}
Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
error: ambiguous `+` in a type
2+
--> $DIR/ty-variance-issue-124423.rs:8:15
3+
|
4+
LL | fn elided(_: &impl Copy + 'a) -> _ { x }
5+
| ^^^^^^^^^^^^^^
6+
|
7+
help: try adding parentheses
8+
|
9+
LL | fn elided(_: &(impl Copy + 'a)) -> _ { x }
10+
| + +
11+
12+
error: ambiguous `+` in a type
13+
--> $DIR/ty-variance-issue-124423.rs:13:24
14+
|
15+
LL | fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
16+
| ^^^^^^^^^^^^^^
17+
|
18+
help: try adding parentheses
19+
|
20+
LL | fn explicit<'b>(_: &'a (impl Copy + 'a)) -> impl 'a { x }
21+
| + +
22+
23+
error: expected identifier, found keyword `impl`
24+
--> $DIR/ty-variance-issue-124423.rs:20:13
25+
|
26+
LL | fn elided2( impl 'b) -> impl 'a + 'a { x }
27+
| ^^^^ expected identifier, found keyword
28+
29+
error: expected one of `:` or `|`, found `'b`
30+
--> $DIR/ty-variance-issue-124423.rs:20:18
31+
|
32+
LL | fn elided2( impl 'b) -> impl 'a + 'a { x }
33+
| ^^ expected one of `:` or `|`
34+
35+
error: ambiguous `+` in a type
36+
--> $DIR/ty-variance-issue-124423.rs:27:25
37+
|
38+
LL | fn explicit2<'a>(_: &'a impl Copy + 'a) -> impl Copy + 'a { x }
39+
| ^^^^^^^^^^^^^^
40+
|
41+
help: try adding parentheses
42+
|
43+
LL | fn explicit2<'a>(_: &'a (impl Copy + 'a)) -> impl Copy + 'a { x }
44+
| + +
45+
46+
error: ambiguous `+` in a type
47+
--> $DIR/ty-variance-issue-124423.rs:30:16
48+
|
49+
LL | fn foo<'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
50+
| ^^^^^^^^^^^^^^
51+
|
52+
help: try adding parentheses
53+
|
54+
LL | fn foo<'a>(_: &(impl Copy + 'a)) -> impl 'b + 'a { x }
55+
| + +
56+
57+
error: ambiguous `+` in a type
58+
--> $DIR/ty-variance-issue-124423.rs:35:16
59+
|
60+
LL | fn elided3(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
61+
| ^^^^^^^^^^^^^^
62+
|
63+
help: try adding parentheses
64+
|
65+
LL | fn elided3(_: &(impl Copy + 'a)) -> Box<dyn 'a> { Box::new(x) }
66+
| + +
67+
68+
error: ambiguous `+` in a type
69+
--> $DIR/ty-variance-issue-124423.rs:41:17
70+
|
71+
LL | fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
72+
| ^^^^^^^^^^^^^^
73+
|
74+
help: try adding parentheses
75+
|
76+
LL | fn x<'b>(_: &'a (impl Copy + 'a)) -> Box<dyn 'b> { Box::u32(x) }
77+
| + +
78+
79+
error: ambiguous `+` in a type
80+
--> $DIR/ty-variance-issue-124423.rs:48:16
81+
|
82+
LL | fn elided4(_: &impl Copy + 'a) -> new { x(x) }
83+
| ^^^^^^^^^^^^^^
84+
|
85+
help: try adding parentheses
86+
|
87+
LL | fn elided4(_: &(impl Copy + 'a)) -> new { x(x) }
88+
| + +
89+
90+
error: at least one trait must be specified
91+
--> $DIR/ty-variance-issue-124423.rs:13:43
92+
|
93+
LL | fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
94+
| ^^^^^^^
95+
96+
error: at least one trait must be specified
97+
--> $DIR/ty-variance-issue-124423.rs:20:25
98+
|
99+
LL | fn elided2( impl 'b) -> impl 'a + 'a { x }
100+
| ^^^^^^^^^^^^
101+
102+
error: at least one trait must be specified
103+
--> $DIR/ty-variance-issue-124423.rs:30:35
104+
|
105+
LL | fn foo<'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
106+
| ^^^^^^^^^^^^
107+
108+
error[E0261]: use of undeclared lifetime name `'a`
109+
--> $DIR/ty-variance-issue-124423.rs:8:27
110+
|
111+
LL | fn elided(_: &impl Copy + 'a) -> _ { x }
112+
| ^^ undeclared lifetime
113+
|
114+
help: consider introducing lifetime `'a` here
115+
|
116+
LL | fn elided<'a>(_: &impl Copy + 'a) -> _ { x }
117+
| ++++
118+
119+
error[E0261]: use of undeclared lifetime name `'a`
120+
--> $DIR/ty-variance-issue-124423.rs:13:21
121+
|
122+
LL | fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
123+
| ^^ undeclared lifetime
124+
|
125+
help: consider introducing lifetime `'a` here
126+
|
127+
LL | fn explicit<'a, 'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
128+
| +++
129+
130+
error[E0261]: use of undeclared lifetime name `'a`
131+
--> $DIR/ty-variance-issue-124423.rs:13:36
132+
|
133+
LL | fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
134+
| ^^ undeclared lifetime
135+
|
136+
help: consider introducing lifetime `'a` here
137+
|
138+
LL | fn explicit<'a, 'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
139+
| +++
140+
141+
error[E0261]: use of undeclared lifetime name `'a`
142+
--> $DIR/ty-variance-issue-124423.rs:13:48
143+
|
144+
LL | fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
145+
| ^^ undeclared lifetime
146+
|
147+
help: consider introducing lifetime `'a` here
148+
|
149+
LL | fn explicit<'a, 'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
150+
| +++
151+
152+
error[E0261]: use of undeclared lifetime name `'a`
153+
--> $DIR/ty-variance-issue-124423.rs:20:30
154+
|
155+
LL | fn elided2( impl 'b) -> impl 'a + 'a { x }
156+
| ^^ undeclared lifetime
157+
|
158+
help: consider introducing lifetime `'a` here
159+
|
160+
LL | fn elided2<'a>( impl 'b) -> impl 'a + 'a { x }
161+
| ++++
162+
163+
error[E0261]: use of undeclared lifetime name `'a`
164+
--> $DIR/ty-variance-issue-124423.rs:20:35
165+
|
166+
LL | fn elided2( impl 'b) -> impl 'a + 'a { x }
167+
| ^^ undeclared lifetime
168+
|
169+
help: consider introducing lifetime `'a` here
170+
|
171+
LL | fn elided2<'a>( impl 'b) -> impl 'a + 'a { x }
172+
| ++++
173+
174+
error[E0261]: use of undeclared lifetime name `'b`
175+
--> $DIR/ty-variance-issue-124423.rs:30:40
176+
|
177+
LL | fn foo<'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
178+
| ^^ undeclared lifetime
179+
|
180+
help: consider introducing lifetime `'b` here
181+
|
182+
LL | fn foo<'b, 'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
183+
| +++
184+
185+
error[E0261]: use of undeclared lifetime name `'a`
186+
--> $DIR/ty-variance-issue-124423.rs:35:28
187+
|
188+
LL | fn elided3(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
189+
| ^^ undeclared lifetime
190+
|
191+
help: consider introducing lifetime `'a` here
192+
|
193+
LL | fn elided3<'a>(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
194+
| ++++
195+
196+
error[E0261]: use of undeclared lifetime name `'a`
197+
--> $DIR/ty-variance-issue-124423.rs:35:43
198+
|
199+
LL | fn elided3(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
200+
| ^^ undeclared lifetime
201+
|
202+
help: consider introducing lifetime `'a` here
203+
|
204+
LL | fn elided3<'a>(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
205+
| ++++
206+
207+
error[E0261]: use of undeclared lifetime name `'a`
208+
--> $DIR/ty-variance-issue-124423.rs:41:14
209+
|
210+
LL | fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
211+
| ^^ undeclared lifetime
212+
|
213+
help: consider introducing lifetime `'a` here
214+
|
215+
LL | fn x<'a, 'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
216+
| +++
217+
218+
error[E0261]: use of undeclared lifetime name `'a`
219+
--> $DIR/ty-variance-issue-124423.rs:41:29
220+
|
221+
LL | fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
222+
| ^^ undeclared lifetime
223+
|
224+
help: consider introducing lifetime `'a` here
225+
|
226+
LL | fn x<'a, 'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
227+
| +++
228+
229+
error[E0261]: use of undeclared lifetime name `'a`
230+
--> $DIR/ty-variance-issue-124423.rs:48:28
231+
|
232+
LL | fn elided4(_: &impl Copy + 'a) -> new { x(x) }
233+
| ^^ undeclared lifetime
234+
|
235+
help: consider introducing lifetime `'a` here
236+
|
237+
LL | fn elided4<'a>(_: &impl Copy + 'a) -> new { x(x) }
238+
| ++++
239+
240+
error[E0412]: cannot find type `new` in this scope
241+
--> $DIR/ty-variance-issue-124423.rs:48:36
242+
|
243+
LL | fn elided4(_: &impl Copy + 'a) -> new { x(x) }
244+
| ^^^ not found in this scope
245+
246+
error[E0224]: at least one trait is required for an object type
247+
--> $DIR/ty-variance-issue-124423.rs:35:39
248+
|
249+
LL | fn elided3(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
250+
| ^^^^^^
251+
252+
error[E0224]: at least one trait is required for an object type
253+
--> $DIR/ty-variance-issue-124423.rs:41:40
254+
|
255+
LL | fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
256+
| ^^^^^^
257+
258+
error[E0224]: at least one trait is required for an object type
259+
--> $DIR/ty-variance-issue-124423.rs:55:40
260+
|
261+
LL | impl<'a> LifetimeTrait<'a> for &'a Box<dyn 'a> {}
262+
| ^^^^^^
263+
264+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
265+
--> $DIR/ty-variance-issue-124423.rs:8:34
266+
|
267+
LL | fn elided(_: &impl Copy + 'a) -> _ { x }
268+
| ^ not allowed in type signatures
269+
270+
error[E0599]: no function or associated item named `u32` found for struct `Box<_, _>` in the current scope
271+
--> $DIR/ty-variance-issue-124423.rs:41:55
272+
|
273+
LL | fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
274+
| ^^^ function or associated item not found in `Box<_, _>`
275+
|
276+
note: if you're trying to build a new `Box<_, _>` consider using one of the following associated functions:
277+
Box::<T>::new
278+
Box::<T>::new_uninit
279+
Box::<T>::new_zeroed
280+
Box::<T>::try_new
281+
and 22 others
282+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
283+
284+
error: aborting due to 30 previous errors
285+
286+
Some errors have detailed explanations: E0121, E0224, E0261, E0412, E0599.
287+
For more information about an error, try `rustc --explain E0121`.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test for #127971, which causes an ice bug: only `variances_of` returns `&[ty::Variance]`
2+
//
3+
//@ compile-flags: -Z threads=16
4+
//@ compare-output-by-lines
5+
6+
use std::fmt::Debug;
7+
8+
fn elided(_: &impl Copy + 'a) -> _ { x }
9+
//~^ ERROR ambiguous `+` in a type
10+
//~| ERROR use of undeclared lifetime name `'a`
11+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for return types
12+
13+
fn foo<'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
14+
//~^ ERROR ambiguous `+` in a type
15+
//~| ERROR at least one trait must be specified
16+
//~| ERROR use of undeclared lifetime name `'b`
17+
18+
fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
19+
//~^ ERROR ambiguous `+` in a type
20+
//~| ERROR use of undeclared lifetime name `'a`
21+
//~| ERROR use of undeclared lifetime name `'a`
22+
//~| ERROR at least one trait is required for an object type
23+
//~| ERROR no function or associated item named `u32` found for struct `Box<_, _>` in the current scope
24+
25+
fn main() {}

0 commit comments

Comments
 (0)