diff options
| author | Michael Hewson <michael@michaelhewson.ca> | 2017-12-14 18:43:27 +0100 |
|---|---|---|
| committer | Michael Hewson <michael@michaelhewson.ca> | 2017-12-17 10:13:09 +0100 |
| commit | 4cae2c087d0bfb336ae13a71b55034c4ff2e0acd (patch) | |
| tree | dc528d4b6d8b9187c7ac0f838aa9f5dcd7477f58 | |
| parent | bc0439b3880808e1385da4b99964d5d506f76e3f (diff) | |
| download | rust-4cae2c087d0bfb336ae13a71b55034c4ff2e0acd.tar.gz rust-4cae2c087d0bfb336ae13a71b55034c4ff2e0acd.zip | |
Add tests with *const Rc<Self> and similar self types
| -rw-r--r-- | src/test/run-pass/arbitrary_self_types_raw_pointer_struct.rs | 13 | ||||
| -rw-r--r-- | src/test/run-pass/arbitrary_self_types_raw_pointer_trait.rs | 19 |
2 files changed, 28 insertions, 4 deletions
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 e213d33a9c2..8b6941e1c63 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<Self>) -> &'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::<Rc<Foo>>().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 0d64dacaf4e..15b65d11278 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::<i32>() as *const Foo; - let foo_u32 = ptr::null::<u32>() as *const Foo; + let null_i32 = ptr::null::<i32>() as *const Foo; + let null_u32 = ptr::null::<u32>() 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() }); + } |
