Skip to content

Commit 28962e3

Browse files
committed
Add more tests.
1 parent 83585fa commit 28962e3

8 files changed

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