1 // Check that we can manually implement an object-unsafe trait for its trait object.
5 #![feature(object_safe_for_dispatch)]
11 fn virt(&self) -> char {
14 fn indirect(&self) -> char {
20 fn good_virt(&self) -> char {
23 fn good_indirect(&self) -> char {
28 impl<'a> Bad for dyn Bad + 'a {
32 fn virt(&self) -> char {
39 impl Bad for Struct {}
41 impl Good for Struct {}
46 let mut res = String::new();
48 // Directly call static.
49 res.push(Struct::stat()); // "A"
50 res.push(<dyn Bad>::stat()); // "AC"
52 let good: &dyn Good = &s;
54 // These look similar enough...
55 let bad = unsafe { std::mem::transmute::<&dyn Good, &dyn Bad>(good) };
58 res.push(s.virt()); // "ACB"
59 res.push(bad.virt()); // "ACBD"
61 // Indirectly call static.
62 res.push(s.indirect()); // "ACBDA"
63 res.push(bad.indirect()); // "ACBDAC"
65 assert_eq!(&res, "ACBDAC");