diff --git a/src/test/run-pass/arbitrary_self_types_raw_pointer_struct.rs b/src/test/run-pass/arbitrary_self_types_raw_pointer_struct.rs index e213d33a9c2d..8b6941e1c635 100644 --- a/src/test/run-pass/arbitrary_self_types_raw_pointer_struct.rs +++ b/src/test/run-pass/arbitrary_self_types_raw_pointer_struct.rs @@ -10,15 +10,28 @@ #![feature(arbitrary_self_types)] +use std::rc::Rc; + struct Foo(String); impl Foo { unsafe fn foo(self: *const Self) -> *const str { (*self).0.as_ref() } + + fn complicated_1(self: *const Rc) -> &'static str { + "Foo::complicated_1" + } + + unsafe fn complicated_2(self: Rc<*const Self>) -> *const str { + (**self).0.as_ref() + } } fn main() { let foo = Foo("abc123".into()); assert_eq!("abc123", unsafe { &*(&foo as *const Foo).foo() }); + assert_eq!("Foo::complicated_1", std::ptr::null::>().complicated_1()); + let rc = Rc::new(&foo as *const Foo); + assert_eq!("abc123", unsafe { &*rc.complicated_2()}); } diff --git a/src/test/run-pass/arbitrary_self_types_raw_pointer_trait.rs b/src/test/run-pass/arbitrary_self_types_raw_pointer_trait.rs index 0d64dacaf4e7..15b65d112781 100644 --- a/src/test/run-pass/arbitrary_self_types_raw_pointer_trait.rs +++ b/src/test/run-pass/arbitrary_self_types_raw_pointer_trait.rs @@ -16,6 +16,10 @@ trait Foo { fn foo(self: *const Self) -> &'static str; unsafe fn bar(self: *const Self) -> i64; + + unsafe fn complicated(self: *const *const Self) -> i64 where Self: Sized { + (*self).bar() + } } impl Foo for i32 { @@ -39,21 +43,28 @@ impl Foo for u32 { } fn main() { - let foo_i32 = ptr::null::() as *const Foo; - let foo_u32 = ptr::null::() as *const Foo; + let null_i32 = ptr::null::() as *const Foo; + let null_u32 = ptr::null::() as *const Foo; - assert_eq!("I'm an i32!", foo_i32.foo()); - assert_eq!("I'm a u32!", foo_u32.foo()); + assert_eq!("I'm an i32!", null_i32.foo()); + assert_eq!("I'm a u32!", null_u32.foo()); let bar_i32 = 5i32; let bar_i32_thin = &bar_i32 as *const i32; + assert_eq!("I'm an i32!", bar_i32_thin.foo()); assert_eq!(5, unsafe { bar_i32_thin.bar() }); + assert_eq!(5, unsafe { (&bar_i32_thin as *const *const i32).complicated() }); let bar_i32_fat = bar_i32_thin as *const Foo; + assert_eq!("I'm an i32!", bar_i32_fat.foo()); assert_eq!(5, unsafe { bar_i32_fat.bar() }); let bar_u32 = 18u32; let bar_u32_thin = &bar_u32 as *const u32; + assert_eq!("I'm a u32!", bar_u32_thin.foo()); assert_eq!(18, unsafe { bar_u32_thin.bar() }); + assert_eq!(18, unsafe { (&bar_u32_thin as *const *const u32).complicated() }); let bar_u32_fat = bar_u32_thin as *const Foo; + assert_eq!("I'm a u32!", bar_u32_fat.foo()); assert_eq!(18, unsafe { bar_u32_fat.bar() }); + }