File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
src/test/ui/consts/const-eval Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ // Several variants of #64945.
2+
3+ // This struct is not important, we just use it to put `T` and `'a` in scope for our associated
4+ // consts.
5+ struct Generic < ' a , T > ( std:: marker:: PhantomData < & ' a T > ) ;
6+
7+ impl < ' a , T : ' static > Generic < ' a , T > {
8+ const EMPTY_SLICE : & ' a [ T ] = {
9+ let x: & ' a [ T ] = & [ ] ;
10+ x
11+ } ;
12+
13+ const EMPTY_SLICE_REF : & ' a & ' static [ T ] = {
14+ let x: & ' static [ T ] = & [ ] ;
15+ & x
16+ //~^ ERROR `x` does not live long enough
17+ } ;
18+ }
19+
20+ static mut INTERIOR_MUT_AND_DROP : & ' static [ std:: cell:: RefCell < Vec < i32 > > ] = {
21+ let x: & [ _ ] = & [ ] ;
22+ x
23+ } ;
24+
25+ static mut INTERIOR_MUT_AND_DROP_REF : & ' static & ' static [ std:: cell:: RefCell < Vec < i32 > > ] = {
26+ let x: & [ _ ] = & [ ] ;
27+ & x
28+ //~^ ERROR `x` does not live long enough
29+ } ;
30+
31+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0597]: `x` does not live long enough
2+ --> $DIR/generic-slice.rs:15:9
3+ |
4+ LL | impl<'a, T: 'static> Generic<'a, T> {
5+ | -- lifetime `'a` defined here
6+ ...
7+ LL | &x
8+ | ^^
9+ | |
10+ | borrowed value does not live long enough
11+ | using this value as a constant requires that `x` is borrowed for `'a`
12+ LL |
13+ LL | };
14+ | - `x` dropped here while still borrowed
15+
16+ error[E0597]: `x` does not live long enough
17+ --> $DIR/generic-slice.rs:27:5
18+ |
19+ LL | &x
20+ | ^^
21+ | |
22+ | borrowed value does not live long enough
23+ | using this value as a static requires that `x` is borrowed for `'static`
24+ LL |
25+ LL | };
26+ | - `x` dropped here while still borrowed
27+
28+ error: aborting due to 2 previous errors
29+
30+ For more information about this error, try `rustc --explain E0597`.
You can’t perform that action at this time.
0 commit comments