]> git.lizzy.rs Git - rust.git/blob - src/test/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_ty.rs
b9b74d18338af0c1fbbcada00b77d90287757987
[rust.git] / src / test / ui / transmutability / visibility / assume / should_accept_if_dst_has_unreachable_ty.rs
1 //! If visibility is assumed, a transmutation should be accepted even if the
2 //! destination type contains an unreachable field (e.g., a public field with a
3 //! private type). (This rule is distinct from type privacy, which still may
4 //! forbid naming such types.)
5
6 #![crate_type = "lib"]
7 #![feature(transmutability)]
8 #![allow(dead_code)]
9
10 mod assert {
11     use std::mem::{Assume, BikeshedIntrinsicFrom};
12
13     pub fn is_transmutable<Src, Dst, Context>()
14     where
15         Dst: BikeshedIntrinsicFrom<Src, Context, { Assume::SAFETY }>
16         // safety IS assumed --------------------^^^^^^^^^^^^^^^^^^
17     {}
18 }
19
20 mod src {
21     #[repr(C)] pub(self) struct Zst;
22
23     #[repr(C)] pub(in super) struct Src {
24         pub(self) field: Zst,
25     }
26 }
27
28 mod dst {
29     #[repr(C)] pub(in super) struct Zst;
30
31     // unreachable type
32     #[repr(C)] pub(self) struct Dst {
33         pub(in super) field: Zst,
34     }
35 }
36
37 fn test() {
38     struct Context;
39     assert::is_transmutable::<src::Src, dst::Dst, Context>(); //~ ERROR `Dst` is private
40 }