summaryrefslogtreecommitdiffstats
path: root/src/test/ui/self/arbitrary_self_types_raw_pointer_struct.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/self/arbitrary_self_types_raw_pointer_struct.rs')
-rw-r--r--src/test/ui/self/arbitrary_self_types_raw_pointer_struct.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/self/arbitrary_self_types_raw_pointer_struct.rs b/src/test/ui/self/arbitrary_self_types_raw_pointer_struct.rs
new file mode 100644
index 000000000..0eab7617f
--- /dev/null
+++ b/src/test/ui/self/arbitrary_self_types_raw_pointer_struct.rs
@@ -0,0 +1,28 @@
+// run-pass
+#![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()});
+}