]>
Commit | Line | Data |
---|---|---|
064997fb FG |
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 { | |
f2b60f7d | 11 | use std::mem::{Assume, BikeshedIntrinsicFrom}; |
064997fb FG |
12 | |
13 | pub fn is_transmutable<Src, Dst, Context>() | |
14 | where | |
f2b60f7d FG |
15 | Dst: BikeshedIntrinsicFrom<Src, Context, { Assume::SAFETY }> |
16 | // safety IS assumed --------------------^^^^^^^^^^^^^^^^^^ | |
064997fb FG |
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(self) struct Zst; // <- unreachable type | |
30 | ||
31 | #[repr(C)] pub(in super) struct Dst { | |
32 | pub(in super) field: Zst, //~ ERROR private type | |
33 | } | |
34 | } | |
35 | ||
36 | fn test() { | |
37 | struct Context; | |
38 | assert::is_transmutable::<src::Src, dst::Dst, Context>(); | |
39 | } |