File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -123,8 +123,35 @@ fn pointers_and_wrappers() {
123
123
assert_eq ! ( wpw. wrapper_ptr_wrapper( ) , 7 ) ;
124
124
}
125
125
126
+ fn raw_ptr_receiver ( ) {
127
+ use std:: ptr;
128
+
129
+ trait Foo {
130
+ fn foo ( self : * const Self ) -> & ' static str ;
131
+ }
132
+
133
+ impl Foo for i32 {
134
+ fn foo ( self : * const Self ) -> & ' static str {
135
+ "I'm an i32!"
136
+ }
137
+ }
138
+
139
+ impl Foo for u32 {
140
+ fn foo ( self : * const Self ) -> & ' static str {
141
+ "I'm a u32!"
142
+ }
143
+ }
144
+
145
+ let null_i32 = ptr:: null :: < i32 > ( ) as * const dyn Foo ;
146
+ let null_u32 = ptr:: null :: < u32 > ( ) as * const dyn Foo ;
147
+
148
+ assert_eq ! ( "I'm an i32!" , null_i32. foo( ) ) ;
149
+ assert_eq ! ( "I'm a u32!" , null_u32. foo( ) ) ;
150
+ }
151
+
126
152
fn main ( ) {
127
153
pin_box_dyn ( ) ;
128
154
stdlib_pointers ( ) ;
129
155
pointers_and_wrappers ( ) ;
156
+ raw_ptr_receiver ( ) ;
130
157
}
You can’t perform that action at this time.
0 commit comments