File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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 ( ) { }
You can’t perform that action at this time.
0 commit comments