Skip to content

Commit 8206008

Browse files
committed
Add regression test for issue 229
1 parent f013652 commit 8206008

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/ui/lifetime-defined-here.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use async_trait::async_trait;
2+
3+
#[async_trait]
4+
trait Foo {
5+
async fn bar(&self, x: &str, y: &'_ str) -> &'static str;
6+
}
7+
8+
struct S(String);
9+
10+
#[async_trait]
11+
impl Foo for S {
12+
async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
13+
if false {
14+
&self.0
15+
} else if false {
16+
x
17+
} else {
18+
y
19+
}
20+
}
21+
}
22+
23+
fn main() {}

tests/ui/lifetime-defined-here.stderr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: lifetime may not live long enough
2+
--> tests/ui/lifetime-defined-here.rs:12:49
3+
|
4+
12 | async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
5+
| ----- lifetime `'life0` defined here ^^^^^^^^^^^^ type annotation requires that `'life0` must outlive `'static`
6+
7+
error: lifetime may not live long enough
8+
--> tests/ui/lifetime-defined-here.rs:12:49
9+
|
10+
12 | async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
11+
| ----- lifetime `'life1` defined here ^^^^^^^^^^^^ type annotation requires that `'life1` must outlive `'static`
12+
13+
error: lifetime may not live long enough
14+
--> tests/ui/lifetime-defined-here.rs:12:49
15+
|
16+
12 | async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
17+
| -- ^^^^^^^^^^^^ type annotation requires that `'life2` must outlive `'static`
18+
| |
19+
| lifetime `'life2` defined here
20+
21+
help: the following changes may resolve your lifetime errors
22+
|
23+
= help: replace `'life0` with `'static`
24+
= help: replace `'life1` with `'static`
25+
= help: replace `'life2` with `'static`

0 commit comments

Comments
 (0)