]> git.proxmox.com Git - rustc.git/blob - src/test/ui/transmutability/visibility/should_reject_if_dst_has_private_variant.rs
Update upstream source from tag 'upstream/1.64.0+dfsg1'
[rustc.git] / src / test / ui / transmutability / visibility / should_reject_if_dst_has_private_variant.rs
1 //! Unless visibility is assumed, a transmutation should be rejected if the
2 //! destination type contains a private variant.
3
4 #![crate_type = "lib"]
5 #![feature(transmutability)]
6 #![allow(dead_code)]
7
8 mod assert {
9 use std::mem::BikeshedIntrinsicFrom;
10
11 pub fn is_transmutable<Src, Dst, Context>()
12 where
13 Dst: BikeshedIntrinsicFrom<Src, Context, false, false, false, false>
14 // visibility is NOT assumed ---------------------------------^^^^^
15 {}
16 }
17
18 mod src {
19 #[repr(C)] pub(in super) struct Zst;
20
21 #[repr(C)] pub(in super) struct Src {
22 pub(in super) field: Zst,
23 }
24 }
25
26 mod dst {
27 #[derive(Copy, Clone)]
28 #[repr(C)] pub(in super) struct Zst;
29
30 #[repr(C)] pub(in super) union Dst {
31 pub(self) field: Zst, // <- private variant
32 }
33 }
34
35 fn test() {
36 struct Context;
37 assert::is_transmutable::<src::Src, dst::Dst, Context>(); //~ ERROR cannot be safely transmuted
38 }