]> git.proxmox.com Git - rustc.git/blob - tests/ui/self/arbitrary_self_types_raw_pointer_struct.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / self / arbitrary_self_types_raw_pointer_struct.rs
1 // run-pass
2 #![feature(arbitrary_self_types)]
3
4 use std::rc::Rc;
5
6 struct Foo(String);
7
8 impl Foo {
9 unsafe fn foo(self: *const Self) -> *const str {
10 (*self).0.as_ref()
11 }
12
13 fn complicated_1(self: *const Rc<Self>) -> &'static str {
14 "Foo::complicated_1"
15 }
16
17 unsafe fn complicated_2(self: Rc<*const Self>) -> *const str {
18 (**self).0.as_ref()
19 }
20 }
21
22 fn main() {
23 let foo = Foo("abc123".into());
24 assert_eq!("abc123", unsafe { &*(&foo as *const Foo).foo() });
25 assert_eq!("Foo::complicated_1", std::ptr::null::<Rc<Foo>>().complicated_1());
26 let rc = Rc::new(&foo as *const Foo);
27 assert_eq!("abc123", unsafe { &*rc.complicated_2()});
28 }