@@ -16,6 +16,10 @@ trait Foo {
16
16
fn foo ( self : * const Self ) -> & ' static str ;
17
17
18
18
unsafe fn bar ( self : * const Self ) -> i64 ;
19
+
20
+ unsafe fn complicated ( self : * const * const Self ) -> i64 where Self : Sized {
21
+ ( * self ) . bar ( )
22
+ }
19
23
}
20
24
21
25
impl Foo for i32 {
@@ -39,21 +43,28 @@ impl Foo for u32 {
39
43
}
40
44
41
45
fn main ( ) {
42
- let foo_i32 = ptr:: null :: < i32 > ( ) as * const Foo ;
43
- let foo_u32 = ptr:: null :: < u32 > ( ) as * const Foo ;
46
+ let null_i32 = ptr:: null :: < i32 > ( ) as * const Foo ;
47
+ let null_u32 = ptr:: null :: < u32 > ( ) as * const Foo ;
44
48
45
- assert_eq ! ( "I'm an i32!" , foo_i32 . foo( ) ) ;
46
- assert_eq ! ( "I'm a u32!" , foo_u32 . foo( ) ) ;
49
+ assert_eq ! ( "I'm an i32!" , null_i32 . foo( ) ) ;
50
+ assert_eq ! ( "I'm a u32!" , null_u32 . foo( ) ) ;
47
51
48
52
let bar_i32 = 5i32 ;
49
53
let bar_i32_thin = & bar_i32 as * const i32 ;
54
+ assert_eq ! ( "I'm an i32!" , bar_i32_thin. foo( ) ) ;
50
55
assert_eq ! ( 5 , unsafe { bar_i32_thin. bar( ) } ) ;
56
+ assert_eq ! ( 5 , unsafe { ( & bar_i32_thin as * const * const i32 ) . complicated( ) } ) ;
51
57
let bar_i32_fat = bar_i32_thin as * const Foo ;
58
+ assert_eq ! ( "I'm an i32!" , bar_i32_fat. foo( ) ) ;
52
59
assert_eq ! ( 5 , unsafe { bar_i32_fat. bar( ) } ) ;
53
60
54
61
let bar_u32 = 18u32 ;
55
62
let bar_u32_thin = & bar_u32 as * const u32 ;
63
+ assert_eq ! ( "I'm a u32!" , bar_u32_thin. foo( ) ) ;
56
64
assert_eq ! ( 18 , unsafe { bar_u32_thin. bar( ) } ) ;
65
+ assert_eq ! ( 18 , unsafe { ( & bar_u32_thin as * const * const u32 ) . complicated( ) } ) ;
57
66
let bar_u32_fat = bar_u32_thin as * const Foo ;
67
+ assert_eq ! ( "I'm a u32!" , bar_u32_fat. foo( ) ) ;
58
68
assert_eq ! ( 18 , unsafe { bar_u32_fat. bar( ) } ) ;
69
+
59
70
}
0 commit comments