summaryrefslogtreecommitdiffstats
path: root/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs')
-rw-r--r--tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs
new file mode 100644
index 000000000..dd57b877d
--- /dev/null
+++ b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_private_variant.rs
@@ -0,0 +1,39 @@
+// check-pass
+//! If visibility is assumed, a transmutation should be accepted even if the
+//! destination type contains a private variant.
+
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code)]
+
+mod assert {
+ use std::mem::{Assume, BikeshedIntrinsicFrom};
+
+ pub fn is_transmutable<Src, Dst, Context>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, { Assume::SAFETY }>
+ // safety IS assumed --------------------^^^^^^^^^^^^^^^^^^
+ {}
+}
+
+mod src {
+ #[repr(C)] pub(self) struct Zst;
+
+ #[repr(C)] pub(in super) struct Src {
+ pub(self) field: Zst,
+ }
+}
+
+mod dst {
+ #[derive(Copy, Clone)]
+ #[repr(C)] pub(in super) struct Zst;
+
+ #[repr(C)] pub(in super) union Dst {
+ pub(self) field: Zst, // <- private variant
+ }
+}
+
+fn test() {
+ struct Context;
+ assert::is_transmutable::<src::Src, dst::Dst, Context>();
+}