Skip to content

Commit 99d7555

Browse files
committed
Add more tests.
1 parent ead39df commit 99d7555

8 files changed

+673
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Test for #120760, which causes an ice bug
2+
//
3+
//@ compile-flags: -Z threads=45
4+
//@ check-fail
5+
//@ edition: 2021
6+
//@ parallel-front-end
7+
8+
type BoxFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T>>>;
9+
10+
fn main() {
11+
let _ = f();
12+
}
13+
14+
async fn f() {
15+
run("dependency").await; //~ ERROR cannot find function `run` in this scope
16+
}
17+
18+
struct InMemoryStorage;
19+
20+
pub struct User<'dep> {
21+
pub name: &'a str, //~ ERROR use of undeclared lifetime name `'a`
22+
}
23+
24+
impl<'a> StorageRequest<InMemoryStorage> for SaveUser<'a> {
25+
fn execute(&self) -> BoxFuture<Result<(), String>> {
26+
todo!()
27+
}
28+
}
29+
30+
trait Storage {
31+
type Error;
32+
}
33+
34+
impl Storage for InMemoryStorage {
35+
type Error = String;
36+
}
37+
38+
trait StorageRequestReturnType {
39+
type Output;
40+
}
41+
42+
trait StorageRequest<S: Storage>: StorageRequestReturnType {
43+
fn execute(
44+
&self,
45+
) -> BoxFuture<Result<<SaveUser as StorageRequestReturnType>::Output, <S as Storage>::Error>>;
46+
}
47+
48+
pub struct SaveUser<'a> {
49+
pub name: &'a str,
50+
}
51+
52+
impl<'a> StorageRequestReturnType for SaveUser<'a> {
53+
type Output = ();
54+
}
55+
56+
impl<'dep> User<'dep> {
57+
async fn save<S>(self)
58+
where
59+
S: Storage,
60+
for<'a> SaveUser<'a>: StorageRequest<S>,
61+
{
62+
let _ = run("dependency").await; //~ ERROR cannot find function `run` in this scope
63+
}
64+
}
65+
66+
async fn execute<S>(dep: &str)
67+
where
68+
S: Storage,
69+
for<'a> SaveUser<'a>: StorageRequest<S>,
70+
{
71+
User { dep }.save().await; //~ ERROR struct `User<'_>` has no field named `dep`
72+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0261]: use of undeclared lifetime name `'a`
2+
--> $DIR/ice-issue-120760.rs:21:16
3+
|
4+
LL | pub name: &'a str,
5+
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'a` here
8+
|
9+
LL | pub struct User<'a, 'dep> {
10+
| +++
11+
12+
error[E0560]: struct `User<'_>` has no field named `dep`
13+
--> $DIR/ice-issue-120760.rs:71:12
14+
|
15+
LL | User { dep }.save().await;
16+
| ^^^ `User<'_>` does not have this field
17+
|
18+
= note: available fields are: `name`
19+
20+
error[E0425]: cannot find function `run` in this scope
21+
--> $DIR/ice-issue-120760.rs:15:5
22+
|
23+
LL | run("dependency").await;
24+
| ^^^ not found in this scope
25+
26+
error[E0425]: cannot find function `run` in this scope
27+
--> $DIR/ice-issue-120760.rs:62:17
28+
|
29+
LL | let _ = run("dependency").await;
30+
| ^^^ not found in this scope
31+
32+
error: aborting due to 4 previous errors
33+
34+
Some errors have detailed explanations: E0261, E0425, E0560.
35+
For more information about an error, try `rustc --explain E0261`.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Test for #124423, which causes an ice bug
2+
//
3+
//@ compile-flags: -Z threads=16
4+
//@ check-fail
5+
//@ parallel-front-end
6+
7+
use std::fmt::Debug;
8+
9+
fn elided(_: &impl Copy + 'a) -> _ { x }
10+
//~^ ERROR ambiguous `+` in a type
11+
//~| ERROR use of undeclared lifetime name `'a`
12+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for return types
13+
14+
fn explicit<'b>(_: &'a impl Copy + 'a) -> impl 'a { x }
15+
//~^ ERROR ambiguous `+` in a type
16+
//~| ERROR at least one trait must be specified
17+
//~| ERROR use of undeclared lifetime name `'a`
18+
//~| ERROR use of undeclared lifetime name `'a`
19+
//~| ERROR use of undeclared lifetime name `'a`
20+
21+
fn elided2( impl 'b) -> impl 'a + 'a { x }
22+
//~^ ERROR expected one of `:` or `|`, found `'b`
23+
//~| ERROR expected identifier, found keyword `impl`
24+
//~| ERROR at least one trait must be specified
25+
//~| ERROR use of undeclared lifetime name `'a`
26+
//~| ERROR use of undeclared lifetime name `'a`
27+
28+
fn explicit2<'a>(_: &'a impl Copy + 'a) -> impl Copy + 'a { x }
29+
//~^ ERROR ambiguous `+` in a type
30+
31+
fn foo<'a>(_: &impl Copy + 'a) -> impl 'b + 'a { x }
32+
//~^ ERROR ambiguous `+` in a type
33+
//~| ERROR at least one trait must be specified
34+
//~| ERROR use of undeclared lifetime name `'b`
35+
36+
fn elided3(_: &impl Copy + 'a) -> Box<dyn 'a> { Box::new(x) }
37+
//~^ ERROR ambiguous `+` in a type
38+
//~| ERROR use of undeclared lifetime name `'a`
39+
//~| ERROR use of undeclared lifetime name `'a`
40+
//~| ERROR at least one trait is required for an object type
41+
42+
fn x<'b>(_: &'a impl Copy + 'a) -> Box<dyn 'b> { Box::u32(x) }
43+
//~^ ERROR ambiguous `+` in a type
44+
//~| ERROR use of undeclared lifetime name `'a`
45+
//~| ERROR use of undeclared lifetime name `'a`
46+
//~| ERROR at least one trait is required for an object type
47+
//~| ERROR no function or associated item named `u32` found for struct `Box<_, _>` in the current scope
48+
49+
fn elided4(_: &impl Copy + 'a) -> new { x(x) }
50+
//~^ ERROR ambiguous `+` in a type
51+
//~| ERROR use of undeclared lifetime name `'a`
52+
//~| ERROR cannot find type `new` in this scope
53+
54+
trait LifetimeTrait<'a> {}
55+
56+
impl<'a> LifetimeTrait<'a> for &'a Box<dyn 'a> {}
57+
//~^ ERROR at least one trait is required for an object type
58+
59+
fn main() {}

0 commit comments

Comments
 (0)