]> git.proxmox.com Git - rustc.git/blob - src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / transmutability / malformed-program-gracefulness / wrong-type-assume.rs
1 //! The implementation must behave well if const values of wrong types are
2 //! provided.
3
4 #![crate_type = "lib"]
5 #![feature(adt_const_params)]
6 #![feature(generic_const_exprs)]
7 #![feature(transmutability)]
8 #![allow(dead_code, incomplete_features, non_camel_case_types)]
9
10 mod assert {
11 use std::mem::{Assume, BikeshedIntrinsicFrom};
12
13 pub fn is_transmutable<
14 Src,
15 Dst,
16 Context,
17 const ASSUME_ALIGNMENT: bool,
18 const ASSUME_LIFETIMES: bool,
19 const ASSUME_SAFETY: bool,
20 const ASSUME_VALIDITY: bool,
21 >()
22 where
23 Dst: BikeshedIntrinsicFrom<
24 Src,
25 Context,
26 { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
27 >,
28 {}
29
30 const fn from_options(
31 alignment: bool,
32 lifetimes: bool,
33 safety: bool,
34 validity: bool,
35 ) -> Assume {
36 Assume {
37 alignment,
38 lifetimes,
39 safety,
40 validity,
41 }
42 }
43 }
44
45 fn test() {
46 struct Context;
47 #[repr(C)] struct Src;
48 #[repr(C)] struct Dst;
49 assert::is_transmutable::<Src, Dst, Context, {0u8}, false, false, false>(); //~ ERROR mismatched types
50 assert::is_transmutable::<Src, Dst, Context, false, {0u8}, false, false>(); //~ ERROR mismatched types
51 assert::is_transmutable::<Src, Dst, Context, false, false, {0u8}, false>(); //~ ERROR mismatched types
52 assert::is_transmutable::<Src, Dst, Context, false, false, false, {0u8}>(); //~ ERROR mismatched types
53 }