File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ // compile-pass
2+ use std:: marker:: PhantomData ;
3+
4+ struct Meta < A > {
5+ value : i32 ,
6+ type_ : PhantomData < A >
7+ }
8+
9+ trait MetaTrait {
10+ fn get_value ( & self ) -> i32 ;
11+ }
12+
13+ impl < A > MetaTrait for Meta < A > {
14+ fn get_value ( & self ) -> i32 { self . value }
15+ }
16+
17+ trait Bar {
18+ fn get_const ( & self ) -> & dyn MetaTrait ;
19+ }
20+
21+ struct Foo < A > {
22+ _value : A
23+ }
24+
25+ impl < A : ' static > Foo < A > {
26+ const CONST : & ' static dyn MetaTrait = & Meta :: < Self > {
27+ value : 10 ,
28+ type_ : PhantomData
29+ } ;
30+ }
31+
32+ impl < A : ' static > Bar for Foo < A > {
33+ fn get_const ( & self ) -> & dyn MetaTrait { Self :: CONST }
34+ }
35+
36+ fn main ( ) {
37+ let foo = Foo :: < i32 > { _value : 10 } ;
38+ let bar: & dyn Bar = & foo;
39+ println ! ( "const {}" , bar. get_const( ) . get_value( ) ) ;
40+ }
You can’t perform that action at this time.
0 commit comments