UnsafeCell now has no niches, ever.
This commit is contained in:
parent
e78e747f53
commit
2a899dc1cf
22 changed files with 73 additions and 512 deletions
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
// run-pass
|
||||
|
||||
#![feature(no_niche)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
use std::mem::size_of;
|
||||
use std::num::NonZeroU32 as N32;
|
||||
|
|
@ -16,8 +14,7 @@ struct Wrapper<T>(T);
|
|||
#[repr(transparent)]
|
||||
struct Transparent<T>(T);
|
||||
|
||||
#[repr(no_niche)]
|
||||
struct NoNiche<T>(T);
|
||||
struct NoNiche<T>(UnsafeCell<T>);
|
||||
|
||||
fn main() {
|
||||
assert_eq!(size_of::<Option<Wrapper<u32>>>(), 8);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// check-pass
|
||||
// aux-build:external_extern_fn.rs
|
||||
#![crate_type = "lib"]
|
||||
#![feature(no_niche)]
|
||||
#![warn(clashing_extern_declarations)]
|
||||
|
||||
mod redeclared_different_signature {
|
||||
|
|
@ -400,9 +399,8 @@ mod hidden_niche {
|
|||
#[repr(transparent)]
|
||||
struct Transparent { x: NonZeroUsize }
|
||||
|
||||
#[repr(no_niche)]
|
||||
#[repr(transparent)]
|
||||
struct TransparentNoNiche { y: NonZeroUsize }
|
||||
struct TransparentNoNiche { y: UnsafeCell<NonZeroUsize> }
|
||||
|
||||
extern "C" {
|
||||
fn hidden_niche_transparent() -> Option<Transparent>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: `clash` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:15:13
|
||||
--> $DIR/clashing-extern-fn.rs:14:13
|
||||
|
|
||||
LL | fn clash(x: u8);
|
||||
| ---------------- `clash` previously declared here
|
||||
|
|
@ -8,7 +8,7 @@ LL | fn clash(x: u64);
|
|||
| ^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/clashing-extern-fn.rs:5:9
|
||||
--> $DIR/clashing-extern-fn.rs:4:9
|
||||
|
|
||||
LL | #![warn(clashing_extern_declarations)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -16,7 +16,7 @@ LL | #![warn(clashing_extern_declarations)]
|
|||
found `unsafe extern "C" fn(u64)`
|
||||
|
||||
warning: `extern_link_name` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:53:9
|
||||
--> $DIR/clashing-extern-fn.rs:52:9
|
||||
|
|
||||
LL | / #[link_name = "extern_link_name"]
|
||||
LL | | fn some_new_name(x: i16);
|
||||
|
|
@ -29,7 +29,7 @@ LL | fn extern_link_name(x: u32);
|
|||
found `unsafe extern "C" fn(u32)`
|
||||
|
||||
warning: `some_other_extern_link_name` redeclares `some_other_new_name` with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:56:9
|
||||
--> $DIR/clashing-extern-fn.rs:55:9
|
||||
|
|
||||
LL | fn some_other_new_name(x: i16);
|
||||
| ------------------------------- `some_other_new_name` previously declared here
|
||||
|
|
@ -43,7 +43,7 @@ LL | | fn some_other_extern_link_name(x: u32);
|
|||
found `unsafe extern "C" fn(u32)`
|
||||
|
||||
warning: `other_both_names_different` redeclares `link_name_same` with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:60:9
|
||||
--> $DIR/clashing-extern-fn.rs:59:9
|
||||
|
|
||||
LL | / #[link_name = "link_name_same"]
|
||||
LL | | fn both_names_different(x: i16);
|
||||
|
|
@ -58,7 +58,7 @@ LL | | fn other_both_names_different(x: u32);
|
|||
found `unsafe extern "C" fn(u32)`
|
||||
|
||||
warning: `different_mod` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:73:9
|
||||
--> $DIR/clashing-extern-fn.rs:72:9
|
||||
|
|
||||
LL | fn different_mod(x: u8);
|
||||
| ------------------------ `different_mod` previously declared here
|
||||
|
|
@ -70,7 +70,7 @@ LL | fn different_mod(x: u64);
|
|||
found `unsafe extern "C" fn(u64)`
|
||||
|
||||
warning: `variadic_decl` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:83:9
|
||||
--> $DIR/clashing-extern-fn.rs:82:9
|
||||
|
|
||||
LL | fn variadic_decl(x: u8, ...);
|
||||
| ----------------------------- `variadic_decl` previously declared here
|
||||
|
|
@ -82,7 +82,7 @@ LL | fn variadic_decl(x: u8);
|
|||
found `unsafe extern "C" fn(u8)`
|
||||
|
||||
warning: `weigh_banana` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:143:13
|
||||
--> $DIR/clashing-extern-fn.rs:142:13
|
||||
|
|
||||
LL | fn weigh_banana(count: *const Banana) -> u64;
|
||||
| --------------------------------------------- `weigh_banana` previously declared here
|
||||
|
|
@ -94,7 +94,7 @@ LL | fn weigh_banana(count: *const Banana) -> u64;
|
|||
found `unsafe extern "C" fn(*const three::Banana) -> u64`
|
||||
|
||||
warning: `draw_point` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:172:13
|
||||
--> $DIR/clashing-extern-fn.rs:171:13
|
||||
|
|
||||
LL | fn draw_point(p: Point);
|
||||
| ------------------------ `draw_point` previously declared here
|
||||
|
|
@ -106,7 +106,7 @@ LL | fn draw_point(p: Point);
|
|||
found `unsafe extern "C" fn(sameish_members::b::Point)`
|
||||
|
||||
warning: `origin` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:198:13
|
||||
--> $DIR/clashing-extern-fn.rs:197:13
|
||||
|
|
||||
LL | fn origin() -> Point3;
|
||||
| ---------------------- `origin` previously declared here
|
||||
|
|
@ -118,7 +118,7 @@ LL | fn origin() -> Point3;
|
|||
found `unsafe extern "C" fn() -> same_sized_members_clash::b::Point3`
|
||||
|
||||
warning: `transparent_incorrect` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:221:13
|
||||
--> $DIR/clashing-extern-fn.rs:220:13
|
||||
|
|
||||
LL | fn transparent_incorrect() -> T;
|
||||
| -------------------------------- `transparent_incorrect` previously declared here
|
||||
|
|
@ -130,7 +130,7 @@ LL | fn transparent_incorrect() -> isize;
|
|||
found `unsafe extern "C" fn() -> isize`
|
||||
|
||||
warning: `missing_return_type` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:239:13
|
||||
--> $DIR/clashing-extern-fn.rs:238:13
|
||||
|
|
||||
LL | fn missing_return_type() -> usize;
|
||||
| ---------------------------------- `missing_return_type` previously declared here
|
||||
|
|
@ -142,7 +142,7 @@ LL | fn missing_return_type();
|
|||
found `unsafe extern "C" fn()`
|
||||
|
||||
warning: `non_zero_usize` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:257:13
|
||||
--> $DIR/clashing-extern-fn.rs:256:13
|
||||
|
|
||||
LL | fn non_zero_usize() -> core::num::NonZeroUsize;
|
||||
| ----------------------------------------------- `non_zero_usize` previously declared here
|
||||
|
|
@ -154,7 +154,7 @@ LL | fn non_zero_usize() -> usize;
|
|||
found `unsafe extern "C" fn() -> usize`
|
||||
|
||||
warning: `non_null_ptr` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:259:13
|
||||
--> $DIR/clashing-extern-fn.rs:258:13
|
||||
|
|
||||
LL | fn non_null_ptr() -> core::ptr::NonNull<usize>;
|
||||
| ----------------------------------------------- `non_null_ptr` previously declared here
|
||||
|
|
@ -166,7 +166,7 @@ LL | fn non_null_ptr() -> *const usize;
|
|||
found `unsafe extern "C" fn() -> *const usize`
|
||||
|
||||
warning: `option_non_zero_usize_incorrect` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:357:13
|
||||
--> $DIR/clashing-extern-fn.rs:356:13
|
||||
|
|
||||
LL | fn option_non_zero_usize_incorrect() -> usize;
|
||||
| ---------------------------------------------- `option_non_zero_usize_incorrect` previously declared here
|
||||
|
|
@ -178,7 +178,7 @@ LL | fn option_non_zero_usize_incorrect() -> isize;
|
|||
found `unsafe extern "C" fn() -> isize`
|
||||
|
||||
warning: `option_non_null_ptr_incorrect` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:359:13
|
||||
--> $DIR/clashing-extern-fn.rs:358:13
|
||||
|
|
||||
LL | fn option_non_null_ptr_incorrect() -> *const usize;
|
||||
| --------------------------------------------------- `option_non_null_ptr_incorrect` previously declared here
|
||||
|
|
@ -190,7 +190,7 @@ LL | fn option_non_null_ptr_incorrect() -> *const isize;
|
|||
found `unsafe extern "C" fn() -> *const isize`
|
||||
|
||||
warning: `hidden_niche_transparent_no_niche` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:410:13
|
||||
--> $DIR/clashing-extern-fn.rs:408:13
|
||||
|
|
||||
LL | fn hidden_niche_transparent_no_niche() -> usize;
|
||||
| ------------------------------------------------ `hidden_niche_transparent_no_niche` previously declared here
|
||||
|
|
@ -202,7 +202,7 @@ LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoN
|
|||
found `unsafe extern "C" fn() -> Option<TransparentNoNiche>`
|
||||
|
||||
warning: `hidden_niche_unsafe_cell` redeclared with a different signature
|
||||
--> $DIR/clashing-extern-fn.rs:414:13
|
||||
--> $DIR/clashing-extern-fn.rs:412:13
|
||||
|
|
||||
LL | fn hidden_niche_unsafe_cell() -> usize;
|
||||
| --------------------------------------- `hidden_niche_unsafe_cell` previously declared here
|
||||
|
|
@ -214,7 +214,7 @@ LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize
|
|||
found `unsafe extern "C" fn() -> Option<UnsafeCell<NonZeroUsize>>`
|
||||
|
||||
warning: `extern` block uses type `Option<TransparentNoNiche>`, which is not FFI-safe
|
||||
--> $DIR/clashing-extern-fn.rs:410:55
|
||||
--> $DIR/clashing-extern-fn.rs:408:55
|
||||
|
|
||||
LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoNiche>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
||||
|
|
@ -224,7 +224,7 @@ LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoN
|
|||
= note: enum has no representation hint
|
||||
|
||||
warning: `extern` block uses type `Option<UnsafeCell<NonZeroUsize>>`, which is not FFI-safe
|
||||
--> $DIR/clashing-extern-fn.rs:414:46
|
||||
--> $DIR/clashing-extern-fn.rs:412:46
|
||||
|
|
||||
LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
use std::num::NonZeroU8 as N8;
|
||||
use std::num::NonZeroU16 as N16;
|
||||
|
||||
#[repr(no_niche)]
|
||||
pub struct Cloaked(N16);
|
||||
//~^^ ERROR the attribute `repr(no_niche)` is currently unstable [E0658]
|
||||
|
||||
#[repr(transparent, no_niche)]
|
||||
pub struct Shadowy(N16);
|
||||
//~^^ ERROR the attribute `repr(no_niche)` is currently unstable [E0658]
|
||||
|
||||
#[repr(no_niche)]
|
||||
pub enum Cloaked1 { _A(N16), }
|
||||
//~^^ ERROR the attribute `repr(no_niche)` is currently unstable [E0658]
|
||||
|
||||
#[repr(no_niche)]
|
||||
pub enum Cloaked2 { _A(N16), _B(u8, N8) }
|
||||
//~^^ ERROR the attribute `repr(no_niche)` is currently unstable [E0658]
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
error[E0658]: the attribute `repr(no_niche)` is currently unstable
|
||||
--> $DIR/feature-gate-no-niche.rs:4:8
|
||||
|
|
||||
LL | #[repr(no_niche)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: add `#![feature(no_niche)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: the attribute `repr(no_niche)` is currently unstable
|
||||
--> $DIR/feature-gate-no-niche.rs:8:21
|
||||
|
|
||||
LL | #[repr(transparent, no_niche)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: add `#![feature(no_niche)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: the attribute `repr(no_niche)` is currently unstable
|
||||
--> $DIR/feature-gate-no-niche.rs:12:8
|
||||
|
|
||||
LL | #[repr(no_niche)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: add `#![feature(no_niche)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: the attribute `repr(no_niche)` is currently unstable
|
||||
--> $DIR/feature-gate-no-niche.rs:16:8
|
||||
|
|
||||
LL | #[repr(no_niche)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: add `#![feature(no_niche)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#![feature(no_niche)]
|
||||
|
||||
use std::num::NonZeroU8 as N8;
|
||||
use std::num::NonZeroU16 as N16;
|
||||
|
||||
#[repr(no_niche)]
|
||||
pub union Cloaked1 { _A: N16 }
|
||||
//~^^ ERROR attribute should be applied to a struct or enum [E0517]
|
||||
|
||||
#[repr(no_niche)]
|
||||
pub union Cloaked2 { _A: N16, _B: (u8, N8) }
|
||||
//~^^ ERROR attribute should be applied to a struct or enum [E0517]
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
error[E0517]: attribute should be applied to a struct or enum
|
||||
--> $DIR/repr-no-niche-inapplicable-to-unions.rs:6:8
|
||||
|
|
||||
LL | #[repr(no_niche)]
|
||||
| ^^^^^^^^
|
||||
LL | pub union Cloaked1 { _A: N16 }
|
||||
| ------------------------------ not a struct or enum
|
||||
|
||||
error[E0517]: attribute should be applied to a struct or enum
|
||||
--> $DIR/repr-no-niche-inapplicable-to-unions.rs:10:8
|
||||
|
|
||||
LL | #[repr(no_niche)]
|
||||
| ^^^^^^^^
|
||||
LL | pub union Cloaked2 { _A: N16, _B: (u8, N8) }
|
||||
| -------------------------------------------- not a struct or enum
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0517`.
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
// run-pass
|
||||
|
||||
// This file tests repr(no_niche), which causes an struct/enum to hide
|
||||
// any niche space that may exist in its internal state from the
|
||||
// context it appears in.
|
||||
|
||||
// Here are the axes this test is seeking to cover:
|
||||
//
|
||||
// repr annotation:
|
||||
// visible: (); cloaked: (no_niche); transparent: (transparent); shadowy: (transparent, no_niche)
|
||||
//
|
||||
// enum vs struct
|
||||
//
|
||||
// niche-type via type-parameter vs inline declaration
|
||||
|
||||
#![feature(decl_macro)]
|
||||
#![feature(no_niche)]
|
||||
|
||||
use std::mem::size_of;
|
||||
use std::num::{NonZeroU8, NonZeroU16};
|
||||
|
||||
mod struct_inline {
|
||||
use std::num::NonZeroU16 as N16;
|
||||
|
||||
#[derive(Debug)] pub struct Visible(N16);
|
||||
|
||||
#[repr(no_niche)]
|
||||
#[derive(Debug)] pub struct Cloaked(N16);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug)] pub struct Transparent(N16);
|
||||
|
||||
#[repr(transparent, no_niche)]
|
||||
#[derive(Debug)] pub struct Shadowy(N16);
|
||||
}
|
||||
|
||||
mod struct_param {
|
||||
#[derive(Debug)] pub struct Visible<T>(T);
|
||||
|
||||
#[repr(no_niche)]
|
||||
#[derive(Debug)] pub struct Cloaked<T>(T);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug)] pub struct Transparent<T>(T);
|
||||
|
||||
#[repr(transparent, no_niche)]
|
||||
#[derive(Debug)] pub struct Shadowy<T>(T);
|
||||
}
|
||||
|
||||
mod enum_inline {
|
||||
use crate::two_fifty_six_variant_enum;
|
||||
use std::num::{NonZeroU8 as N8, NonZeroU16 as N16};
|
||||
|
||||
#[derive(Debug)] pub enum Visible1 { _A(N16), }
|
||||
|
||||
#[repr(no_niche)]
|
||||
#[derive(Debug)] pub enum Cloaked1 { _A(N16), }
|
||||
|
||||
// (N.B.: transparent enums must be univariant)
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug)] pub enum Transparent { _A(N16), }
|
||||
|
||||
#[repr(transparent, no_niche)]
|
||||
#[derive(Debug)] pub enum Shadowy { _A(N16), }
|
||||
|
||||
// including multivariant enums for completeness. Payload and
|
||||
// number of variants (i.e. discriminant size) have been chosen so
|
||||
// that layout including discriminant is 4 bytes, with no space in
|
||||
// padding to hide another discrimnant from the surrounding
|
||||
// context.
|
||||
//
|
||||
// (Note that multivariant enums cannot usefully expose a niche in
|
||||
// general; this test is relying on that.)
|
||||
two_fifty_six_variant_enum!(Visible2, N8);
|
||||
|
||||
two_fifty_six_variant_enum!(#[repr(no_niche)] Cloaked2, N8);
|
||||
}
|
||||
|
||||
mod enum_param {
|
||||
use super::two_fifty_six_variant_enum;
|
||||
|
||||
#[derive(Debug)] pub enum Visible1<T> { _A(T), }
|
||||
|
||||
#[repr(no_niche)]
|
||||
#[derive(Debug)] pub enum Cloaked1<T> { _A(T), }
|
||||
|
||||
// (N.B.: transparent enums must be univariant)
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug)] pub enum Transparent<T> { _A(T), }
|
||||
|
||||
#[repr(transparent, no_niche)]
|
||||
#[derive(Debug)] pub enum Shadowy<T> { _A(T), }
|
||||
|
||||
// including multivariant enums for completeness. Same notes apply
|
||||
// here as above (assuming `T` is instantiated with `NonZeroU8`).
|
||||
two_fifty_six_variant_enum!(Visible2<T>);
|
||||
|
||||
two_fifty_six_variant_enum!(#[repr(no_niche)] Cloaked2<T>);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// sanity-checks
|
||||
assert_eq!(size_of::<struct_inline::Visible>(), 2);
|
||||
assert_eq!(size_of::<struct_inline::Cloaked>(), 2);
|
||||
assert_eq!(size_of::<struct_inline::Transparent>(), 2);
|
||||
assert_eq!(size_of::<struct_inline::Shadowy>(), 2);
|
||||
|
||||
assert_eq!(size_of::<struct_param::Visible<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<struct_param::Cloaked<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<struct_param::Transparent<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<struct_param::Shadowy<NonZeroU16>>(), 2);
|
||||
|
||||
assert_eq!(size_of::<enum_inline::Visible1>(), 2);
|
||||
assert_eq!(size_of::<enum_inline::Cloaked1>(), 2);
|
||||
assert_eq!(size_of::<enum_inline::Transparent>(), 2); // transparent enums are univariant
|
||||
assert_eq!(size_of::<enum_inline::Shadowy>(), 2);
|
||||
assert_eq!(size_of::<enum_inline::Visible2>(), 4);
|
||||
assert_eq!(size_of::<enum_inline::Cloaked2>(), 4);
|
||||
|
||||
assert_eq!(size_of::<enum_param::Visible1<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<enum_param::Cloaked1<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<enum_param::Transparent<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<enum_param::Shadowy<NonZeroU16>>(), 2);
|
||||
assert_eq!(size_of::<enum_param::Visible2<NonZeroU8>>(), 4);
|
||||
assert_eq!(size_of::<enum_param::Cloaked2<NonZeroU8>>(), 4);
|
||||
|
||||
// now the actual tests of no_niche: how do inputs above compose
|
||||
// with `Option` type constructor. The cases with a `_+2` are the
|
||||
// ones where no_niche fires.
|
||||
assert_eq!(size_of::<Option<struct_inline::Visible>>(), 2);
|
||||
assert_eq!(size_of::<Option<struct_inline::Cloaked>>(), 2+2);
|
||||
assert_eq!(size_of::<Option<struct_inline::Transparent>>(), 2);
|
||||
assert_eq!(size_of::<Option<struct_inline::Shadowy>>(), 2+2);
|
||||
|
||||
assert_eq!(size_of::<Option<struct_param::Visible<NonZeroU16>>>(), 2);
|
||||
assert_eq!(size_of::<Option<struct_param::Cloaked<NonZeroU16>>>(), 2+2);
|
||||
assert_eq!(size_of::<Option<struct_param::Transparent<NonZeroU16>>>(), 2);
|
||||
assert_eq!(size_of::<Option<struct_param::Shadowy<NonZeroU16>>>(), 2+2);
|
||||
|
||||
assert_eq!(size_of::<Option<enum_inline::Visible1>>(), 2);
|
||||
assert_eq!(size_of::<Option<enum_inline::Cloaked1>>(), 2+2);
|
||||
assert_eq!(size_of::<Option<enum_inline::Transparent>>(), 2);
|
||||
assert_eq!(size_of::<Option<enum_inline::Shadowy>>(), 2+2);
|
||||
// cannot use niche of multivariant payload
|
||||
assert_eq!(size_of::<Option<enum_inline::Visible2>>(), 4+2);
|
||||
assert_eq!(size_of::<Option<enum_inline::Cloaked2>>(), 4+2);
|
||||
|
||||
assert_eq!(size_of::<Option<enum_param::Visible1<NonZeroU16>>>(), 2);
|
||||
assert_eq!(size_of::<Option<enum_param::Cloaked1<NonZeroU16>>>(), 2+2);
|
||||
assert_eq!(size_of::<Option<enum_param::Transparent<NonZeroU16>>>(), 2);
|
||||
assert_eq!(size_of::<Option<enum_param::Shadowy<NonZeroU16>>>(), 2+2);
|
||||
// cannot use niche of multivariant payload
|
||||
assert_eq!(size_of::<Option<enum_param::Visible2<NonZeroU8>>>(), 4+2);
|
||||
assert_eq!(size_of::<Option<enum_param::Cloaked2<NonZeroU8>>>(), 4+2);
|
||||
}
|
||||
|
||||
macro two_fifty_six_variant_enum {
|
||||
($(#[$attr:meta])* $name:ident<$param:ident>) => {
|
||||
#[derive(Debug)] $(#[$attr])*
|
||||
pub enum $name<$param> {
|
||||
_V00($param, u16), _V01(u16, $param), _V02($param, u16), _V03(u16, $param),
|
||||
_V04($param, u16), _V05(u16, $param), _V06($param, u16), _V07(u16, $param),
|
||||
_V08($param, u16), _V09(u16, $param), _V0a($param, u16), _V0b(u16, $param),
|
||||
_V0c($param, u16), _V0d(u16, $param), _V0e($param, u16), _V0f(u16, $param),
|
||||
|
||||
_V10($param, u16), _V11(u16, $param), _V12($param, u16), _V13(u16, $param),
|
||||
_V14($param, u16), _V15(u16, $param), _V16($param, u16), _V17(u16, $param),
|
||||
_V18($param, u16), _V19(u16, $param), _V1a($param, u16), _V1b(u16, $param),
|
||||
_V1c($param, u16), _V1d(u16, $param), _V1e($param, u16), _V1f(u16, $param),
|
||||
|
||||
_V20($param, u16), _V21(u16, $param), _V22($param, u16), _V23(u16, $param),
|
||||
_V24($param, u16), _V25(u16, $param), _V26($param, u16), _V27(u16, $param),
|
||||
_V28($param, u16), _V29(u16, $param), _V2a($param, u16), _V2b(u16, $param),
|
||||
_V2c($param, u16), _V2d(u16, $param), _V2e($param, u16), _V2f(u16, $param),
|
||||
|
||||
_V30($param, u16), _V31(u16, $param), _V32($param, u16), _V33(u16, $param),
|
||||
_V34($param, u16), _V35(u16, $param), _V36($param, u16), _V37(u16, $param),
|
||||
_V38($param, u16), _V39(u16, $param), _V3a($param, u16), _V3b(u16, $param),
|
||||
_V3c($param, u16), _V3d(u16, $param), _V3e($param, u16), _V3f(u16, $param),
|
||||
|
||||
_V40($param, u16), _V41(u16, $param), _V42($param, u16), _V43(u16, $param),
|
||||
_V44($param, u16), _V45(u16, $param), _V46($param, u16), _V47(u16, $param),
|
||||
_V48($param, u16), _V49(u16, $param), _V4a($param, u16), _V4b(u16, $param),
|
||||
_V4c($param, u16), _V4d(u16, $param), _V4e($param, u16), _V4f(u16, $param),
|
||||
|
||||
_V50($param, u16), _V51(u16, $param), _V52($param, u16), _V53(u16, $param),
|
||||
_V54($param, u16), _V55(u16, $param), _V56($param, u16), _V57(u16, $param),
|
||||
_V58($param, u16), _V59(u16, $param), _V5a($param, u16), _V5b(u16, $param),
|
||||
_V5c($param, u16), _V5d(u16, $param), _V5e($param, u16), _V5f(u16, $param),
|
||||
|
||||
_V60($param, u16), _V61(u16, $param), _V62($param, u16), _V63(u16, $param),
|
||||
_V64($param, u16), _V65(u16, $param), _V66($param, u16), _V67(u16, $param),
|
||||
_V68($param, u16), _V69(u16, $param), _V6a($param, u16), _V6b(u16, $param),
|
||||
_V6c($param, u16), _V6d(u16, $param), _V6e($param, u16), _V6f(u16, $param),
|
||||
|
||||
_V70($param, u16), _V71(u16, $param), _V72($param, u16), _V73(u16, $param),
|
||||
_V74($param, u16), _V75(u16, $param), _V76($param, u16), _V77(u16, $param),
|
||||
_V78($param, u16), _V79(u16, $param), _V7a($param, u16), _V7b(u16, $param),
|
||||
_V7c($param, u16), _V7d(u16, $param), _V7e($param, u16), _V7f(u16, $param),
|
||||
|
||||
_V80($param, u16), _V81(u16, $param), _V82($param, u16), _V83(u16, $param),
|
||||
_V84($param, u16), _V85(u16, $param), _V86($param, u16), _V87(u16, $param),
|
||||
_V88($param, u16), _V89(u16, $param), _V8a($param, u16), _V8b(u16, $param),
|
||||
_V8c($param, u16), _V8d(u16, $param), _V8e($param, u16), _V8f(u16, $param),
|
||||
|
||||
_V90($param, u16), _V91(u16, $param), _V92($param, u16), _V93(u16, $param),
|
||||
_V94($param, u16), _V95(u16, $param), _V96($param, u16), _V97(u16, $param),
|
||||
_V98($param, u16), _V99(u16, $param), _V9a($param, u16), _V9b(u16, $param),
|
||||
_V9c($param, u16), _V9d(u16, $param), _V9e($param, u16), _V9f(u16, $param),
|
||||
|
||||
_Va0($param, u16), _Va1(u16, $param), _Va2($param, u16), _Va3(u16, $param),
|
||||
_Va4($param, u16), _Va5(u16, $param), _Va6($param, u16), _Va7(u16, $param),
|
||||
_Va8($param, u16), _Va9(u16, $param), _Vaa($param, u16), _Vab(u16, $param),
|
||||
_Vac($param, u16), _Vad(u16, $param), _Vae($param, u16), _Vaf(u16, $param),
|
||||
|
||||
_Vb0($param, u16), _Vb1(u16, $param), _Vb2($param, u16), _Vb3(u16, $param),
|
||||
_Vb4($param, u16), _Vb5(u16, $param), _Vb6($param, u16), _Vb7(u16, $param),
|
||||
_Vb8($param, u16), _Vb9(u16, $param), _Vba($param, u16), _Vbb(u16, $param),
|
||||
_Vbc($param, u16), _Vbd(u16, $param), _Vbe($param, u16), _Vbf(u16, $param),
|
||||
|
||||
_Vc0($param, u16), _Vc1(u16, $param), _Vc2($param, u16), _Vc3(u16, $param),
|
||||
_Vc4($param, u16), _Vc5(u16, $param), _Vc6($param, u16), _Vc7(u16, $param),
|
||||
_Vc8($param, u16), _Vc9(u16, $param), _Vca($param, u16), _Vcb(u16, $param),
|
||||
_Vcc($param, u16), _Vcd(u16, $param), _Vce($param, u16), _Vcf(u16, $param),
|
||||
|
||||
_Vd0($param, u16), _Vd1(u16, $param), _Vd2($param, u16), _Vd3(u16, $param),
|
||||
_Vd4($param, u16), _Vd5(u16, $param), _Vd6($param, u16), _Vd7(u16, $param),
|
||||
_Vd8($param, u16), _Vd9(u16, $param), _Vda($param, u16), _Vdb(u16, $param),
|
||||
_Vdc($param, u16), _Vdd(u16, $param), _Vde($param, u16), _Vdf(u16, $param),
|
||||
|
||||
_Ve0($param, u16), _Ve1(u16, $param), _Ve2($param, u16), _Ve3(u16, $param),
|
||||
_Ve4($param, u16), _Ve5(u16, $param), _Ve6($param, u16), _Ve7(u16, $param),
|
||||
_Ve8($param, u16), _Ve9(u16, $param), _Vea($param, u16), _Veb(u16, $param),
|
||||
_Vec($param, u16), _Ved(u16, $param), _Vee($param, u16), _Vef(u16, $param),
|
||||
|
||||
_Vf0($param, u16), _Vf1(u16, $param), _Vf2($param, u16), _Vf3(u16, $param),
|
||||
_Vf4($param, u16), _Vf5(u16, $param), _Vf6($param, u16), _Vf7(u16, $param),
|
||||
_Vf8($param, u16), _Vf9(u16, $param), _Vfa($param, u16), _Vfb(u16, $param),
|
||||
_Vfc($param, u16), _Vfd(u16, $param), _Vfe($param, u16), _Vff(u16, $param),
|
||||
}
|
||||
},
|
||||
|
||||
($(#[$attr:meta])* $name:ident, $param:ty) => {
|
||||
#[derive(Debug)] $(#[$attr])*
|
||||
pub enum $name {
|
||||
_V00($param, u16), _V01(u16, $param), _V02($param, u16), _V03(u16, $param),
|
||||
_V04($param, u16), _V05(u16, $param), _V06($param, u16), _V07(u16, $param),
|
||||
_V08($param, u16), _V09(u16, $param), _V0a($param, u16), _V0b(u16, $param),
|
||||
_V0c($param, u16), _V0d(u16, $param), _V0e($param, u16), _V0f(u16, $param),
|
||||
|
||||
_V10($param, u16), _V11(u16, $param), _V12($param, u16), _V13(u16, $param),
|
||||
_V14($param, u16), _V15(u16, $param), _V16($param, u16), _V17(u16, $param),
|
||||
_V18($param, u16), _V19(u16, $param), _V1a($param, u16), _V1b(u16, $param),
|
||||
_V1c($param, u16), _V1d(u16, $param), _V1e($param, u16), _V1f(u16, $param),
|
||||
|
||||
_V20($param, u16), _V21(u16, $param), _V22($param, u16), _V23(u16, $param),
|
||||
_V24($param, u16), _V25(u16, $param), _V26($param, u16), _V27(u16, $param),
|
||||
_V28($param, u16), _V29(u16, $param), _V2a($param, u16), _V2b(u16, $param),
|
||||
_V2c($param, u16), _V2d(u16, $param), _V2e($param, u16), _V2f(u16, $param),
|
||||
|
||||
_V30($param, u16), _V31(u16, $param), _V32($param, u16), _V33(u16, $param),
|
||||
_V34($param, u16), _V35(u16, $param), _V36($param, u16), _V37(u16, $param),
|
||||
_V38($param, u16), _V39(u16, $param), _V3a($param, u16), _V3b(u16, $param),
|
||||
_V3c($param, u16), _V3d(u16, $param), _V3e($param, u16), _V3f(u16, $param),
|
||||
|
||||
_V40($param, u16), _V41(u16, $param), _V42($param, u16), _V43(u16, $param),
|
||||
_V44($param, u16), _V45(u16, $param), _V46($param, u16), _V47(u16, $param),
|
||||
_V48($param, u16), _V49(u16, $param), _V4a($param, u16), _V4b(u16, $param),
|
||||
_V4c($param, u16), _V4d(u16, $param), _V4e($param, u16), _V4f(u16, $param),
|
||||
|
||||
_V50($param, u16), _V51(u16, $param), _V52($param, u16), _V53(u16, $param),
|
||||
_V54($param, u16), _V55(u16, $param), _V56($param, u16), _V57(u16, $param),
|
||||
_V58($param, u16), _V59(u16, $param), _V5a($param, u16), _V5b(u16, $param),
|
||||
_V5c($param, u16), _V5d(u16, $param), _V5e($param, u16), _V5f(u16, $param),
|
||||
|
||||
_V60($param, u16), _V61(u16, $param), _V62($param, u16), _V63(u16, $param),
|
||||
_V64($param, u16), _V65(u16, $param), _V66($param, u16), _V67(u16, $param),
|
||||
_V68($param, u16), _V69(u16, $param), _V6a($param, u16), _V6b(u16, $param),
|
||||
_V6c($param, u16), _V6d(u16, $param), _V6e($param, u16), _V6f(u16, $param),
|
||||
|
||||
_V70($param, u16), _V71(u16, $param), _V72($param, u16), _V73(u16, $param),
|
||||
_V74($param, u16), _V75(u16, $param), _V76($param, u16), _V77(u16, $param),
|
||||
_V78($param, u16), _V79(u16, $param), _V7a($param, u16), _V7b(u16, $param),
|
||||
_V7c($param, u16), _V7d(u16, $param), _V7e($param, u16), _V7f(u16, $param),
|
||||
|
||||
_V80($param, u16), _V81(u16, $param), _V82($param, u16), _V83(u16, $param),
|
||||
_V84($param, u16), _V85(u16, $param), _V86($param, u16), _V87(u16, $param),
|
||||
_V88($param, u16), _V89(u16, $param), _V8a($param, u16), _V8b(u16, $param),
|
||||
_V8c($param, u16), _V8d(u16, $param), _V8e($param, u16), _V8f(u16, $param),
|
||||
|
||||
_V90($param, u16), _V91(u16, $param), _V92($param, u16), _V93(u16, $param),
|
||||
_V94($param, u16), _V95(u16, $param), _V96($param, u16), _V97(u16, $param),
|
||||
_V98($param, u16), _V99(u16, $param), _V9a($param, u16), _V9b(u16, $param),
|
||||
_V9c($param, u16), _V9d(u16, $param), _V9e($param, u16), _V9f(u16, $param),
|
||||
|
||||
_Va0($param, u16), _Va1(u16, $param), _Va2($param, u16), _Va3(u16, $param),
|
||||
_Va4($param, u16), _Va5(u16, $param), _Va6($param, u16), _Va7(u16, $param),
|
||||
_Va8($param, u16), _Va9(u16, $param), _Vaa($param, u16), _Vab(u16, $param),
|
||||
_Vac($param, u16), _Vad(u16, $param), _Vae($param, u16), _Vaf(u16, $param),
|
||||
|
||||
_Vb0($param, u16), _Vb1(u16, $param), _Vb2($param, u16), _Vb3(u16, $param),
|
||||
_Vb4($param, u16), _Vb5(u16, $param), _Vb6($param, u16), _Vb7(u16, $param),
|
||||
_Vb8($param, u16), _Vb9(u16, $param), _Vba($param, u16), _Vbb(u16, $param),
|
||||
_Vbc($param, u16), _Vbd(u16, $param), _Vbe($param, u16), _Vbf(u16, $param),
|
||||
|
||||
_Vc0($param, u16), _Vc1(u16, $param), _Vc2($param, u16), _Vc3(u16, $param),
|
||||
_Vc4($param, u16), _Vc5(u16, $param), _Vc6($param, u16), _Vc7(u16, $param),
|
||||
_Vc8($param, u16), _Vc9(u16, $param), _Vca($param, u16), _Vcb(u16, $param),
|
||||
_Vcc($param, u16), _Vcd(u16, $param), _Vce($param, u16), _Vcf(u16, $param),
|
||||
|
||||
_Vd0($param, u16), _Vd1(u16, $param), _Vd2($param, u16), _Vd3(u16, $param),
|
||||
_Vd4($param, u16), _Vd5(u16, $param), _Vd6($param, u16), _Vd7(u16, $param),
|
||||
_Vd8($param, u16), _Vd9(u16, $param), _Vda($param, u16), _Vdb(u16, $param),
|
||||
_Vdc($param, u16), _Vdd(u16, $param), _Vde($param, u16), _Vdf(u16, $param),
|
||||
|
||||
_Ve0($param, u16), _Ve1(u16, $param), _Ve2($param, u16), _Ve3(u16, $param),
|
||||
_Ve4($param, u16), _Ve5(u16, $param), _Ve6($param, u16), _Ve7(u16, $param),
|
||||
_Ve8($param, u16), _Ve9(u16, $param), _Vea($param, u16), _Veb(u16, $param),
|
||||
_Vec($param, u16), _Ved(u16, $param), _Vee($param, u16), _Vef(u16, $param),
|
||||
|
||||
_Vf0($param, u16), _Vf1(u16, $param), _Vf2($param, u16), _Vf3(u16, $param),
|
||||
_Vf4($param, u16), _Vf5(u16, $param), _Vf6($param, u16), _Vf7(u16, $param),
|
||||
_Vf8($param, u16), _Vf9(u16, $param), _Vfa($param, u16), _Vfb(u16, $param),
|
||||
_Vfc($param, u16), _Vfd(u16, $param), _Vfe($param, u16), _Vff(u16, $param),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ fn is_value_unfrozen_raw<'tcx>(
|
|||
match val.ty().kind() {
|
||||
// the fact that we have to dig into every structs to search enums
|
||||
// leads us to the point checking `UnsafeCell` directly is the only option.
|
||||
ty::Adt(ty_def, ..) if Some(ty_def.did()) == cx.tcx.lang_items().unsafe_cell_type() => true,
|
||||
ty::Adt(ty_def, ..) if ty_def.is_unsafe_cell() => true,
|
||||
ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => {
|
||||
let val = cx.tcx.destructure_mir_constant(cx.param_env, val);
|
||||
val.fields.iter().any(|field| inner(cx, *field))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue