File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ feature( inline_const, const_type_id) ]
2+
3+ use std:: alloc:: Layout ;
4+ use std:: any:: TypeId ;
5+ use std:: mem:: transmute;
6+ use std:: ptr:: drop_in_place;
7+
8+ pub struct VTable {
9+ layout : Layout ,
10+ type_id : TypeId ,
11+ drop_in_place : unsafe fn ( * mut ( ) ) ,
12+ }
13+
14+ impl VTable {
15+ pub fn new < T > ( ) -> & ' static Self {
16+ const {
17+ //~^ ERROR the parameter type `T` may not live long enough
18+ //~| ERROR the parameter type `T` may not live long enough
19+ & VTable {
20+ layout : Layout :: new :: < T > ( ) ,
21+ type_id : TypeId :: of :: < T > ( ) ,
22+ drop_in_place : unsafe {
23+ transmute :: < unsafe fn ( * mut T ) , unsafe fn ( * mut ( ) ) > ( drop_in_place :: < T > )
24+ } ,
25+ }
26+ }
27+ }
28+ }
29+
30+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0310]: the parameter type `T` may not live long enough
2+ --> $DIR/issue-102117.rs:16:9
3+ |
4+ LL | / const {
5+ LL | |
6+ LL | |
7+ LL | | &VTable {
8+ ... |
9+ LL | | }
10+ LL | | }
11+ | |_________^ ...so that the type `T` will meet its required lifetime bounds
12+ |
13+ help: consider adding an explicit lifetime bound...
14+ |
15+ LL | pub fn new<T: 'static>() -> &'static Self {
16+ | +++++++++
17+
18+ error[E0310]: the parameter type `T` may not live long enough
19+ --> $DIR/issue-102117.rs:16:9
20+ |
21+ LL | / const {
22+ LL | |
23+ LL | |
24+ LL | | &VTable {
25+ ... |
26+ LL | | }
27+ LL | | }
28+ | |_________^ ...so that the type `T` will meet its required lifetime bounds
29+ |
30+ help: consider adding an explicit lifetime bound...
31+ |
32+ LL | pub fn new<T: 'static>() -> &'static Self {
33+ | +++++++++
34+
35+ error: aborting due to 2 previous errors
36+
37+ For more information about this error, try `rustc --explain E0310`.
You can’t perform that action at this time.
0 commit comments