Skip to content

Commit cac62ab

Browse files
committed
add known-bug test for unsound issue 84533
1 parent fbfb620 commit cac62ab

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// check-pass
2+
// known-bug: #84533
3+
4+
// Should fail. Lifetimes are checked correctly when `foo` is called, but NOT
5+
// when only the lifetime parameters are instantiated.
6+
7+
use std::marker::PhantomData;
8+
9+
#[allow(dead_code)]
10+
fn foo<'b, 'a>() -> PhantomData<&'b &'a ()> {
11+
PhantomData
12+
}
13+
14+
#[allow(dead_code)]
15+
#[allow(path_statements)]
16+
fn caller<'b, 'a>() {
17+
foo::<'b, 'a>;
18+
}
19+
20+
// In contrast to above, below code correctly does NOT compile.
21+
// fn caller<'b, 'a>() {
22+
// foo::<'b, 'a>();
23+
// }
24+
25+
// error: lifetime may not live long enough
26+
// --> src/main.rs:22:5
27+
// |
28+
// 21 | fn caller<'b, 'a>() {
29+
// | -- -- lifetime `'a` defined here
30+
// | |
31+
// | lifetime `'b` defined here
32+
// 22 | foo::<'b, 'a>();
33+
// | ^^^^^^^^^^^^^^^ requires that `'a` must outlive `'b`
34+
// |
35+
// = help: consider adding the following bound: `'a: 'b`
36+
37+
fn main() {}

0 commit comments

Comments
 (0)