Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8c5c291

Browse files
committed
safe transmute: test when ASSUME params are passed indirectly
ref: https://github.com/rust-lang/rust/pull/92268/files#r925258420
1 parent 18751a7 commit 8c5c291

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// check-pass
2+
//! The implementation should behave correctly when the `ASSUME` parameters are
3+
//! provided indirectly through an abstraction.
4+
5+
#![crate_type = "lib"]
6+
#![feature(transmutability)]
7+
#![allow(dead_code, incomplete_features, non_camel_case_types)]
8+
9+
mod assert {
10+
use std::mem::BikeshedIntrinsicFrom;
11+
12+
pub fn is_transmutable<
13+
Src,
14+
Dst,
15+
Context,
16+
const ASSUME_ALIGNMENT: bool,
17+
const ASSUME_LIFETIMES: bool,
18+
const ASSUME_VALIDITY: bool,
19+
const ASSUME_VISIBILITY: bool,
20+
>()
21+
where
22+
Dst: BikeshedIntrinsicFrom<
23+
Src,
24+
Context,
25+
ASSUME_ALIGNMENT,
26+
ASSUME_LIFETIMES,
27+
ASSUME_VALIDITY,
28+
ASSUME_VISIBILITY,
29+
>,
30+
{}
31+
}
32+
33+
fn direct() {
34+
struct Context;
35+
#[repr(C)] struct Src;
36+
#[repr(C)] struct Dst;
37+
38+
assert::is_transmutable::<Src, Dst, Context, false, false, false, false>();
39+
}
40+
41+
fn via_const() {
42+
struct Context;
43+
#[repr(C)] struct Src;
44+
#[repr(C)] struct Dst;
45+
46+
const FALSE: bool = false;
47+
48+
assert::is_transmutable::<Src, Dst, Context, FALSE, FALSE, FALSE, FALSE>();
49+
}
50+
51+
fn via_associated_const() {
52+
struct Context;
53+
#[repr(C)] struct Src;
54+
#[repr(C)] struct Dst;
55+
56+
trait Trait {
57+
const FALSE: bool = true;
58+
}
59+
60+
struct Ty;
61+
62+
impl Trait for Ty {}
63+
64+
assert::is_transmutable::<
65+
Src,
66+
Dst,
67+
Context,
68+
{Ty::FALSE},
69+
{Ty::FALSE},
70+
{Ty::FALSE},
71+
{Ty::FALSE}
72+
>();
73+
}

0 commit comments

Comments
 (0)