Use generic NonZero in tests.

This commit is contained in:
Markus Reiter 2024-02-22 14:59:52 +01:00
parent 710048f790
commit b2fbb8a053
No known key found for this signature in database
GPG Key ID: 245293B51702655B
43 changed files with 519 additions and 516 deletions

View File

@ -1,7 +1,7 @@
//@ compile-flags: -O -Z merge-functions=disabled //@ compile-flags: -O -Z merge-functions=disabled
//@ only-x86_64 //@ only-x86_64
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
// CHECK-LABEL: @array_eq_value // CHECK-LABEL: @array_eq_value
#[no_mangle] #[no_mangle]
@ -63,7 +63,7 @@ pub fn array_eq_zero_short(x: [u16; 3]) -> bool {
// CHECK-LABEL: @array_eq_none_short(i40 // CHECK-LABEL: @array_eq_none_short(i40
#[no_mangle] #[no_mangle]
pub fn array_eq_none_short(x: [Option<std::num::NonZeroU8>; 5]) -> bool { pub fn array_eq_none_short(x: [Option<std::num::NonZero<u8>>; 5]) -> bool {
// CHECK-NEXT: start: // CHECK-NEXT: start:
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0 // CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0
// CHECK-NEXT: ret i1 %[[EQ]] // CHECK-NEXT: ret i1 %[[EQ]]

View File

@ -1,20 +1,17 @@
// This tests that optimized enum debug info accurately reflects the enum layout. //! This tests that optimized enum debug info accurately reflects the enum layout.
// This is ignored for the fallback mode on MSVC due to problems with PDB. //! This is ignored for the fallback mode on MSVC due to problems with PDB.
//!
//
//@ ignore-msvc
//@ compile-flags: -g -C no-prepopulate-passes //@ compile-flags: -g -C no-prepopulate-passes
//@ ignore-msvc
//
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}} // CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}} // CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}} // CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}
#![feature(generic_nonzero, never_type)]
#![feature(never_type)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Entity { pub struct Entity {
private: std::num::NonZeroU32, private: std::num::NonZero<u32>,
} }
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]

View File

@ -1,10 +1,10 @@
//@ compile-flags: -O -C no-prepopulate-passes //@ compile-flags: -O -C no-prepopulate-passes
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(dyn_star)] #![feature(dyn_star)]
#![feature(generic_nonzero)]
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::num::NonZeroU64; use std::num::NonZero;
use std::marker::PhantomPinned; use std::marker::PhantomPinned;
use std::ptr::NonNull; use std::ptr::NonNull;
@ -70,13 +70,13 @@ pub fn int(x: u64) -> u64 {
// CHECK: noundef i64 @nonzero_int(i64 noundef %x) // CHECK: noundef i64 @nonzero_int(i64 noundef %x)
#[no_mangle] #[no_mangle]
pub fn nonzero_int(x: NonZeroU64) -> NonZeroU64 { pub fn nonzero_int(x: NonZero<u64>) -> NonZero<u64> {
x x
} }
// CHECK: noundef i64 @option_nonzero_int(i64 noundef %x) // CHECK: noundef i64 @option_nonzero_int(i64 noundef %x)
#[no_mangle] #[no_mangle]
pub fn option_nonzero_int(x: Option<NonZeroU64>) -> Option<NonZeroU64> { pub fn option_nonzero_int(x: Option<NonZero<u64>>) -> Option<NonZero<u64>> {
x x
} }

View File

@ -2,11 +2,11 @@
//@ [OPT] compile-flags: -C opt-level=3 -C no-prepopulate-passes //@ [OPT] compile-flags: -C opt-level=3 -C no-prepopulate-passes
//@ [DBG] compile-flags: -C opt-level=0 -C no-prepopulate-passes //@ [DBG] compile-flags: -C opt-level=0 -C no-prepopulate-passes
//@ only-64bit (so I don't need to worry about usize) //@ only-64bit (so I don't need to worry about usize)
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
use std::mem::transmute; use std::mem::transmute;
use std::num::NonZeroU32; use std::num::NonZero;
#[repr(u8)] #[repr(u8)]
pub enum SmallEnum { pub enum SmallEnum {
@ -130,7 +130,7 @@ pub unsafe fn check_enum_to_char(x: Minus100ToPlus100) -> char {
// CHECK-LABEL: @check_swap_pair( // CHECK-LABEL: @check_swap_pair(
#[no_mangle] #[no_mangle]
pub unsafe fn check_swap_pair(x: (char, NonZeroU32)) -> (NonZeroU32, char) { pub unsafe fn check_swap_pair(x: (char, NonZero<u32>)) -> (NonZero<u32>, char) {
// OPT: %0 = icmp ule i32 %x.0, 1114111 // OPT: %0 = icmp ule i32 %x.0, 1114111
// OPT: call void @llvm.assume(i1 %0) // OPT: call void @llvm.assume(i1 %0)
// OPT: %1 = icmp uge i32 %x.0, 1 // OPT: %1 = icmp uge i32 %x.0, 1

View File

@ -1,13 +1,13 @@
//! This test checks that compiler don't generate useless compares to zeros //! This test checks that compiler don't generate useless compares to zeros
//! for NonZero integer types. //! for `NonZero` integer types.
//!
//@ compile-flags: -O --edition=2021 -Zmerge-functions=disabled //@ compile-flags: -O --edition=2021 -Zmerge-functions=disabled
//@ only-64bit (because the LLVM type of i64 for usize shows up) //@ only-64bit (because the LLVM type of i64 for usize shows up)
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
use core::num::*;
use core::ptr::NonNull; use core::ptr::NonNull;
use core::num::NonZero;
// CHECK-LABEL: @check_non_null // CHECK-LABEL: @check_non_null
#[no_mangle] #[no_mangle]
@ -18,7 +18,7 @@ pub fn check_non_null(x: NonNull<u8>) -> bool {
// CHECK-LABEL: @equals_zero_is_false_u8 // CHECK-LABEL: @equals_zero_is_false_u8
#[no_mangle] #[no_mangle]
pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool { pub fn equals_zero_is_false_u8(x: NonZero<u8>) -> bool {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: ret i1 false // CHECK: ret i1 false
// CHECK-NOT: br // CHECK-NOT: br
@ -27,7 +27,7 @@ pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool {
// CHECK-LABEL: @not_equals_zero_is_true_u8 // CHECK-LABEL: @not_equals_zero_is_true_u8
#[no_mangle] #[no_mangle]
pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool { pub fn not_equals_zero_is_true_u8(x: NonZero<u8>) -> bool {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: ret i1 true // CHECK: ret i1 true
// CHECK-NOT: br // CHECK-NOT: br
@ -36,7 +36,7 @@ pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool {
// CHECK-LABEL: @equals_zero_is_false_i8 // CHECK-LABEL: @equals_zero_is_false_i8
#[no_mangle] #[no_mangle]
pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool { pub fn equals_zero_is_false_i8(x: NonZero<i8>) -> bool {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: ret i1 false // CHECK: ret i1 false
// CHECK-NOT: br // CHECK-NOT: br
@ -45,7 +45,7 @@ pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool {
// CHECK-LABEL: @not_equals_zero_is_true_i8 // CHECK-LABEL: @not_equals_zero_is_true_i8
#[no_mangle] #[no_mangle]
pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool { pub fn not_equals_zero_is_true_i8(x: NonZero<i8>) -> bool {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: ret i1 true // CHECK: ret i1 true
// CHECK-NOT: br // CHECK-NOT: br
@ -54,7 +54,7 @@ pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool {
// CHECK-LABEL: @usize_try_from_u32 // CHECK-LABEL: @usize_try_from_u32
#[no_mangle] #[no_mangle]
pub fn usize_try_from_u32(x: NonZeroU32) -> NonZeroUsize { pub fn usize_try_from_u32(x: NonZero<u32>) -> NonZero<usize> {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: zext i32 %{{.*}} to i64 // CHECK: zext i32 %{{.*}} to i64
// CHECK-NOT: br // CHECK-NOT: br
@ -64,7 +64,7 @@ pub fn usize_try_from_u32(x: NonZeroU32) -> NonZeroUsize {
// CHECK-LABEL: @isize_try_from_i32 // CHECK-LABEL: @isize_try_from_i32
#[no_mangle] #[no_mangle]
pub fn isize_try_from_i32(x: NonZeroI32) -> NonZeroIsize { pub fn isize_try_from_i32(x: NonZero<i32>) -> NonZero<isize> {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: sext i32 %{{.*}} to i64 // CHECK: sext i32 %{{.*}} to i64
// CHECK-NOT: br // CHECK-NOT: br
@ -74,7 +74,7 @@ pub fn isize_try_from_i32(x: NonZeroI32) -> NonZeroIsize {
// CHECK-LABEL: @u64_from_nonzero_is_not_zero // CHECK-LABEL: @u64_from_nonzero_is_not_zero
#[no_mangle] #[no_mangle]
pub fn u64_from_nonzero_is_not_zero(x: NonZeroU64)->bool { pub fn u64_from_nonzero_is_not_zero(x: NonZero<u64>)->bool {
// CHECK-NOT: br // CHECK-NOT: br
// CHECK: ret i1 false // CHECK: ret i1 false
// CHECK-NOT: br // CHECK-NOT: br

View File

@ -1,9 +1,9 @@
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0 //@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::num::NonZeroU16; use std::num::NonZero;
pub struct Bytes { pub struct Bytes {
a: u8, a: u8,
@ -99,14 +99,14 @@ pub fn load_int(x: &u16) -> u16 {
// CHECK-LABEL: @load_nonzero_int // CHECK-LABEL: @load_nonzero_int
#[no_mangle] #[no_mangle]
pub fn load_nonzero_int(x: &NonZeroU16) -> NonZeroU16 { pub fn load_nonzero_int(x: &NonZero<u16>) -> NonZero<u16> {
// CHECK: load i16, ptr %x, align 2, !range ![[NONZEROU16_RANGE:[0-9]+]], !noundef !{{[0-9]+}} // CHECK: load i16, ptr %x, align 2, !range ![[NONZEROU16_RANGE:[0-9]+]], !noundef !{{[0-9]+}}
*x *x
} }
// CHECK-LABEL: @load_option_nonzero_int // CHECK-LABEL: @load_option_nonzero_int
#[no_mangle] #[no_mangle]
pub fn load_option_nonzero_int(x: &Option<NonZeroU16>) -> Option<NonZeroU16> { pub fn load_option_nonzero_int(x: &Option<NonZero<u16>>) -> Option<NonZero<u16>> {
// CHECK: load i16, ptr %x, align 2, !noundef ![[NOUNDEF]]{{$}} // CHECK: load i16, ptr %x, align 2, !noundef ![[NOUNDEF]]{{$}}
*x *x
} }

View File

@ -1,14 +1,13 @@
//@ compile-flags: -O -Z randomize-layout=no //@ compile-flags: -O -Z randomize-layout=no
//@ only-x86_64 //@ only-x86_64
//@ ignore-llvm-version: 16.0.0 //@ ignore-llvm-version: 16.0.0
// ^ needs https://reviews.llvm.org/D146149 in 16.0.1 // ^-- needs https://reviews.llvm.org/D146149 in 16.0.1
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(option_as_slice)] #![feature(generic_nonzero)]
extern crate core; extern crate core;
use core::num::NonZeroU64; use core::num::NonZero;
use core::option::Option; use core::option::Option;
// CHECK-LABEL: @u64_opt_as_slice // CHECK-LABEL: @u64_opt_as_slice
@ -23,7 +22,7 @@ pub fn u64_opt_as_slice(o: &Option<u64>) -> &[u64] {
// CHECK-LABEL: @nonzero_u64_opt_as_slice // CHECK-LABEL: @nonzero_u64_opt_as_slice
#[no_mangle] #[no_mangle]
pub fn nonzero_u64_opt_as_slice(o: &Option<NonZeroU64>) -> &[NonZeroU64] { pub fn nonzero_u64_opt_as_slice(o: &Option<NonZero<u64>>) -> &[NonZero<u64>] {
// CHECK-NOT: select // CHECK-NOT: select
// CHECK-NOT: br // CHECK-NOT: br
// CHECK-NOT: switch // CHECK-NOT: switch

View File

@ -1,18 +1,18 @@
//@ compile-flags: -O -Zmerge-functions=disabled //@ compile-flags: -O -Zmerge-functions=disabled
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
extern crate core; extern crate core;
use core::cmp::Ordering; use core::cmp::Ordering;
use core::num::{NonZeroU32, NonZeroI64};
use core::ptr::NonNull; use core::ptr::NonNull;
use core::num::NonZero;
// See also tests/assembly/option-nonzero-eq.rs, for cases with `assume`s in the // See also tests/assembly/option-nonzero-eq.rs, for cases with `assume`s in the
// LLVM and thus don't optimize down clearly here, but do in assembly. // LLVM and thus don't optimize down clearly here, but do in assembly.
// CHECK-lABEL: @non_zero_eq // CHECK-lABEL: @non_zero_eq
#[no_mangle] #[no_mangle]
pub fn non_zero_eq(l: Option<NonZeroU32>, r: Option<NonZeroU32>) -> bool { pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool {
// CHECK: start: // CHECK: start:
// CHECK-NEXT: icmp eq i32 // CHECK-NEXT: icmp eq i32
// CHECK-NEXT: ret i1 // CHECK-NEXT: ret i1
@ -21,7 +21,7 @@ pub fn non_zero_eq(l: Option<NonZeroU32>, r: Option<NonZeroU32>) -> bool {
// CHECK-lABEL: @non_zero_signed_eq // CHECK-lABEL: @non_zero_signed_eq
#[no_mangle] #[no_mangle]
pub fn non_zero_signed_eq(l: Option<NonZeroI64>, r: Option<NonZeroI64>) -> bool { pub fn non_zero_signed_eq(l: Option<NonZero<i64>>, r: Option<NonZero<i64>>) -> bool {
// CHECK: start: // CHECK: start:
// CHECK-NEXT: icmp eq i64 // CHECK-NEXT: icmp eq i64
// CHECK-NEXT: ret i1 // CHECK-NEXT: ret i1

View File

@ -1,8 +1,8 @@
//@ compile-flags: -O -Zmerge-functions=disabled //@ compile-flags: -O -Zmerge-functions=disabled
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
use std::num::{NonZeroI16, NonZeroU32}; use std::num::NonZero;
// #71602 reported a simple array comparison just generating a loop. // #71602 reported a simple array comparison just generating a loop.
// This was originally fixed by ensuring it generates a single bcmp, // This was originally fixed by ensuring it generates a single bcmp,
@ -70,7 +70,7 @@ fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool {
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1 // CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
// CHECK-SAME: [[USIZE]] noundef %3 // CHECK-SAME: [[USIZE]] noundef %3
#[no_mangle] #[no_mangle]
fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool { fn eq_slice_of_nonzero(x: &[NonZero<i32>], y: &[NonZero<i32>]) -> bool {
// CHECK: icmp eq [[USIZE]] %1, %3 // CHECK: icmp eq [[USIZE]] %1, %3
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2 // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
@ -82,7 +82,7 @@ fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1 // CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
// CHECK-SAME: [[USIZE]] noundef %3 // CHECK-SAME: [[USIZE]] noundef %3
#[no_mangle] #[no_mangle]
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZeroI16>], y: &[Option<NonZeroI16>]) -> bool { fn eq_slice_of_option_of_nonzero(x: &[Option<NonZero<i16>>], y: &[Option<NonZero<i16>>]) -> bool {
// CHECK: icmp eq [[USIZE]] %1, %3 // CHECK: icmp eq [[USIZE]] %1, %3
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1 // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr

View File

@ -1,6 +1,6 @@
//@ compile-flags: -O -Z merge-functions=disabled //@ compile-flags: -O -Z merge-functions=disabled
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
// This tests that LLVM can optimize based on the niches in the source or // This tests that LLVM can optimize based on the niches in the source or
// destination types for transmutes. // destination types for transmutes.
@ -33,7 +33,7 @@ pub fn non_null_is_null(x: std::ptr::NonNull<i32>) -> bool {
// CHECK-LABEL: i1 @non_zero_is_null( // CHECK-LABEL: i1 @non_zero_is_null(
#[no_mangle] #[no_mangle]
pub fn non_zero_is_null(x: std::num::NonZeroUsize) -> bool { pub fn non_zero_is_null(x: std::num::NonZero<usize>) -> bool {
// CHECK: ret i1 false // CHECK: ret i1 false
let p: *const i32 = unsafe { std::mem::transmute(x) }; let p: *const i32 = unsafe { std::mem::transmute(x) };
p.is_null() p.is_null()
@ -72,7 +72,7 @@ pub fn normal_div(a: u32, b: u32) -> u32 {
// CHECK-LABEL: i32 @div_transmute_nonzero(i32 // CHECK-LABEL: i32 @div_transmute_nonzero(i32
#[no_mangle] #[no_mangle]
pub fn div_transmute_nonzero(a: u32, b: std::num::NonZeroI32) -> u32 { pub fn div_transmute_nonzero(a: u32, b: std::num::NonZero<i32>) -> u32 {
// CHECK-NOT: call core::panicking::panic // CHECK-NOT: call core::panicking::panic
// CHECK: %[[R:.+]] = udiv i32 %a, %b // CHECK: %[[R:.+]] = udiv i32 %a, %b
// CHECK-NEXT: ret i32 %[[R]] // CHECK-NEXT: ret i32 %[[R]]

View File

@ -1,143 +1,143 @@
//@ only-cdb //@ only-cdb
//@ compile-flags:-g //@ compile-flags:-g
//
// cdb-command: g // cdb-command: g
//
// cdb-command: dx a // cdb-command: dx a
// cdb-check:a : Some [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >] // cdb-check:a : Some [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
// cdb-check: [+0x000] __0 : Low (0x2) [Type: msvc_pretty_enums::CStyleEnum] // cdb-check: [+0x000] __0 : Low (0x2) [Type: msvc_pretty_enums::CStyleEnum]
//
// cdb-command: dx b // cdb-command: dx b
// cdb-check:b : None [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >] // cdb-check:b : None [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
//
// cdb-command: dx c // cdb-command: dx c
// cdb-check:c : Tag1 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>] // cdb-check:c : Tag1 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
//
// cdb-command: dx d // cdb-command: dx d
// cdb-check:d : Data [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>] // cdb-check:d : Data [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
// cdb-check: [+0x000] my_data : High (0x10) [Type: msvc_pretty_enums::CStyleEnum] // cdb-check: [+0x000] my_data : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
//
// cdb-command: dx e // cdb-command: dx e
// cdb-check:e : Tag2 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>] // cdb-check:e : Tag2 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
//
// cdb-command: dx f // cdb-command: dx f
// cdb-check:f : Some [Type: enum2$<core::option::Option<ref$<u32> > >] // cdb-check:f : Some [Type: enum2$<core::option::Option<ref$<u32> > >]
// cdb-check: [+0x000] __0 : 0x[...] : 0x1 [Type: unsigned int *] // cdb-check: [+0x000] __0 : 0x[...] : 0x1 [Type: unsigned int *]
//
// cdb-command: dx g // cdb-command: dx g
// cdb-check:g : None [Type: enum2$<core::option::Option<ref$<u32> > >] // cdb-check:g : None [Type: enum2$<core::option::Option<ref$<u32> > >]
//
// cdb-command: dx h // cdb-command: dx h
// cdb-check:h : Some [Type: enum2$<core::option::Option<u32> >] // cdb-check:h : Some [Type: enum2$<core::option::Option<u32> >]
// cdb-check: [+0x004] __0 : 0xc [Type: unsigned int] // cdb-check: [+0x004] __0 : 0xc [Type: unsigned int]
//
// cdb-command: dx i // cdb-command: dx i
// cdb-check:i : None [Type: enum2$<core::option::Option<u32> >] // cdb-check:i : None [Type: enum2$<core::option::Option<u32> >]
//
// cdb-command: dx j // cdb-command: dx j
// cdb-check:j : High (0x10) [Type: msvc_pretty_enums::CStyleEnum] // cdb-check:j : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
//
// cdb-command: dx k // cdb-command: dx k
// cdb-check:k : Some [Type: enum2$<core::option::Option<alloc::string::String> >] // cdb-check:k : Some [Type: enum2$<core::option::Option<alloc::string::String> >]
// cdb-check: [+0x000] __0 : "IAMA optional string!" [Type: alloc::string::String] // cdb-check: [+0x000] __0 : "IAMA optional string!" [Type: alloc::string::String]
//
// cdb-command: dx l // cdb-command: dx l
// cdb-check:l : Ok [Type: enum2$<core::result::Result<u32,enum2$<msvc_pretty_enums::Empty> > >] // cdb-check:l : Ok [Type: enum2$<core::result::Result<u32,enum2$<msvc_pretty_enums::Empty> > >]
// cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int] // cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int]
//
// cdb-command: dx niche128_some // cdb-command: dx niche128_some
// cdb-check: niche128_some : Some [Type: enum2$<core::option::Option<core::num::nonzero::NonZero<i128> > >] // cdb-check: niche128_some : Some [Type: enum2$<core::option::Option<core::num::nonzero::NonZero<i128> > >]
// Note: we can't actually read the value of the field because CDB cannot handle 128 bit integers. // Note: we can't actually read the value of the field because CDB cannot handle 128 bit integers.
// cdb-check: [+0x000] __0 [...] [Type: core::num::nonzero::NonZero<i128>] // cdb-check: [+0x000] __0 [...] [Type: core::num::nonzero::NonZero<i128>]
//
// cdb-command: dx niche128_none // cdb-command: dx niche128_none
// cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZero<i128> > >] // cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZero<i128> > >]
//
// cdb-command: dx wrapping_niche128_untagged // cdb-command: dx wrapping_niche128_untagged
// cdb-check: wrapping_niche128_untagged : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>] // cdb-check: wrapping_niche128_untagged : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
// cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128] // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
//
// cdb-command: dx wrapping_niche128_none1 // cdb-command: dx wrapping_niche128_none1
// cdb-check: wrapping_niche128_none1 : Y [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>] // cdb-check: wrapping_niche128_none1 : Y [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
// cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128] // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
//
// cdb-command: dx wrapping_niche128_none2 // cdb-command: dx wrapping_niche128_none2
// cdb-check: wrapping_niche128_none2 : Z [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>] // cdb-check: wrapping_niche128_none2 : Z [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
// cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128] // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
//
// cdb-command: dx direct_tag_128_a,d // cdb-command: dx direct_tag_128_a,d
// cdb-check: direct_tag_128_a,d : A [Type: enum2$<msvc_pretty_enums::DirectTag128>] // cdb-check: direct_tag_128_a,d : A [Type: enum2$<msvc_pretty_enums::DirectTag128>]
// cdb-check: [+0x[...]] __0 : 42 [Type: unsigned int] // cdb-check: [+0x[...]] __0 : 42 [Type: unsigned int]
//
// cdb-command: dx direct_tag_128_b,d // cdb-command: dx direct_tag_128_b,d
// cdb-check: direct_tag_128_b,d : B [Type: enum2$<msvc_pretty_enums::DirectTag128>] // cdb-check: direct_tag_128_b,d : B [Type: enum2$<msvc_pretty_enums::DirectTag128>]
// cdb-check: [+0x[...]] __0 : 137 [Type: unsigned int] // cdb-check: [+0x[...]] __0 : 137 [Type: unsigned int]
//
// cdb-command: dx niche_w_fields_1_some,d // cdb-command: dx niche_w_fields_1_some,d
// cdb-check: niche_w_fields_1_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>] // cdb-check: niche_w_fields_1_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>]
// cdb-check: [+0x[...]] __0 : 0x[...] : 77 [Type: unsigned char *] // cdb-check: [+0x[...]] __0 : 0x[...] : 77 [Type: unsigned char *]
// cdb-check: [+0x[...]] __1 : 7 [Type: unsigned int] // cdb-check: [+0x[...]] __1 : 7 [Type: unsigned int]
//
// cdb-command: dx niche_w_fields_1_none,d // cdb-command: dx niche_w_fields_1_none,d
// cdb-check: niche_w_fields_1_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>] // cdb-check: niche_w_fields_1_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>]
// cdb-check: [+0x[...]] __0 : 99 [Type: unsigned int] // cdb-check: [+0x[...]] __0 : 99 [Type: unsigned int]
//
// cdb-command: dx niche_w_fields_2_some,d // cdb-command: dx niche_w_fields_2_some,d
// cdb-check: niche_w_fields_2_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>] // cdb-check: niche_w_fields_2_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
// cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZero<u32>] // cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZero<u32>]
// cdb-check: [+0x[...]] __1 : 900 [Type: unsigned __int64] // cdb-check: [+0x[...]] __1 : 900 [Type: unsigned __int64]
//
// cdb-command: dx niche_w_fields_2_none,d // cdb-command: dx niche_w_fields_2_none,d
// cdb-check: niche_w_fields_2_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>] // cdb-check: niche_w_fields_2_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
// cdb-check: [+0x[...]] __0 : 1000 [Type: unsigned __int64] // cdb-check: [+0x[...]] __0 : 1000 [Type: unsigned __int64]
//
// cdb-command: dx niche_w_fields_3_some,d // cdb-command: dx niche_w_fields_3_some,d
// cdb-check: niche_w_fields_3_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>] // cdb-check: niche_w_fields_3_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
// cdb-check: [+0x[...]] __0 : 137 [Type: unsigned char] // cdb-check: [+0x[...]] __0 : 137 [Type: unsigned char]
// cdb-check: [+0x[...]] __1 : true [Type: bool] // cdb-check: [+0x[...]] __1 : true [Type: bool]
//
// cdb-command: dx niche_w_fields_3_niche1,d // cdb-command: dx niche_w_fields_3_niche1,d
// cdb-check: niche_w_fields_3_niche1,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>] // cdb-check: niche_w_fields_3_niche1,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
// cdb-check: [+0x[...]] __0 : 12 [Type: unsigned char] // cdb-check: [+0x[...]] __0 : 12 [Type: unsigned char]
//
// cdb-command: dx niche_w_fields_3_niche2,d // cdb-command: dx niche_w_fields_3_niche2,d
// cdb-check: niche_w_fields_3_niche2,d : C [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>] // cdb-check: niche_w_fields_3_niche2,d : C [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
// cdb-check: [+0x[...]] __0 : false [Type: bool] // cdb-check: [+0x[...]] __0 : false [Type: bool]
//
// cdb-command: dx niche_w_fields_3_niche3,d // cdb-command: dx niche_w_fields_3_niche3,d
// cdb-check: niche_w_fields_3_niche3,d : D [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>] // cdb-check: niche_w_fields_3_niche3,d : D [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
// cdb-check: [+0x[...]] __0 : 34 [Type: unsigned char] // cdb-check: [+0x[...]] __0 : 34 [Type: unsigned char]
//
// cdb-command: dx niche_w_fields_3_niche4,d // cdb-command: dx niche_w_fields_3_niche4,d
// cdb-check: niche_w_fields_3_niche4,d : E [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>] // cdb-check: niche_w_fields_3_niche4,d : E [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
// cdb-check: [+0x[...]] __0 : 56 [Type: unsigned char] // cdb-check: [+0x[...]] __0 : 56 [Type: unsigned char]
//
// cdb-command: dx niche_w_fields_3_niche5,d // cdb-command: dx niche_w_fields_3_niche5,d
// cdb-check: niche_w_fields_3_niche5,d : F [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>] // cdb-check: niche_w_fields_3_niche5,d : F [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
//
// cdb-command: dx -r3 niche_w_fields_std_result_ok,d // cdb-command: dx -r3 niche_w_fields_std_result_ok,d
// cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$<core::result::Result<alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>,u64> >] // cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$<core::result::Result<alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>,u64> >]
// cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>] // cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>]
// cdb-check: [+0x[...]] data_ptr : [...] // cdb-check: [+0x[...]] data_ptr : [...]
// cdb-check: [+0x[...]] length : 3 [...] // cdb-check: [+0x[...]] length : 3 [...]
//
// cdb-command: dx -r3 niche_w_fields_std_result_err,d // cdb-command: dx -r3 niche_w_fields_std_result_err,d
// cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$<core::result::Result<alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>,u64> >] // cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$<core::result::Result<alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>,u64> >]
// cdb-check: [+0x[...]] __0 : 789 [Type: unsigned __int64] // cdb-check: [+0x[...]] __0 : 789 [Type: unsigned __int64]
//
// cdb-command: dx -r2 arbitrary_discr1,d // cdb-command: dx -r2 arbitrary_discr1,d
// cdb-check: arbitrary_discr1,d : Abc [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>] // cdb-check: arbitrary_discr1,d : Abc [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>]
// cdb-check: [+0x[...]] __0 : 1234 [Type: unsigned int] // cdb-check: [+0x[...]] __0 : 1234 [Type: unsigned int]
//
// cdb-command: dx -r2 arbitrary_discr2,d // cdb-command: dx -r2 arbitrary_discr2,d
// cdb-check: arbitrary_discr2,d : Def [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>] // cdb-check: arbitrary_discr2,d : Def [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>]
// cdb-check: [+0x[...]] __0 : 5678 [Type: unsigned int] // cdb-check: [+0x[...]] __0 : 5678 [Type: unsigned int]
#![feature(generic_nonzero)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(repr128)] #![feature(repr128)]
#![feature(arbitrary_enum_discriminant)] #![feature(arbitrary_enum_discriminant)]
use std::num::{NonZeroI128, NonZeroU32}; use std::num::NonZero;
pub enum CStyleEnum { pub enum CStyleEnum {
Low = 2, Low = 2,
@ -160,7 +160,7 @@ enum NicheLayoutWithFields1<'a> {
} }
enum NicheLayoutWithFields2 { enum NicheLayoutWithFields2 {
A(NonZeroU32, u64), A(NonZero<u32>, u64),
B(u64), B(u64),
} }
@ -210,8 +210,8 @@ fn main() {
let j = CStyleEnum::High; let j = CStyleEnum::High;
let k = Some("IAMA optional string!".to_string()); let k = Some("IAMA optional string!".to_string());
let l = Result::<u32, Empty>::Ok(42); let l = Result::<u32, Empty>::Ok(42);
let niche128_some = Some(NonZeroI128::new(123456).unwrap()); let niche128_some = NonZero::new(123456i128);
let niche128_none: Option<NonZeroI128> = None; let niche128_none: Option<NonZero<i128>> = None;
let wrapping_niche128_untagged = let wrapping_niche128_untagged =
unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) }; unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) };
@ -224,7 +224,7 @@ fn main() {
let niche_w_fields_1_some = NicheLayoutWithFields1::A(&77, 7); let niche_w_fields_1_some = NicheLayoutWithFields1::A(&77, 7);
let niche_w_fields_1_none = NicheLayoutWithFields1::B(99); let niche_w_fields_1_none = NicheLayoutWithFields1::B(99);
let niche_w_fields_2_some = NicheLayoutWithFields2::A(NonZeroU32::new(800).unwrap(), 900); let niche_w_fields_2_some = NicheLayoutWithFields2::A(NonZero::new(800).unwrap(), 900);
let niche_w_fields_2_none = NicheLayoutWithFields2::B(1000); let niche_w_fields_2_none = NicheLayoutWithFields2::B(1000);
let niche_w_fields_3_some = NicheLayoutWithFields3::A(137, true); let niche_w_fields_3_some = NicheLayoutWithFields3::A(137, true);

View File

@ -237,25 +237,25 @@
// lldb-command:print nz_usize // lldb-command:print nz_usize
// lldb-check:[...]$11 = 122 { __0 = 122 } // lldb-check:[...]$11 = 122 { __0 = 122 }
#![feature(generic_nonzero)]
use std::num::*; use std::num::*;
use std::sync::atomic::*; use std::sync::atomic::*;
fn main() { fn main() {
let nz_i8 = NonZeroI8::new(11).unwrap(); let nz_i8 = NonZero::new(11i8).unwrap();
let nz_i16 = NonZeroI16::new(22).unwrap(); let nz_i16 = NonZero::new(22i16).unwrap();
let nz_i32 = NonZeroI32::new(33).unwrap(); let nz_i32 = NonZero::new(33i32).unwrap();
let nz_i64 = NonZeroI64::new(44).unwrap(); let nz_i64 = NonZero::new(44i64).unwrap();
let nz_i128 = NonZeroI128::new(55).unwrap(); let nz_i128 = NonZero::new(55i128).unwrap();
let nz_isize = NonZeroIsize::new(66).unwrap(); let nz_isize = NonZero::new(66isize).unwrap();
let nz_u8 = NonZeroU8::new(77).unwrap(); let nz_u8 = NonZero::new(77u8).unwrap();
let nz_u16 = NonZeroU16::new(88).unwrap(); let nz_u16 = NonZero::new(88u16).unwrap();
let nz_u32 = NonZeroU32::new(99).unwrap(); let nz_u32 = NonZero::new(99u32).unwrap();
let nz_u64 = NonZeroU64::new(100).unwrap(); let nz_u64 = NonZero::new(100u64).unwrap();
let nz_u128 = NonZeroU128::new(111).unwrap(); let nz_u128 = NonZero::new(111u128).unwrap();
let nz_usize = NonZeroUsize::new(122).unwrap(); let nz_usize = NonZero::new(122usize).unwrap();
let w_i8 = Wrapping(10i8); let w_i8 = Wrapping(10i8);
let w_i16 = Wrapping(20i16); let w_i16 = Wrapping(20i16);

View File

@ -1,9 +1,9 @@
//@ unit-test: InstSimplify //@ unit-test: InstSimplify
//@ compile-flags: -C panic=abort //@ compile-flags: -C panic=abort
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(custom_mir)] #![feature(custom_mir)]
#![feature(generic_nonzero)]
use std::intrinsics::mir::*; use std::intrinsics::mir::*;
use std::mem::{MaybeUninit, ManuallyDrop, transmute}; use std::mem::{MaybeUninit, ManuallyDrop, transmute};
@ -54,7 +54,7 @@ pub unsafe fn adt_transmutes() {
// CHECK: as i32 (Transmute); // CHECK: as i32 (Transmute);
// CHECK: ({{_.*}}.1: std::mem::ManuallyDrop<std::string::String>); // CHECK: ({{_.*}}.1: std::mem::ManuallyDrop<std::string::String>);
let _a: u8 = transmute(Some(std::num::NonZeroU8::MAX)); let _a: u8 = transmute(Some(std::num::NonZero::<u8>::MAX));
let _a: i16 = transmute(std::num::Wrapping(0_i16)); let _a: i16 = transmute(std::num::Wrapping(0_i16));
let _a: u16 = transmute(std::num::Wrapping(0_i16)); let _a: u16 = transmute(std::num::Wrapping(0_i16));
let _a: u32 = transmute(Union32 { i32: 0 }); let _a: u32 = transmute(Union32 { i32: 0 });

View File

@ -81,7 +81,7 @@ pub enum Variants {
// @hasraw - '<code>Some</code>: 4 bytes' // @hasraw - '<code>Some</code>: 4 bytes'
pub enum WithNiche { pub enum WithNiche {
None, None,
Some(std::num::NonZeroU32), Some(std::num::NonZero<u32>),
} }
// @hasraw type_layout/enum.Uninhabited.html 'Size: ' // @hasraw type_layout/enum.Uninhabited.html 'Size: '

View File

@ -64,6 +64,7 @@
[csky] needs-llvm-components: csky [csky] needs-llvm-components: csky
*/ */
#![feature(rustc_attrs, unsized_fn_params, transparent_unions)] #![feature(rustc_attrs, unsized_fn_params, transparent_unions)]
#![cfg_attr(host, feature(generic_nonzero))]
#![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)] #![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)]
#![allow(unused, improper_ctypes_definitions, internal_features)] #![allow(unused, improper_ctypes_definitions, internal_features)]
@ -74,7 +75,7 @@
#[cfg(host)] #[cfg(host)]
use std::{ use std::{
any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZeroI32, ptr::NonNull, rc::Rc, any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZero, ptr::NonNull, rc::Rc,
sync::Arc, sync::Arc,
}; };
@ -145,7 +146,7 @@ mod prelude {
#[repr(transparent)] #[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)] #[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed] #[rustc_nonnull_optimization_guaranteed]
pub struct NonZeroI32(i32); pub struct NonZero<T>(T);
// This just stands in for a non-trivial type. // This just stands in for a non-trivial type.
pub struct Vec<T> { pub struct Vec<T> {
@ -274,7 +275,7 @@ test_abi_compatible!(isize_int, isize, i64);
test_abi_compatible!(zst_unit, Zst, ()); test_abi_compatible!(zst_unit, Zst, ());
#[cfg(not(any(target_arch = "sparc64")))] #[cfg(not(any(target_arch = "sparc64")))]
test_abi_compatible!(zst_array, Zst, [u8; 0]); test_abi_compatible!(zst_array, Zst, [u8; 0]);
test_abi_compatible!(nonzero_int, NonZeroI32, i32); test_abi_compatible!(nonzero_int, NonZero<i32>, i32);
// `DispatchFromDyn` relies on ABI compatibility. // `DispatchFromDyn` relies on ABI compatibility.
// This is interesting since these types are not `repr(transparent)`. So this is not part of our // This is interesting since these types are not `repr(transparent)`. So this is not part of our
@ -381,6 +382,6 @@ test_nonnull!(mut_unsized, &mut [i32]);
test_nonnull!(fn_, fn()); test_nonnull!(fn_, fn());
test_nonnull!(nonnull, NonNull<i32>); test_nonnull!(nonnull, NonNull<i32>);
test_nonnull!(nonnull_unsized, NonNull<dyn Any>); test_nonnull!(nonnull_unsized, NonNull<dyn Any>);
test_nonnull!(non_zero, NonZeroI32); test_nonnull!(non_zero, NonZero<i32>);
fn main() {} fn main() {}

View File

@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:22:1 --> $DIR/raw-bytes.rs:21:1
| |
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x00000001, but expected a valid enum tag | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x00000001, but expected a valid enum tag
@ -10,7 +10,7 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:30:1 --> $DIR/raw-bytes.rs:29:1
| |
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x00000000, but expected a valid enum tag | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x00000000, but expected a valid enum tag
@ -21,7 +21,7 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:44:1 --> $DIR/raw-bytes.rs:43:1
| |
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
@ -32,7 +32,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:46:1 --> $DIR/raw-bytes.rs:45:1
| |
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
@ -43,7 +43,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:52:1 --> $DIR/raw-bytes.rs:51:1
| |
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) })); LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
@ -54,7 +54,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:57:1 --> $DIR/raw-bytes.rs:56:1
| |
LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) }; LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@ -65,10 +65,10 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:60:1 --> $DIR/raw-bytes.rs:59:1
| |
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
| |
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: 1, align: 1) { = note: the raw bytes of the constant (size: 1, align: 1) {
@ -76,10 +76,10 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:62:1 --> $DIR/raw-bytes.rs:61:1
| |
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
| |
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: 4, align: 4) { = note: the raw bytes of the constant (size: 4, align: 4) {
@ -87,7 +87,7 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:68:1 --> $DIR/raw-bytes.rs:67:1
| |
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 42, but expected something in the range 10..=30 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 42, but expected something in the range 10..=30
@ -98,7 +98,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:74:1 --> $DIR/raw-bytes.rs:73:1
| |
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30
@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:77:1 --> $DIR/raw-bytes.rs:76:1
| |
LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe { LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:85:1 --> $DIR/raw-bytes.rs:84:1
| |
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
@ -131,7 +131,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:89:1 --> $DIR/raw-bytes.rs:88:1
| |
LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1)
@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:93:1 --> $DIR/raw-bytes.rs:92:1
| |
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
@ -153,7 +153,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:96:1 --> $DIR/raw-bytes.rs:95:1
| |
LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box
@ -164,7 +164,7 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:99:1 --> $DIR/raw-bytes.rs:98:1
| |
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance)
@ -175,7 +175,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:102:1 --> $DIR/raw-bytes.rs:101:1
| |
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance)
@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:105:1 --> $DIR/raw-bytes.rs:104:1
| |
LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
@ -197,7 +197,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:107:1 --> $DIR/raw-bytes.rs:106:1
| |
LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
@ -208,7 +208,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:109:1 --> $DIR/raw-bytes.rs:108:1
| |
LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC3<imm>, but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC3<imm>, but expected a function pointer
@ -219,7 +219,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:115:1 --> $DIR/raw-bytes.rs:114:1
| |
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar
@ -230,7 +230,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:140:1 --> $DIR/raw-bytes.rs:139:1
| |
LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@ -241,7 +241,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:142:1 --> $DIR/raw-bytes.rs:141:1
| |
LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object
@ -252,7 +252,7 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:144:1 --> $DIR/raw-bytes.rs:143:1
| |
LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@ -263,7 +263,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize:
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:147:1 --> $DIR/raw-bytes.rs:146:1
| |
LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected a string | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected a string
@ -274,7 +274,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:149:1 --> $DIR/raw-bytes.rs:148:1
| |
LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized memory, but expected a string | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized memory, but expected a string
@ -285,7 +285,7 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:151:1 --> $DIR/raw-bytes.rs:150:1
| |
LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered a pointer, but expected a string | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered a pointer, but expected a string
@ -298,7 +298,7 @@ LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:155:1 --> $DIR/raw-bytes.rs:154:1
| |
LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@ -309,7 +309,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:157:1 --> $DIR/raw-bytes.rs:156:1
| |
LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@ -320,7 +320,7 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:160:1 --> $DIR/raw-bytes.rs:159:1
| |
LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation)
@ -331,7 +331,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:163:1 --> $DIR/raw-bytes.rs:162:1
| |
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
@ -342,13 +342,13 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
} }
note: erroneous constant encountered note: erroneous constant encountered
--> $DIR/raw-bytes.rs:163:40 --> $DIR/raw-bytes.rs:162:40
| |
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:169:1 --> $DIR/raw-bytes.rs:168:1
| |
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
@ -359,13 +359,13 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3
} }
note: erroneous constant encountered note: erroneous constant encountered
--> $DIR/raw-bytes.rs:169:42 --> $DIR/raw-bytes.rs:168:42
| |
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:173:1 --> $DIR/raw-bytes.rs:172:1
| |
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean
@ -376,13 +376,13 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran
} }
note: erroneous constant encountered note: erroneous constant encountered
--> $DIR/raw-bytes.rs:173:42 --> $DIR/raw-bytes.rs:172:42
| |
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:178:1 --> $DIR/raw-bytes.rs:177:1
| |
LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC17<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC17<imm>, but expected a vtable pointer
@ -393,7 +393,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:182:1 --> $DIR/raw-bytes.rs:181:1
| |
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC19<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC19<imm>, but expected a vtable pointer
@ -404,7 +404,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:186:1 --> $DIR/raw-bytes.rs:185:1
| |
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
@ -415,7 +415,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:189:1 --> $DIR/raw-bytes.rs:188:1
| |
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC22<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC22<imm>, but expected a vtable pointer
@ -426,7 +426,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:193:1 --> $DIR/raw-bytes.rs:192:1
| |
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
@ -437,7 +437,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_,
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:197:1 --> $DIR/raw-bytes.rs:196:1
| |
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
@ -448,7 +448,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:199:1 --> $DIR/raw-bytes.rs:198:1
| |
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC27<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC27<imm>, but expected a vtable pointer
@ -459,7 +459,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:203:1 --> $DIR/raw-bytes.rs:202:1
| |
LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) };
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type [!; 1] | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type [!; 1]
@ -470,7 +470,7 @@ LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:204:1 --> $DIR/raw-bytes.rs:203:1
| |
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) };
| ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!` | ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!`
@ -481,7 +481,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:205:1 --> $DIR/raw-bytes.rs:204:1
| |
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) };
| ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!` | ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!`
@ -492,7 +492,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:209:1 --> $DIR/raw-bytes.rs:208:1
| |
LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
@ -503,7 +503,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:212:1 --> $DIR/raw-bytes.rs:211:1
| |
LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) }; LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
@ -516,7 +516,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem:
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:215:1 --> $DIR/raw-bytes.rs:214:1
| |
LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
@ -527,7 +527,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4)
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:219:1 --> $DIR/raw-bytes.rs:218:1
| |
LL | pub static S7: &[u16] = unsafe { LL | pub static S7: &[u16] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized memory, but expected an integer | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized memory, but expected an integer
@ -538,7 +538,7 @@ LL | pub static S7: &[u16] = unsafe {
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:226:1 --> $DIR/raw-bytes.rs:225:1
| |
LL | pub static R4: &[u8] = unsafe { LL | pub static R4: &[u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
@ -549,7 +549,7 @@ LL | pub static R4: &[u8] = unsafe {
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:231:1 --> $DIR/raw-bytes.rs:230:1
| |
LL | pub static R5: &[u8] = unsafe { LL | pub static R5: &[u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
@ -562,7 +562,7 @@ LL | pub static R5: &[u8] = unsafe {
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:236:1 --> $DIR/raw-bytes.rs:235:1
| |
LL | pub static R6: &[bool] = unsafe { LL | pub static R6: &[bool] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean

View File

@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:22:1 --> $DIR/raw-bytes.rs:21:1
| |
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000001, but expected a valid enum tag | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000001, but expected a valid enum tag
@ -10,7 +10,7 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:30:1 --> $DIR/raw-bytes.rs:29:1
| |
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000000, but expected a valid enum tag | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000000, but expected a valid enum tag
@ -21,7 +21,7 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:44:1 --> $DIR/raw-bytes.rs:43:1
| |
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
@ -32,7 +32,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:46:1 --> $DIR/raw-bytes.rs:45:1
| |
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
@ -43,7 +43,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:52:1 --> $DIR/raw-bytes.rs:51:1
| |
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) })); LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
@ -54,7 +54,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:57:1 --> $DIR/raw-bytes.rs:56:1
| |
LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) }; LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@ -65,10 +65,10 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:60:1 --> $DIR/raw-bytes.rs:59:1
| |
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
| |
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: 1, align: 1) { = note: the raw bytes of the constant (size: 1, align: 1) {
@ -76,10 +76,10 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:62:1 --> $DIR/raw-bytes.rs:61:1
| |
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
| |
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: 8, align: 8) { = note: the raw bytes of the constant (size: 8, align: 8) {
@ -87,7 +87,7 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:68:1 --> $DIR/raw-bytes.rs:67:1
| |
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 42, but expected something in the range 10..=30 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 42, but expected something in the range 10..=30
@ -98,7 +98,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:74:1 --> $DIR/raw-bytes.rs:73:1
| |
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30
@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:77:1 --> $DIR/raw-bytes.rs:76:1
| |
LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe { LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:85:1 --> $DIR/raw-bytes.rs:84:1
| |
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
@ -131,7 +131,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:89:1 --> $DIR/raw-bytes.rs:88:1
| |
LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1)
@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:93:1 --> $DIR/raw-bytes.rs:92:1
| |
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
@ -153,7 +153,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:96:1 --> $DIR/raw-bytes.rs:95:1
| |
LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box
@ -164,7 +164,7 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:99:1 --> $DIR/raw-bytes.rs:98:1
| |
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance)
@ -175,7 +175,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:102:1 --> $DIR/raw-bytes.rs:101:1
| |
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance)
@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:105:1 --> $DIR/raw-bytes.rs:104:1
| |
LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
@ -197,7 +197,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:107:1 --> $DIR/raw-bytes.rs:106:1
| |
LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
@ -208,7 +208,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:109:1 --> $DIR/raw-bytes.rs:108:1
| |
LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC3<imm>, but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC3<imm>, but expected a function pointer
@ -219,7 +219,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:115:1 --> $DIR/raw-bytes.rs:114:1
| |
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar
@ -230,7 +230,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:140:1 --> $DIR/raw-bytes.rs:139:1
| |
LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@ -241,7 +241,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:142:1 --> $DIR/raw-bytes.rs:141:1
| |
LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object
@ -252,7 +252,7 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:144:1 --> $DIR/raw-bytes.rs:143:1
| |
LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@ -263,7 +263,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize:
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:147:1 --> $DIR/raw-bytes.rs:146:1
| |
LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected a string | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected a string
@ -274,7 +274,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:149:1 --> $DIR/raw-bytes.rs:148:1
| |
LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) }; LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized memory, but expected a string | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized memory, but expected a string
@ -285,7 +285,7 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:151:1 --> $DIR/raw-bytes.rs:150:1
| |
LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered a pointer, but expected a string | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered a pointer, but expected a string
@ -298,7 +298,7 @@ LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:155:1 --> $DIR/raw-bytes.rs:154:1
| |
LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@ -309,7 +309,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:157:1 --> $DIR/raw-bytes.rs:156:1
| |
LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@ -320,7 +320,7 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:160:1 --> $DIR/raw-bytes.rs:159:1
| |
LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation)
@ -331,7 +331,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:163:1 --> $DIR/raw-bytes.rs:162:1
| |
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
@ -342,13 +342,13 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
} }
note: erroneous constant encountered note: erroneous constant encountered
--> $DIR/raw-bytes.rs:163:40 --> $DIR/raw-bytes.rs:162:40
| |
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:169:1 --> $DIR/raw-bytes.rs:168:1
| |
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
@ -359,13 +359,13 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3
} }
note: erroneous constant encountered note: erroneous constant encountered
--> $DIR/raw-bytes.rs:169:42 --> $DIR/raw-bytes.rs:168:42
| |
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:173:1 --> $DIR/raw-bytes.rs:172:1
| |
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean
@ -376,13 +376,13 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran
} }
note: erroneous constant encountered note: erroneous constant encountered
--> $DIR/raw-bytes.rs:173:42 --> $DIR/raw-bytes.rs:172:42
| |
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:178:1 --> $DIR/raw-bytes.rs:177:1
| |
LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC17<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC17<imm>, but expected a vtable pointer
@ -393,7 +393,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:182:1 --> $DIR/raw-bytes.rs:181:1
| |
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC19<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC19<imm>, but expected a vtable pointer
@ -404,7 +404,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:186:1 --> $DIR/raw-bytes.rs:185:1
| |
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
@ -415,7 +415,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:189:1 --> $DIR/raw-bytes.rs:188:1
| |
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC22<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC22<imm>, but expected a vtable pointer
@ -426,7 +426,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:193:1 --> $DIR/raw-bytes.rs:192:1
| |
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
@ -437,7 +437,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_,
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:197:1 --> $DIR/raw-bytes.rs:196:1
| |
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
@ -448,7 +448,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:199:1 --> $DIR/raw-bytes.rs:198:1
| |
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC27<imm>, but expected a vtable pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC27<imm>, but expected a vtable pointer
@ -459,7 +459,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:203:1 --> $DIR/raw-bytes.rs:202:1
| |
LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) };
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type [!; 1] | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type [!; 1]
@ -470,7 +470,7 @@ LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:204:1 --> $DIR/raw-bytes.rs:203:1
| |
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) };
| ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!` | ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!`
@ -481,7 +481,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:205:1 --> $DIR/raw-bytes.rs:204:1
| |
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) };
| ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!` | ^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a value of the never type `!`
@ -492,7 +492,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:209:1 --> $DIR/raw-bytes.rs:208:1
| |
LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
@ -503,7 +503,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:212:1 --> $DIR/raw-bytes.rs:211:1
| |
LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) }; LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
@ -516,7 +516,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem:
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:215:1 --> $DIR/raw-bytes.rs:214:1
| |
LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
@ -527,7 +527,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4)
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:219:1 --> $DIR/raw-bytes.rs:218:1
| |
LL | pub static S7: &[u16] = unsafe { LL | pub static S7: &[u16] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized memory, but expected an integer | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized memory, but expected an integer
@ -538,7 +538,7 @@ LL | pub static S7: &[u16] = unsafe {
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:226:1 --> $DIR/raw-bytes.rs:225:1
| |
LL | pub static R4: &[u8] = unsafe { LL | pub static R4: &[u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
@ -549,7 +549,7 @@ LL | pub static R4: &[u8] = unsafe {
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:231:1 --> $DIR/raw-bytes.rs:230:1
| |
LL | pub static R5: &[u8] = unsafe { LL | pub static R5: &[u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
@ -562,7 +562,7 @@ LL | pub static R5: &[u8] = unsafe {
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/raw-bytes.rs:236:1 --> $DIR/raw-bytes.rs:235:1
| |
LL | pub static R6: &[bool] = unsafe { LL | pub static R6: &[bool] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean

View File

@ -2,14 +2,13 @@
//@ ignore-endian-big //@ ignore-endian-big
// ignore-tidy-linelength // ignore-tidy-linelength
//@ normalize-stderr-test "╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼" -> "╾ALLOC_ID$1╼" //@ normalize-stderr-test "╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼" -> "╾ALLOC_ID$1╼"
#![feature(never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range)]
#![allow(invalid_value)] #![allow(invalid_value)]
#![feature(generic_nonzero, never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range)]
use std::mem; use std::mem;
use std::alloc::Layout; use std::alloc::Layout;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::num::{NonZeroU8, NonZeroUsize}; use std::num::NonZero;
use std::slice::{from_ptr_range, from_raw_parts}; use std::slice::{from_ptr_range, from_raw_parts};
// # Bad enums and chars // # Bad enums and chars
@ -57,9 +56,9 @@ const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute
const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) }; const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
//~^ ERROR it is undefined behavior to use this value //~^ ERROR it is undefined behavior to use this value
const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
//~^ ERROR it is undefined behavior to use this value //~^ ERROR it is undefined behavior to use this value
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
//~^ ERROR it is undefined behavior to use this value //~^ ERROR it is undefined behavior to use this value
#[rustc_layout_scalar_valid_range_start(10)] #[rustc_layout_scalar_valid_range_start(10)]

View File

@ -1,12 +1,12 @@
// Strip out raw byte dumps to make comparison platform-independent: // Strip out raw byte dumps to make comparison platform-independent:
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" //@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP" //@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP"
#![feature(rustc_attrs, ptr_metadata)]
#![allow(invalid_value)] // make sure we cannot allow away the errors tested here #![allow(invalid_value)] // make sure we cannot allow away the errors tested here
#![feature(generic_nonzero, rustc_attrs, ptr_metadata)]
use std::mem; use std::mem;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::num::{NonZeroU8, NonZeroUsize}; use std::num::NonZero;
const NON_NULL: NonNull<u8> = unsafe { mem::transmute(1usize) }; const NON_NULL: NonNull<u8> = unsafe { mem::transmute(1usize) };
const NON_NULL_PTR: NonNull<u8> = unsafe { mem::transmute(&1) }; const NON_NULL_PTR: NonNull<u8> = unsafe { mem::transmute(&1) };
@ -21,9 +21,9 @@ const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
mem::transmute(out_of_bounds_ptr) mem::transmute(out_of_bounds_ptr)
} }; } };
const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
//~^ ERROR it is undefined behavior to use this value //~^ ERROR it is undefined behavior to use this value
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
//~^ ERROR it is undefined behavior to use this value //~^ ERROR it is undefined behavior to use this value
#[repr(C)] #[repr(C)]
@ -31,7 +31,7 @@ union MaybeUninit<T: Copy> {
uninit: (), uninit: (),
init: T, init: T,
} }
const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init }; const UNINIT: NonZero<u8> = unsafe { MaybeUninit { uninit: () }.init };
//~^ ERROR evaluation of constant value failed //~^ ERROR evaluation of constant value failed
//~| uninitialized //~| uninitialized

View File

@ -18,8 +18,8 @@ LL | let out_of_bounds_ptr = &ptr[255];
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:24:1 --> $DIR/ub-nonnull.rs:24:1
| |
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
| |
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
@ -29,8 +29,8 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:26:1 --> $DIR/ub-nonnull.rs:26:1
| |
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
| |
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
@ -38,9 +38,9 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
} }
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/ub-nonnull.rs:34:36 --> $DIR/ub-nonnull.rs:34:38
| |
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init }; LL | const UNINIT: NonZero<u8> = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value

View File

@ -1,16 +1,17 @@
//@ check-pass //@ check-pass
//
// Some constants that *are* valid // Some constants that *are* valid
#![feature(generic_nonzero)]
use std::mem; use std::mem;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::num::{NonZeroU8, NonZeroUsize}; use std::num::NonZero;
const NON_NULL_PTR1: NonNull<u8> = unsafe { mem::transmute(1usize) }; const NON_NULL_PTR1: NonNull<u8> = unsafe { mem::transmute(1usize) };
const NON_NULL_PTR2: NonNull<u8> = unsafe { mem::transmute(&0) }; const NON_NULL_PTR2: NonNull<u8> = unsafe { mem::transmute(&0) };
const NON_NULL_U8: NonZeroU8 = unsafe { mem::transmute(1u8) }; const NON_NULL_U8: NonZero<u8> = unsafe { mem::transmute(1u8) };
const NON_NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(1usize) }; const NON_NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(1usize) };
const UNIT: () = (); const UNIT: () = ();

View File

@ -1,10 +1,11 @@
//@ run-pass //@ run-pass
//
// https://github.com/rust-lang/rust/issues/41898 // https://github.com/rust-lang/rust/issues/41898
#![feature(generic_nonzero)]
use std::num::NonZeroU64; use std::num::NonZero;
fn main() { fn main() {
const FOO: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(2) }; const FOO: NonZero<u64> = unsafe { NonZero::new_unchecked(2) };
if let FOO = FOO {} if let FOO = FOO {}
} }

View File

@ -4,11 +4,11 @@
// ignore-tidy-linelength // ignore-tidy-linelength
//@ ignore-emscripten spawning processes is not supported //@ ignore-emscripten spawning processes is not supported
//@ ignore-sgx no processes //@ ignore-sgx no processes
//
// This test checks panic emitted from `mem::{uninitialized,zeroed}`. // This test checks panic emitted from `mem::{uninitialized,zeroed}`.
#![feature(never_type)]
#![allow(deprecated, invalid_value)] #![allow(deprecated, invalid_value)]
#![feature(generic_nonzero)]
#![feature(never_type)]
use std::{ use std::{
mem::{self, MaybeUninit, ManuallyDrop}, mem::{self, MaybeUninit, ManuallyDrop},
@ -29,7 +29,7 @@ enum OneVariant { Variant(i32) }
#[allow(dead_code, non_camel_case_types)] #[allow(dead_code, non_camel_case_types)]
enum OneVariant_NonZero { enum OneVariant_NonZero {
Variant(i32, i32, num::NonZeroI32), Variant(i32, i32, num::NonZero<i32>),
DeadVariant(Bar), DeadVariant(Bar),
} }
@ -55,8 +55,8 @@ enum LR {
} }
#[allow(dead_code, non_camel_case_types)] #[allow(dead_code, non_camel_case_types)]
enum LR_NonZero { enum LR_NonZero {
Left(num::NonZeroI64), Left(num::NonZero<i64>),
Right(num::NonZeroI64), Right(num::NonZero<i64>),
} }
struct ZeroSized; struct ZeroSized;

View File

@ -1,7 +1,8 @@
//@ check-pass //@ check-pass
#![deny(improper_ctypes)] #![deny(improper_ctypes)]
#![feature(generic_nonzero)]
pub struct Error(std::num::NonZeroU32); pub struct Error(std::num::NonZero<u32>);
extern "Rust" { extern "Rust" {
fn foo(dest: &mut [u8]) -> Result<(), Error>; fn foo(dest: &mut [u8]) -> Result<(), Error>;

View File

@ -1,17 +1,17 @@
// For rust-lang/rust#68303: the contents of `UnsafeCell<T>` cannot // For rust-lang/rust#68303: the contents of `UnsafeCell<T>` cannot
// participate in the niche-optimization for enum discriminants. This // participate in the niche-optimization for enum discriminants. This
// test checks that an `Option<UnsafeCell<NonZeroU32>>` has the same // test checks that an `Option<UnsafeCell<NonZero<u32>>>` has the same
// size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes). // size in memory as an `Option<UnsafeCell<u32>>` (namely, 8 bytes).
//
//@ check-pass //@ check-pass
//@ compile-flags: --crate-type=lib //@ compile-flags: --crate-type=lib
//@ only-x86 //@ only-x86
#![feature(generic_nonzero)]
#![feature(repr_simd)] #![feature(repr_simd)]
use std::cell::{UnsafeCell, RefCell, Cell}; use std::cell::{UnsafeCell, RefCell, Cell};
use std::mem::size_of; use std::mem::size_of;
use std::num::NonZeroU32 as N32; use std::num::NonZero;
use std::sync::{Mutex, RwLock}; use std::sync::{Mutex, RwLock};
struct Wrapper<T>(#[allow(dead_code)] T); struct Wrapper<T>(#[allow(dead_code)] T);
@ -55,14 +55,16 @@ macro_rules! check_sizes {
const PTR_SIZE: usize = std::mem::size_of::<*const ()>(); const PTR_SIZE: usize = std::mem::size_of::<*const ()>();
check_sizes!(Wrapper<u32>: 4 => 8); check_sizes!(Wrapper<u32>: 4 => 8);
check_sizes!(Wrapper<N32>: 4 => 4); // (✓ niche opt) check_sizes!(Wrapper<NonZero<u32>>: 4 => 4); // (✓ niche opt)
check_sizes!(Transparent<u32>: 4 => 8); check_sizes!(Transparent<u32>: 4 => 8);
check_sizes!(Transparent<N32>: 4 => 4); // (✓ niche opt) check_sizes!(Transparent<NonZero<u32>>: 4 => 4); // (✓ niche opt)
check_sizes!(NoNiche<u32>: 4 => 8); check_sizes!(NoNiche<u32>: 4 => 8);
check_sizes!(NoNiche<N32>: 4 => 8); check_sizes!(NoNiche<NonZero<u32>>: 4 => 8);
check_sizes!(UnsafeCell<u32>: 4 => 8); check_sizes!(UnsafeCell<u32>: 4 => 8);
check_sizes!(UnsafeCell<N32>: 4 => 8); check_sizes!(UnsafeCell<NonZero<u32>>: 4 => 8);
check_sizes!(UnsafeCell<&()>: PTR_SIZE => PTR_SIZE * 2); check_sizes!(UnsafeCell<&()>: PTR_SIZE => PTR_SIZE * 2);
check_sizes!( RefCell<&()>: PTR_SIZE * 2 => PTR_SIZE * 3); check_sizes!( RefCell<&()>: PTR_SIZE * 2 => PTR_SIZE * 3);
@ -79,4 +81,4 @@ check_sizes!(UnsafeCell<&dyn Trait>: PTR_SIZE * 2 => PTR_SIZE * 3);
#[repr(simd)] #[repr(simd)]
pub struct Vec4<T>([T; 4]); pub struct Vec4<T>([T; 4]);
check_sizes!(UnsafeCell<Vec4<N32>>: 16 => 32); check_sizes!(UnsafeCell<Vec4<NonZero<u32>>>: 16 => 32);

View File

@ -1,6 +1,7 @@
//@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN" //@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN"
#![feature(rustc_attrs)]
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(generic_nonzero)]
#![feature(rustc_attrs)]
// Various tests around the behavior of zero-sized arrays and // Various tests around the behavior of zero-sized arrays and
// enum niches, especially that they have coherent size and alignment. // enum niches, especially that they have coherent size and alignment.
@ -34,7 +35,7 @@ enum MultipleAlignments { //~ ERROR: layout_of
struct Packed<T>(T); struct Packed<T>(T);
#[rustc_layout(debug)] #[rustc_layout(debug)]
type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>; //~ ERROR: layout_of type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZero<u16>>>; //~ ERROR: layout_of
// Should get tag_encoding: Direct, size == align == 4. // Should get tag_encoding: Direct, size == align == 4.
#[repr(u16)] #[repr(u16)]

View File

@ -98,7 +98,7 @@ error: layout_of(Result<[u32; 0], bool>) = Layout {
max_repr_align: None, max_repr_align: None,
unadjusted_abi_align: Align(4 bytes), unadjusted_abi_align: Align(4 bytes),
} }
--> $DIR/zero-sized-array-enum-niche.rs:13:1 --> $DIR/zero-sized-array-enum-niche.rs:14:1
| |
LL | type AlignedResult = Result<[u32; 0], bool>; LL | type AlignedResult = Result<[u32; 0], bool>;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
@ -227,7 +227,7 @@ error: layout_of(MultipleAlignments) = Layout {
max_repr_align: None, max_repr_align: None,
unadjusted_abi_align: Align(4 bytes), unadjusted_abi_align: Align(4 bytes),
} }
--> $DIR/zero-sized-array-enum-niche.rs:21:1 --> $DIR/zero-sized-array-enum-niche.rs:22:1
| |
LL | enum MultipleAlignments { LL | enum MultipleAlignments {
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
@ -332,9 +332,9 @@ error: layout_of(Result<[u32; 0], Packed<NonZero<u16>>>) = Layout {
max_repr_align: None, max_repr_align: None,
unadjusted_abi_align: Align(4 bytes), unadjusted_abi_align: Align(4 bytes),
} }
--> $DIR/zero-sized-array-enum-niche.rs:37:1 --> $DIR/zero-sized-array-enum-niche.rs:38:1
| |
LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>; LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZero<u16>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout { error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout {
@ -441,7 +441,7 @@ error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout {
max_repr_align: None, max_repr_align: None,
unadjusted_abi_align: Align(4 bytes), unadjusted_abi_align: Align(4 bytes),
} }
--> $DIR/zero-sized-array-enum-niche.rs:44:1 --> $DIR/zero-sized-array-enum-niche.rs:45:1
| |
LL | type NicheWinsOverTagged = Result<[u32; 0], Packed<U16IsZero>>; LL | type NicheWinsOverTagged = Result<[u32; 0], Packed<U16IsZero>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -2,6 +2,7 @@
//@ aux-build:external_extern_fn.rs //@ aux-build:external_extern_fn.rs
#![crate_type = "lib"] #![crate_type = "lib"]
#![warn(clashing_extern_declarations)] #![warn(clashing_extern_declarations)]
#![feature(generic_nonzero)]
mod redeclared_different_signature { mod redeclared_different_signature {
mod a { mod a {
@ -265,7 +266,7 @@ mod missing_return_type {
mod non_zero_and_non_null { mod non_zero_and_non_null {
mod a { mod a {
extern "C" { extern "C" {
fn non_zero_usize() -> core::num::NonZeroUsize; fn non_zero_usize() -> core::num::NonZero<usize>;
fn non_null_ptr() -> core::ptr::NonNull<usize>; fn non_null_ptr() -> core::ptr::NonNull<usize>;
} }
} }
@ -285,36 +286,33 @@ mod non_zero_and_non_null {
// See #75739 // See #75739
mod non_zero_transparent { mod non_zero_transparent {
mod a1 { mod a1 {
use std::num::NonZeroUsize;
extern "C" { extern "C" {
fn f1() -> NonZeroUsize; fn f1() -> std::num::NonZero<usize>;
} }
} }
mod b1 { mod b1 {
#[repr(transparent)] #[repr(transparent)]
struct X(NonZeroUsize); struct X(std::num::NonZero<usize>);
use std::num::NonZeroUsize;
extern "C" { extern "C" {
fn f1() -> X; fn f1() -> X;
} }
} }
mod a2 { mod a2 {
use std::num::NonZeroUsize;
extern "C" { extern "C" {
fn f2() -> NonZeroUsize; fn f2() -> std::num::NonZero<usize>;
} }
} }
mod b2 { mod b2 {
#[repr(transparent)] #[repr(transparent)]
struct X1(NonZeroUsize); struct X1(std::num::NonZero<usize>);
#[repr(transparent)] #[repr(transparent)]
struct X(X1); struct X(X1);
use std::num::NonZeroUsize;
extern "C" { extern "C" {
// Same case as above, but with two layers of newtyping. // Same case as above, but with two layers of newtyping.
fn f2() -> X; fn f2() -> X;
@ -325,7 +323,6 @@ mod non_zero_transparent {
#[repr(transparent)] #[repr(transparent)]
struct X(core::ptr::NonNull<i32>); struct X(core::ptr::NonNull<i32>);
use std::num::NonZeroUsize;
extern "C" { extern "C" {
fn f3() -> X; fn f3() -> X;
} }
@ -340,7 +337,7 @@ mod non_zero_transparent {
mod a4 { mod a4 {
#[repr(transparent)] #[repr(transparent)]
enum E { enum E {
X(std::num::NonZeroUsize), X(std::num::NonZero<usize>),
} }
extern "C" { extern "C" {
fn f4() -> E; fn f4() -> E;
@ -349,7 +346,7 @@ mod non_zero_transparent {
mod b4 { mod b4 {
extern "C" { extern "C" {
fn f4() -> std::num::NonZeroUsize; fn f4() -> std::num::NonZero<usize>;
} }
} }
} }
@ -369,8 +366,8 @@ mod null_optimised_enums {
extern "C" { extern "C" {
// This should be allowed, because these conversions are guaranteed to be FFI-safe (see // This should be allowed, because these conversions are guaranteed to be FFI-safe (see
// #60300) // #60300)
fn option_non_zero_usize() -> Option<core::num::NonZeroUsize>; fn option_non_zero_usize() -> Option<core::num::NonZero<usize>>;
fn option_non_zero_isize() -> Option<core::num::NonZeroIsize>; fn option_non_zero_isize() -> Option<core::num::NonZero<isize>>;
fn option_non_null_ptr() -> Option<core::ptr::NonNull<usize>>; fn option_non_null_ptr() -> Option<core::ptr::NonNull<usize>>;
// However, these should be incorrect (note isize instead of usize) // However, these should be incorrect (note isize instead of usize)
@ -415,16 +412,16 @@ mod hidden_niche {
} }
mod b { mod b {
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::num::NonZeroUsize; use std::num::NonZero;
#[repr(transparent)] #[repr(transparent)]
struct Transparent { struct Transparent {
x: NonZeroUsize, x: NonZero<usize>,
} }
#[repr(transparent)] #[repr(transparent)]
struct TransparentNoNiche { struct TransparentNoNiche {
y: UnsafeCell<NonZeroUsize>, y: UnsafeCell<NonZero<usize>>,
} }
extern "C" { extern "C" {
@ -434,7 +431,7 @@ mod hidden_niche {
//~^ WARN redeclared with a different signature //~^ WARN redeclared with a different signature
//~| WARN block uses type `Option<TransparentNoNiche>`, which is not FFI-safe //~| WARN block uses type `Option<TransparentNoNiche>`, which is not FFI-safe
fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize>>; fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZero<usize>>>;
//~^ WARN redeclared with a different signature //~^ WARN redeclared with a different signature
//~| WARN block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe //~| WARN block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe
} }

View File

@ -1,5 +1,5 @@
warning: `extern` block uses type `Option<TransparentNoNiche>`, which is not FFI-safe warning: `extern` block uses type `Option<TransparentNoNiche>`, which is not FFI-safe
--> $DIR/clashing-extern-fn.rs:433:55 --> $DIR/clashing-extern-fn.rs:430:55
| |
LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoNiche>; LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoNiche>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@ -9,16 +9,16 @@ LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoN
= note: `#[warn(improper_ctypes)]` on by default = note: `#[warn(improper_ctypes)]` on by default
warning: `extern` block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe warning: `extern` block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe
--> $DIR/clashing-extern-fn.rs:437:46 --> $DIR/clashing-extern-fn.rs:434:46
| |
LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize>>; LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZero<usize>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
| |
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint
warning: `clash` redeclared with a different signature warning: `clash` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:14:13 --> $DIR/clashing-extern-fn.rs:15:13
| |
LL | fn clash(x: u8); LL | fn clash(x: u8);
| --------------- `clash` previously declared here | --------------- `clash` previously declared here
@ -35,7 +35,7 @@ LL | #![warn(clashing_extern_declarations)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `extern_link_name` redeclared with a different signature warning: `extern_link_name` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:52:9 --> $DIR/clashing-extern-fn.rs:53:9
| |
LL | #[link_name = "extern_link_name"] LL | #[link_name = "extern_link_name"]
| --------------------------------- `extern_link_name` previously declared here | --------------------------------- `extern_link_name` previously declared here
@ -47,7 +47,7 @@ LL | fn extern_link_name(x: u32);
found `unsafe extern "C" fn(u32)` found `unsafe extern "C" fn(u32)`
warning: `some_other_extern_link_name` redeclares `some_other_new_name` with a different signature warning: `some_other_extern_link_name` redeclares `some_other_new_name` with a different signature
--> $DIR/clashing-extern-fn.rs:55:9 --> $DIR/clashing-extern-fn.rs:56:9
| |
LL | fn some_other_new_name(x: i16); LL | fn some_other_new_name(x: i16);
| ------------------------------ `some_other_new_name` previously declared here | ------------------------------ `some_other_new_name` previously declared here
@ -59,7 +59,7 @@ LL | #[link_name = "some_other_new_name"]
found `unsafe extern "C" fn(u32)` found `unsafe extern "C" fn(u32)`
warning: `other_both_names_different` redeclares `link_name_same` with a different signature warning: `other_both_names_different` redeclares `link_name_same` with a different signature
--> $DIR/clashing-extern-fn.rs:59:9 --> $DIR/clashing-extern-fn.rs:60:9
| |
LL | #[link_name = "link_name_same"] LL | #[link_name = "link_name_same"]
| ------------------------------- `link_name_same` previously declared here | ------------------------------- `link_name_same` previously declared here
@ -71,7 +71,7 @@ LL | #[link_name = "link_name_same"]
found `unsafe extern "C" fn(u32)` found `unsafe extern "C" fn(u32)`
warning: `different_mod` redeclared with a different signature warning: `different_mod` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:72:9 --> $DIR/clashing-extern-fn.rs:73:9
| |
LL | fn different_mod(x: u8); LL | fn different_mod(x: u8);
| ----------------------- `different_mod` previously declared here | ----------------------- `different_mod` previously declared here
@ -83,7 +83,7 @@ LL | fn different_mod(x: u64);
found `unsafe extern "C" fn(u64)` found `unsafe extern "C" fn(u64)`
warning: `variadic_decl` redeclared with a different signature warning: `variadic_decl` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:82:9 --> $DIR/clashing-extern-fn.rs:83:9
| |
LL | fn variadic_decl(x: u8, ...); LL | fn variadic_decl(x: u8, ...);
| ---------------------------- `variadic_decl` previously declared here | ---------------------------- `variadic_decl` previously declared here
@ -95,7 +95,7 @@ LL | fn variadic_decl(x: u8);
found `unsafe extern "C" fn(u8)` found `unsafe extern "C" fn(u8)`
warning: `weigh_banana` redeclared with a different signature warning: `weigh_banana` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:142:13 --> $DIR/clashing-extern-fn.rs:143:13
| |
LL | fn weigh_banana(count: *const Banana) -> u64; LL | fn weigh_banana(count: *const Banana) -> u64;
| -------------------------------------------- `weigh_banana` previously declared here | -------------------------------------------- `weigh_banana` previously declared here
@ -107,7 +107,7 @@ LL | fn weigh_banana(count: *const Banana) -> u64;
found `unsafe extern "C" fn(*const three::Banana) -> u64` found `unsafe extern "C" fn(*const three::Banana) -> u64`
warning: `draw_point` redeclared with a different signature warning: `draw_point` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:171:13 --> $DIR/clashing-extern-fn.rs:172:13
| |
LL | fn draw_point(p: Point); LL | fn draw_point(p: Point);
| ----------------------- `draw_point` previously declared here | ----------------------- `draw_point` previously declared here
@ -119,7 +119,7 @@ LL | fn draw_point(p: Point);
found `unsafe extern "C" fn(sameish_members::b::Point)` found `unsafe extern "C" fn(sameish_members::b::Point)`
warning: `origin` redeclared with a different signature warning: `origin` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:197:13 --> $DIR/clashing-extern-fn.rs:198:13
| |
LL | fn origin() -> Point3; LL | fn origin() -> Point3;
| --------------------- `origin` previously declared here | --------------------- `origin` previously declared here
@ -131,7 +131,7 @@ LL | fn origin() -> Point3;
found `unsafe extern "C" fn() -> same_sized_members_clash::b::Point3` found `unsafe extern "C" fn() -> same_sized_members_clash::b::Point3`
warning: `transparent_incorrect` redeclared with a different signature warning: `transparent_incorrect` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:220:13 --> $DIR/clashing-extern-fn.rs:221:13
| |
LL | fn transparent_incorrect() -> T; LL | fn transparent_incorrect() -> T;
| ------------------------------- `transparent_incorrect` previously declared here | ------------------------------- `transparent_incorrect` previously declared here
@ -143,7 +143,7 @@ LL | fn transparent_incorrect() -> isize;
found `unsafe extern "C" fn() -> isize` found `unsafe extern "C" fn() -> isize`
warning: `missing_return_type` redeclared with a different signature warning: `missing_return_type` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:259:13 --> $DIR/clashing-extern-fn.rs:260:13
| |
LL | fn missing_return_type() -> usize; LL | fn missing_return_type() -> usize;
| --------------------------------- `missing_return_type` previously declared here | --------------------------------- `missing_return_type` previously declared here
@ -155,10 +155,10 @@ LL | fn missing_return_type();
found `unsafe extern "C" fn()` found `unsafe extern "C" fn()`
warning: `non_zero_usize` redeclared with a different signature warning: `non_zero_usize` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:277:13 --> $DIR/clashing-extern-fn.rs:278:13
| |
LL | fn non_zero_usize() -> core::num::NonZeroUsize; LL | fn non_zero_usize() -> core::num::NonZero<usize>;
| ---------------------------------------------- `non_zero_usize` previously declared here | ------------------------------------------------ `non_zero_usize` previously declared here
... ...
LL | fn non_zero_usize() -> usize; LL | fn non_zero_usize() -> usize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
@ -167,7 +167,7 @@ LL | fn non_zero_usize() -> usize;
found `unsafe extern "C" fn() -> usize` found `unsafe extern "C" fn() -> usize`
warning: `non_null_ptr` redeclared with a different signature warning: `non_null_ptr` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:279:13 --> $DIR/clashing-extern-fn.rs:280:13
| |
LL | fn non_null_ptr() -> core::ptr::NonNull<usize>; LL | fn non_null_ptr() -> core::ptr::NonNull<usize>;
| ---------------------------------------------- `non_null_ptr` previously declared here | ---------------------------------------------- `non_null_ptr` previously declared here
@ -179,7 +179,7 @@ LL | fn non_null_ptr() -> *const usize;
found `unsafe extern "C" fn() -> *const usize` found `unsafe extern "C" fn() -> *const usize`
warning: `option_non_zero_usize_incorrect` redeclared with a different signature warning: `option_non_zero_usize_incorrect` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:377:13 --> $DIR/clashing-extern-fn.rs:374:13
| |
LL | fn option_non_zero_usize_incorrect() -> usize; LL | fn option_non_zero_usize_incorrect() -> usize;
| --------------------------------------------- `option_non_zero_usize_incorrect` previously declared here | --------------------------------------------- `option_non_zero_usize_incorrect` previously declared here
@ -191,7 +191,7 @@ LL | fn option_non_zero_usize_incorrect() -> isize;
found `unsafe extern "C" fn() -> isize` found `unsafe extern "C" fn() -> isize`
warning: `option_non_null_ptr_incorrect` redeclared with a different signature warning: `option_non_null_ptr_incorrect` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:379:13 --> $DIR/clashing-extern-fn.rs:376:13
| |
LL | fn option_non_null_ptr_incorrect() -> *const usize; LL | fn option_non_null_ptr_incorrect() -> *const usize;
| -------------------------------------------------- `option_non_null_ptr_incorrect` previously declared here | -------------------------------------------------- `option_non_null_ptr_incorrect` previously declared here
@ -203,7 +203,7 @@ LL | fn option_non_null_ptr_incorrect() -> *const isize;
found `unsafe extern "C" fn() -> *const isize` found `unsafe extern "C" fn() -> *const isize`
warning: `hidden_niche_transparent_no_niche` redeclared with a different signature warning: `hidden_niche_transparent_no_niche` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:433:13 --> $DIR/clashing-extern-fn.rs:430:13
| |
LL | fn hidden_niche_transparent_no_niche() -> usize; LL | fn hidden_niche_transparent_no_niche() -> usize;
| ----------------------------------------------- `hidden_niche_transparent_no_niche` previously declared here | ----------------------------------------------- `hidden_niche_transparent_no_niche` previously declared here
@ -215,13 +215,13 @@ LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoN
found `unsafe extern "C" fn() -> Option<TransparentNoNiche>` found `unsafe extern "C" fn() -> Option<TransparentNoNiche>`
warning: `hidden_niche_unsafe_cell` redeclared with a different signature warning: `hidden_niche_unsafe_cell` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:437:13 --> $DIR/clashing-extern-fn.rs:434:13
| |
LL | fn hidden_niche_unsafe_cell() -> usize; LL | fn hidden_niche_unsafe_cell() -> usize;
| -------------------------------------- `hidden_niche_unsafe_cell` previously declared here | -------------------------------------- `hidden_niche_unsafe_cell` previously declared here
... ...
LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize>>; LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZero<usize>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
| |
= note: expected `unsafe extern "C" fn() -> usize` = note: expected `unsafe extern "C" fn() -> usize`
found `unsafe extern "C" fn() -> Option<UnsafeCell<NonZero<usize>>>` found `unsafe extern "C" fn() -> Option<UnsafeCell<NonZero<usize>>>`

View File

@ -1,13 +1,12 @@
// This test checks that calling `mem::{uninitialized,zeroed}` with certain types results // This test checks that calling `mem::{uninitialized,zeroed}` with certain types results
// in a lint. // in a lint.
#![feature(never_type, rustc_attrs)]
#![allow(deprecated)] #![allow(deprecated)]
#![deny(invalid_value)] #![deny(invalid_value)]
#![feature(generic_nonzero, never_type, rustc_attrs)]
use std::mem::{self, MaybeUninit}; use std::mem::{self, MaybeUninit};
use std::ptr::NonNull; use std::ptr::NonNull;
use std::num::NonZeroU32; use std::num::NonZero;
enum Void {} enum Void {}
@ -36,7 +35,7 @@ enum OneFruit {
enum OneFruitNonZero { enum OneFruitNonZero {
Apple(!), Apple(!),
Banana(NonZeroU32), Banana(NonZero<u32>),
} }
enum TwoUninhabited { enum TwoUninhabited {
@ -92,8 +91,8 @@ fn main() {
let _val: NonNull<i32> = mem::zeroed(); //~ ERROR: does not permit zero-initialization let _val: NonNull<i32> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: NonNull<i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized let _val: NonNull<i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
let _val: (NonZeroU32, i32) = mem::zeroed(); //~ ERROR: does not permit zero-initialization let _val: (NonZero<u32>, i32) = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: (NonZeroU32, i32) = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized let _val: (NonZero<u32>, i32) = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
let _val: *const dyn Send = mem::zeroed(); //~ ERROR: does not permit zero-initialization let _val: *const dyn Send = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: *const dyn Send = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized let _val: *const dyn Send = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
@ -151,7 +150,7 @@ fn main() {
// Transmute-from-0 // Transmute-from-0
let _val: &'static i32 = mem::transmute(0usize); //~ ERROR: does not permit zero-initialization let _val: &'static i32 = mem::transmute(0usize); //~ ERROR: does not permit zero-initialization
let _val: &'static [i32] = mem::transmute((0usize, 0usize)); //~ ERROR: does not permit zero-initialization let _val: &'static [i32] = mem::transmute((0usize, 0usize)); //~ ERROR: does not permit zero-initialization
let _val: NonZeroU32 = mem::transmute(0); //~ ERROR: does not permit zero-initialization let _val: NonZero<u32> = mem::transmute(0); //~ ERROR: does not permit zero-initialization
// `MaybeUninit` cases // `MaybeUninit` cases
let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init(); //~ ERROR: does not permit zero-initialization let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init(); //~ ERROR: does not permit zero-initialization

View File

@ -1,5 +1,5 @@
error: the type `&T` does not permit zero-initialization error: the type `&T` does not permit zero-initialization
--> $DIR/invalid_value.rs:54:32 --> $DIR/invalid_value.rs:53:32
| |
LL | let _val: &'static T = mem::zeroed(); LL | let _val: &'static T = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -9,13 +9,13 @@ LL | let _val: &'static T = mem::zeroed();
| |
= note: references must be non-null = note: references must be non-null
note: the lint level is defined here note: the lint level is defined here
--> $DIR/invalid_value.rs:6:9 --> $DIR/invalid_value.rs:4:9
| |
LL | #![deny(invalid_value)] LL | #![deny(invalid_value)]
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: the type `&T` does not permit being left uninitialized error: the type `&T` does not permit being left uninitialized
--> $DIR/invalid_value.rs:55:32 --> $DIR/invalid_value.rs:54:32
| |
LL | let _val: &'static T = mem::uninitialized(); LL | let _val: &'static T = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -26,7 +26,7 @@ LL | let _val: &'static T = mem::uninitialized();
= note: references must be non-null = note: references must be non-null
error: the type `Wrap<&T>` does not permit zero-initialization error: the type `Wrap<&T>` does not permit zero-initialization
--> $DIR/invalid_value.rs:57:38 --> $DIR/invalid_value.rs:56:38
| |
LL | let _val: Wrap<&'static T> = mem::zeroed(); LL | let _val: Wrap<&'static T> = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -36,13 +36,13 @@ LL | let _val: Wrap<&'static T> = mem::zeroed();
| |
= note: `Wrap<&T>` must be non-null = note: `Wrap<&T>` must be non-null
note: because references must be non-null (in this struct field) note: because references must be non-null (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the type `Wrap<&T>` does not permit being left uninitialized error: the type `Wrap<&T>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:58:38 --> $DIR/invalid_value.rs:57:38
| |
LL | let _val: Wrap<&'static T> = mem::uninitialized(); LL | let _val: Wrap<&'static T> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -52,13 +52,13 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized();
| |
= note: `Wrap<&T>` must be non-null = note: `Wrap<&T>` must be non-null
note: because references must be non-null (in this struct field) note: because references must be non-null (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the type `!` does not permit zero-initialization error: the type `!` does not permit zero-initialization
--> $DIR/invalid_value.rs:65:23 --> $DIR/invalid_value.rs:64:23
| |
LL | let _val: ! = mem::zeroed(); LL | let _val: ! = mem::zeroed();
| ^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^ this code causes undefined behavior when executed
@ -66,7 +66,7 @@ LL | let _val: ! = mem::zeroed();
= note: the `!` type has no valid value = note: the `!` type has no valid value
error: the type `!` does not permit being left uninitialized error: the type `!` does not permit being left uninitialized
--> $DIR/invalid_value.rs:66:23 --> $DIR/invalid_value.rs:65:23
| |
LL | let _val: ! = mem::uninitialized(); LL | let _val: ! = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
@ -74,7 +74,7 @@ LL | let _val: ! = mem::uninitialized();
= note: the `!` type has no valid value = note: the `!` type has no valid value
error: the type `(i32, !)` does not permit zero-initialization error: the type `(i32, !)` does not permit zero-initialization
--> $DIR/invalid_value.rs:68:30 --> $DIR/invalid_value.rs:67:30
| |
LL | let _val: (i32, !) = mem::zeroed(); LL | let _val: (i32, !) = mem::zeroed();
| ^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^ this code causes undefined behavior when executed
@ -82,7 +82,7 @@ LL | let _val: (i32, !) = mem::zeroed();
= note: the `!` type has no valid value = note: the `!` type has no valid value
error: the type `(i32, !)` does not permit being left uninitialized error: the type `(i32, !)` does not permit being left uninitialized
--> $DIR/invalid_value.rs:69:30 --> $DIR/invalid_value.rs:68:30
| |
LL | let _val: (i32, !) = mem::uninitialized(); LL | let _val: (i32, !) = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
@ -90,31 +90,31 @@ LL | let _val: (i32, !) = mem::uninitialized();
= note: integers must be initialized = note: integers must be initialized
error: the type `Void` does not permit zero-initialization error: the type `Void` does not permit zero-initialization
--> $DIR/invalid_value.rs:71:26 --> $DIR/invalid_value.rs:70:26
| |
LL | let _val: Void = mem::zeroed(); LL | let _val: Void = mem::zeroed();
| ^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^ this code causes undefined behavior when executed
| |
note: enums with no inhabited variants have no valid value note: enums with no inhabited variants have no valid value
--> $DIR/invalid_value.rs:12:1 --> $DIR/invalid_value.rs:11:1
| |
LL | enum Void {} LL | enum Void {}
| ^^^^^^^^^ | ^^^^^^^^^
error: the type `Void` does not permit being left uninitialized error: the type `Void` does not permit being left uninitialized
--> $DIR/invalid_value.rs:72:26 --> $DIR/invalid_value.rs:71:26
| |
LL | let _val: Void = mem::uninitialized(); LL | let _val: Void = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
| |
note: enums with no inhabited variants have no valid value note: enums with no inhabited variants have no valid value
--> $DIR/invalid_value.rs:12:1 --> $DIR/invalid_value.rs:11:1
| |
LL | enum Void {} LL | enum Void {}
| ^^^^^^^^^ | ^^^^^^^^^
error: the type `&i32` does not permit zero-initialization error: the type `&i32` does not permit zero-initialization
--> $DIR/invalid_value.rs:74:34 --> $DIR/invalid_value.rs:73:34
| |
LL | let _val: &'static i32 = mem::zeroed(); LL | let _val: &'static i32 = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -125,7 +125,7 @@ LL | let _val: &'static i32 = mem::zeroed();
= note: references must be non-null = note: references must be non-null
error: the type `&i32` does not permit being left uninitialized error: the type `&i32` does not permit being left uninitialized
--> $DIR/invalid_value.rs:75:34 --> $DIR/invalid_value.rs:74:34
| |
LL | let _val: &'static i32 = mem::uninitialized(); LL | let _val: &'static i32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -136,7 +136,7 @@ LL | let _val: &'static i32 = mem::uninitialized();
= note: references must be non-null = note: references must be non-null
error: the type `Ref` does not permit zero-initialization error: the type `Ref` does not permit zero-initialization
--> $DIR/invalid_value.rs:77:25 --> $DIR/invalid_value.rs:76:25
| |
LL | let _val: Ref = mem::zeroed(); LL | let _val: Ref = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -146,13 +146,13 @@ LL | let _val: Ref = mem::zeroed();
| |
= note: `Ref` must be non-null = note: `Ref` must be non-null
note: because references must be non-null (in this struct field) note: because references must be non-null (in this struct field)
--> $DIR/invalid_value.rs:14:12 --> $DIR/invalid_value.rs:13:12
| |
LL | struct Ref(&'static i32); LL | struct Ref(&'static i32);
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: the type `Ref` does not permit being left uninitialized error: the type `Ref` does not permit being left uninitialized
--> $DIR/invalid_value.rs:78:25 --> $DIR/invalid_value.rs:77:25
| |
LL | let _val: Ref = mem::uninitialized(); LL | let _val: Ref = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -162,13 +162,13 @@ LL | let _val: Ref = mem::uninitialized();
| |
= note: `Ref` must be non-null = note: `Ref` must be non-null
note: because references must be non-null (in this struct field) note: because references must be non-null (in this struct field)
--> $DIR/invalid_value.rs:14:12 --> $DIR/invalid_value.rs:13:12
| |
LL | struct Ref(&'static i32); LL | struct Ref(&'static i32);
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: the type `fn()` does not permit zero-initialization error: the type `fn()` does not permit zero-initialization
--> $DIR/invalid_value.rs:80:26 --> $DIR/invalid_value.rs:79:26
| |
LL | let _val: fn() = mem::zeroed(); LL | let _val: fn() = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -179,7 +179,7 @@ LL | let _val: fn() = mem::zeroed();
= note: function pointers must be non-null = note: function pointers must be non-null
error: the type `fn()` does not permit being left uninitialized error: the type `fn()` does not permit being left uninitialized
--> $DIR/invalid_value.rs:81:26 --> $DIR/invalid_value.rs:80:26
| |
LL | let _val: fn() = mem::uninitialized(); LL | let _val: fn() = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -190,7 +190,7 @@ LL | let _val: fn() = mem::uninitialized();
= note: function pointers must be non-null = note: function pointers must be non-null
error: the type `Wrap<fn()>` does not permit zero-initialization error: the type `Wrap<fn()>` does not permit zero-initialization
--> $DIR/invalid_value.rs:83:32 --> $DIR/invalid_value.rs:82:32
| |
LL | let _val: Wrap<fn()> = mem::zeroed(); LL | let _val: Wrap<fn()> = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -200,13 +200,13 @@ LL | let _val: Wrap<fn()> = mem::zeroed();
| |
= note: `Wrap<fn()>` must be non-null = note: `Wrap<fn()>` must be non-null
note: because function pointers must be non-null (in this struct field) note: because function pointers must be non-null (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the type `Wrap<fn()>` does not permit being left uninitialized error: the type `Wrap<fn()>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:84:32 --> $DIR/invalid_value.rs:83:32
| |
LL | let _val: Wrap<fn()> = mem::uninitialized(); LL | let _val: Wrap<fn()> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -216,13 +216,13 @@ LL | let _val: Wrap<fn()> = mem::uninitialized();
| |
= note: `Wrap<fn()>` must be non-null = note: `Wrap<fn()>` must be non-null
note: because function pointers must be non-null (in this struct field) note: because function pointers must be non-null (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the type `WrapEnum<fn()>` does not permit zero-initialization error: the type `WrapEnum<fn()>` does not permit zero-initialization
--> $DIR/invalid_value.rs:86:36 --> $DIR/invalid_value.rs:85:36
| |
LL | let _val: WrapEnum<fn()> = mem::zeroed(); LL | let _val: WrapEnum<fn()> = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -232,13 +232,13 @@ LL | let _val: WrapEnum<fn()> = mem::zeroed();
| |
= note: `WrapEnum<fn()>` must be non-null = note: `WrapEnum<fn()>` must be non-null
note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant) note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant)
--> $DIR/invalid_value.rs:18:28 --> $DIR/invalid_value.rs:17:28
| |
LL | enum WrapEnum<T> { Wrapped(T) } LL | enum WrapEnum<T> { Wrapped(T) }
| ^ | ^
error: the type `WrapEnum<fn()>` does not permit being left uninitialized error: the type `WrapEnum<fn()>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:87:36 --> $DIR/invalid_value.rs:86:36
| |
LL | let _val: WrapEnum<fn()> = mem::uninitialized(); LL | let _val: WrapEnum<fn()> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -248,13 +248,13 @@ LL | let _val: WrapEnum<fn()> = mem::uninitialized();
| |
= note: `WrapEnum<fn()>` must be non-null = note: `WrapEnum<fn()>` must be non-null
note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant) note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant)
--> $DIR/invalid_value.rs:18:28 --> $DIR/invalid_value.rs:17:28
| |
LL | enum WrapEnum<T> { Wrapped(T) } LL | enum WrapEnum<T> { Wrapped(T) }
| ^ | ^
error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization
--> $DIR/invalid_value.rs:89:42 --> $DIR/invalid_value.rs:88:42
| |
LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed(); LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -263,18 +263,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
| |
note: `RefPair` must be non-null (in this struct field) note: `RefPair` must be non-null (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
note: because references must be non-null (in this struct field) note: because references must be non-null (in this struct field)
--> $DIR/invalid_value.rs:15:16 --> $DIR/invalid_value.rs:14:16
| |
LL | struct RefPair((&'static i32, i32)); LL | struct RefPair((&'static i32, i32));
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:90:42 --> $DIR/invalid_value.rs:89:42
| |
LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -283,18 +283,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
| |
note: `RefPair` must be non-null (in this struct field) note: `RefPair` must be non-null (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
note: because references must be non-null (in this struct field) note: because references must be non-null (in this struct field)
--> $DIR/invalid_value.rs:15:16 --> $DIR/invalid_value.rs:14:16
| |
LL | struct RefPair((&'static i32, i32)); LL | struct RefPair((&'static i32, i32));
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: the type `NonNull<i32>` does not permit zero-initialization error: the type `NonNull<i32>` does not permit zero-initialization
--> $DIR/invalid_value.rs:92:34 --> $DIR/invalid_value.rs:91:34
| |
LL | let _val: NonNull<i32> = mem::zeroed(); LL | let _val: NonNull<i32> = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -305,7 +305,7 @@ LL | let _val: NonNull<i32> = mem::zeroed();
= note: `std::ptr::NonNull<i32>` must be non-null = note: `std::ptr::NonNull<i32>` must be non-null
error: the type `NonNull<i32>` does not permit being left uninitialized error: the type `NonNull<i32>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:93:34 --> $DIR/invalid_value.rs:92:34
| |
LL | let _val: NonNull<i32> = mem::uninitialized(); LL | let _val: NonNull<i32> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -317,9 +317,9 @@ LL | let _val: NonNull<i32> = mem::uninitialized();
= note: raw pointers must be initialized = note: raw pointers must be initialized
error: the type `(NonZero<u32>, i32)` does not permit zero-initialization error: the type `(NonZero<u32>, i32)` does not permit zero-initialization
--> $DIR/invalid_value.rs:95:39 --> $DIR/invalid_value.rs:94:41
| |
LL | let _val: (NonZeroU32, i32) = mem::zeroed(); LL | let _val: (NonZero<u32>, i32) = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
| | | |
| this code causes undefined behavior when executed | this code causes undefined behavior when executed
@ -328,9 +328,9 @@ LL | let _val: (NonZeroU32, i32) = mem::zeroed();
= note: `std::num::NonZero<u32>` must be non-null = note: `std::num::NonZero<u32>` must be non-null
error: the type `(NonZero<u32>, i32)` does not permit being left uninitialized error: the type `(NonZero<u32>, i32)` does not permit being left uninitialized
--> $DIR/invalid_value.rs:96:39 --> $DIR/invalid_value.rs:95:41
| |
LL | let _val: (NonZeroU32, i32) = mem::uninitialized(); LL | let _val: (NonZero<u32>, i32) = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
| | | |
| this code causes undefined behavior when executed | this code causes undefined behavior when executed
@ -340,7 +340,7 @@ LL | let _val: (NonZeroU32, i32) = mem::uninitialized();
= note: integers must be initialized = note: integers must be initialized
error: the type `*const dyn Send` does not permit zero-initialization error: the type `*const dyn Send` does not permit zero-initialization
--> $DIR/invalid_value.rs:98:37 --> $DIR/invalid_value.rs:97:37
| |
LL | let _val: *const dyn Send = mem::zeroed(); LL | let _val: *const dyn Send = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -351,7 +351,7 @@ LL | let _val: *const dyn Send = mem::zeroed();
= note: the vtable of a wide raw pointer must be non-null = note: the vtable of a wide raw pointer must be non-null
error: the type `*const dyn Send` does not permit being left uninitialized error: the type `*const dyn Send` does not permit being left uninitialized
--> $DIR/invalid_value.rs:99:37 --> $DIR/invalid_value.rs:98:37
| |
LL | let _val: *const dyn Send = mem::uninitialized(); LL | let _val: *const dyn Send = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -362,7 +362,7 @@ LL | let _val: *const dyn Send = mem::uninitialized();
= note: the vtable of a wide raw pointer must be non-null = note: the vtable of a wide raw pointer must be non-null
error: the type `[fn(); 2]` does not permit zero-initialization error: the type `[fn(); 2]` does not permit zero-initialization
--> $DIR/invalid_value.rs:101:31 --> $DIR/invalid_value.rs:100:31
| |
LL | let _val: [fn(); 2] = mem::zeroed(); LL | let _val: [fn(); 2] = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -373,7 +373,7 @@ LL | let _val: [fn(); 2] = mem::zeroed();
= note: function pointers must be non-null = note: function pointers must be non-null
error: the type `[fn(); 2]` does not permit being left uninitialized error: the type `[fn(); 2]` does not permit being left uninitialized
--> $DIR/invalid_value.rs:102:31 --> $DIR/invalid_value.rs:101:31
| |
LL | let _val: [fn(); 2] = mem::uninitialized(); LL | let _val: [fn(); 2] = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -384,31 +384,31 @@ LL | let _val: [fn(); 2] = mem::uninitialized();
= note: function pointers must be non-null = note: function pointers must be non-null
error: the type `TwoUninhabited` does not permit zero-initialization error: the type `TwoUninhabited` does not permit zero-initialization
--> $DIR/invalid_value.rs:104:36 --> $DIR/invalid_value.rs:103:36
| |
LL | let _val: TwoUninhabited = mem::zeroed(); LL | let _val: TwoUninhabited = mem::zeroed();
| ^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^ this code causes undefined behavior when executed
| |
note: enums with no inhabited variants have no valid value note: enums with no inhabited variants have no valid value
--> $DIR/invalid_value.rs:42:1 --> $DIR/invalid_value.rs:41:1
| |
LL | enum TwoUninhabited { LL | enum TwoUninhabited {
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: the type `TwoUninhabited` does not permit being left uninitialized error: the type `TwoUninhabited` does not permit being left uninitialized
--> $DIR/invalid_value.rs:105:36 --> $DIR/invalid_value.rs:104:36
| |
LL | let _val: TwoUninhabited = mem::uninitialized(); LL | let _val: TwoUninhabited = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
| |
note: enums with no inhabited variants have no valid value note: enums with no inhabited variants have no valid value
--> $DIR/invalid_value.rs:42:1 --> $DIR/invalid_value.rs:41:1
| |
LL | enum TwoUninhabited { LL | enum TwoUninhabited {
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: the type `OneFruitNonZero` does not permit zero-initialization error: the type `OneFruitNonZero` does not permit zero-initialization
--> $DIR/invalid_value.rs:107:37 --> $DIR/invalid_value.rs:106:37
| |
LL | let _val: OneFruitNonZero = mem::zeroed(); LL | let _val: OneFruitNonZero = mem::zeroed();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -418,13 +418,13 @@ LL | let _val: OneFruitNonZero = mem::zeroed();
| |
= note: `OneFruitNonZero` must be non-null = note: `OneFruitNonZero` must be non-null
note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant) note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant)
--> $DIR/invalid_value.rs:39:12 --> $DIR/invalid_value.rs:38:12
| |
LL | Banana(NonZeroU32), LL | Banana(NonZero<u32>),
| ^^^^^^^^^^ | ^^^^^^^^^^^^
error: the type `OneFruitNonZero` does not permit being left uninitialized error: the type `OneFruitNonZero` does not permit being left uninitialized
--> $DIR/invalid_value.rs:108:37 --> $DIR/invalid_value.rs:107:37
| |
LL | let _val: OneFruitNonZero = mem::uninitialized(); LL | let _val: OneFruitNonZero = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -434,14 +434,14 @@ LL | let _val: OneFruitNonZero = mem::uninitialized();
| |
= note: `OneFruitNonZero` must be non-null = note: `OneFruitNonZero` must be non-null
note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant) note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant)
--> $DIR/invalid_value.rs:39:12 --> $DIR/invalid_value.rs:38:12
| |
LL | Banana(NonZeroU32), LL | Banana(NonZero<u32>),
| ^^^^^^^^^^ | ^^^^^^^^^^^^
= note: integers must be initialized = note: integers must be initialized
error: the type `bool` does not permit being left uninitialized error: the type `bool` does not permit being left uninitialized
--> $DIR/invalid_value.rs:112:26 --> $DIR/invalid_value.rs:111:26
| |
LL | let _val: bool = mem::uninitialized(); LL | let _val: bool = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -452,7 +452,7 @@ LL | let _val: bool = mem::uninitialized();
= note: booleans must be either `true` or `false` = note: booleans must be either `true` or `false`
error: the type `Wrap<char>` does not permit being left uninitialized error: the type `Wrap<char>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:115:32 --> $DIR/invalid_value.rs:114:32
| |
LL | let _val: Wrap<char> = mem::uninitialized(); LL | let _val: Wrap<char> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -462,13 +462,13 @@ LL | let _val: Wrap<char> = mem::uninitialized();
| |
= note: `Wrap<char>` must be initialized inside its custom valid range = note: `Wrap<char>` must be initialized inside its custom valid range
note: characters must be a valid Unicode codepoint (in this struct field) note: characters must be a valid Unicode codepoint (in this struct field)
--> $DIR/invalid_value.rs:17:18 --> $DIR/invalid_value.rs:16:18
| |
LL | struct Wrap<T> { wrapped: T } LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the type `NonBig` does not permit being left uninitialized error: the type `NonBig` does not permit being left uninitialized
--> $DIR/invalid_value.rs:118:28 --> $DIR/invalid_value.rs:117:28
| |
LL | let _val: NonBig = mem::uninitialized(); LL | let _val: NonBig = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -478,13 +478,13 @@ LL | let _val: NonBig = mem::uninitialized();
| |
= note: `NonBig` must be initialized inside its custom valid range = note: `NonBig` must be initialized inside its custom valid range
note: integers must be initialized (in this struct field) note: integers must be initialized (in this struct field)
--> $DIR/invalid_value.rs:23:26 --> $DIR/invalid_value.rs:22:26
| |
LL | pub(crate) struct NonBig(u64); LL | pub(crate) struct NonBig(u64);
| ^^^ | ^^^
error: the type `Fruit` does not permit being left uninitialized error: the type `Fruit` does not permit being left uninitialized
--> $DIR/invalid_value.rs:121:27 --> $DIR/invalid_value.rs:120:27
| |
LL | let _val: Fruit = mem::uninitialized(); LL | let _val: Fruit = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -493,13 +493,13 @@ LL | let _val: Fruit = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
| |
note: enums with multiple inhabited variants have to be initialized to a variant note: enums with multiple inhabited variants have to be initialized to a variant
--> $DIR/invalid_value.rs:26:1 --> $DIR/invalid_value.rs:25:1
| |
LL | enum Fruit { LL | enum Fruit {
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the type `[bool; 2]` does not permit being left uninitialized error: the type `[bool; 2]` does not permit being left uninitialized
--> $DIR/invalid_value.rs:124:31 --> $DIR/invalid_value.rs:123:31
| |
LL | let _val: [bool; 2] = mem::uninitialized(); LL | let _val: [bool; 2] = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -510,7 +510,7 @@ LL | let _val: [bool; 2] = mem::uninitialized();
= note: booleans must be either `true` or `false` = note: booleans must be either `true` or `false`
error: the type `i32` does not permit being left uninitialized error: the type `i32` does not permit being left uninitialized
--> $DIR/invalid_value.rs:127:25 --> $DIR/invalid_value.rs:126:25
| |
LL | let _val: i32 = mem::uninitialized(); LL | let _val: i32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -521,7 +521,7 @@ LL | let _val: i32 = mem::uninitialized();
= note: integers must be initialized = note: integers must be initialized
error: the type `f32` does not permit being left uninitialized error: the type `f32` does not permit being left uninitialized
--> $DIR/invalid_value.rs:130:25 --> $DIR/invalid_value.rs:129:25
| |
LL | let _val: f32 = mem::uninitialized(); LL | let _val: f32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -532,7 +532,7 @@ LL | let _val: f32 = mem::uninitialized();
= note: floats must be initialized = note: floats must be initialized
error: the type `*const ()` does not permit being left uninitialized error: the type `*const ()` does not permit being left uninitialized
--> $DIR/invalid_value.rs:133:31 --> $DIR/invalid_value.rs:132:31
| |
LL | let _val: *const () = mem::uninitialized(); LL | let _val: *const () = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -543,7 +543,7 @@ LL | let _val: *const () = mem::uninitialized();
= note: raw pointers must be initialized = note: raw pointers must be initialized
error: the type `*const [()]` does not permit being left uninitialized error: the type `*const [()]` does not permit being left uninitialized
--> $DIR/invalid_value.rs:136:33 --> $DIR/invalid_value.rs:135:33
| |
LL | let _val: *const [()] = mem::uninitialized(); LL | let _val: *const [()] = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -554,7 +554,7 @@ LL | let _val: *const [()] = mem::uninitialized();
= note: raw pointers must be initialized = note: raw pointers must be initialized
error: the type `WrapAroundRange` does not permit being left uninitialized error: the type `WrapAroundRange` does not permit being left uninitialized
--> $DIR/invalid_value.rs:139:37 --> $DIR/invalid_value.rs:138:37
| |
LL | let _val: WrapAroundRange = mem::uninitialized(); LL | let _val: WrapAroundRange = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -564,13 +564,13 @@ LL | let _val: WrapAroundRange = mem::uninitialized();
| |
= note: `WrapAroundRange` must be initialized inside its custom valid range = note: `WrapAroundRange` must be initialized inside its custom valid range
note: integers must be initialized (in this struct field) note: integers must be initialized (in this struct field)
--> $DIR/invalid_value.rs:49:35 --> $DIR/invalid_value.rs:48:35
| |
LL | pub(crate) struct WrapAroundRange(u8); LL | pub(crate) struct WrapAroundRange(u8);
| ^^ | ^^
error: the type `Result<i32, i32>` does not permit being left uninitialized error: the type `Result<i32, i32>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:144:38 --> $DIR/invalid_value.rs:143:38
| |
LL | let _val: Result<i32, i32> = mem::uninitialized(); LL | let _val: Result<i32, i32> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -582,7 +582,7 @@ note: enums with multiple inhabited variants have to be initialized to a variant
--> $SRC_DIR/core/src/result.rs:LL:COL --> $SRC_DIR/core/src/result.rs:LL:COL
error: the type `&i32` does not permit zero-initialization error: the type `&i32` does not permit zero-initialization
--> $DIR/invalid_value.rs:152:34 --> $DIR/invalid_value.rs:151:34
| |
LL | let _val: &'static i32 = mem::transmute(0usize); LL | let _val: &'static i32 = mem::transmute(0usize);
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
@ -593,7 +593,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize);
= note: references must be non-null = note: references must be non-null
error: the type `&[i32]` does not permit zero-initialization error: the type `&[i32]` does not permit zero-initialization
--> $DIR/invalid_value.rs:153:36 --> $DIR/invalid_value.rs:152:36
| |
LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -604,9 +604,9 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
= note: references must be non-null = note: references must be non-null
error: the type `NonZero<u32>` does not permit zero-initialization error: the type `NonZero<u32>` does not permit zero-initialization
--> $DIR/invalid_value.rs:154:32 --> $DIR/invalid_value.rs:153:34
| |
LL | let _val: NonZeroU32 = mem::transmute(0); LL | let _val: NonZero<u32> = mem::transmute(0);
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
| | | |
| this code causes undefined behavior when executed | this code causes undefined behavior when executed
@ -615,7 +615,7 @@ LL | let _val: NonZeroU32 = mem::transmute(0);
= note: `std::num::NonZero<u32>` must be non-null = note: `std::num::NonZero<u32>` must be non-null
error: the type `NonNull<i32>` does not permit zero-initialization error: the type `NonNull<i32>` does not permit zero-initialization
--> $DIR/invalid_value.rs:157:34 --> $DIR/invalid_value.rs:156:34
| |
LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init(); LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -626,7 +626,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init();
= note: `std::ptr::NonNull<i32>` must be non-null = note: `std::ptr::NonNull<i32>` must be non-null
error: the type `NonNull<i32>` does not permit being left uninitialized error: the type `NonNull<i32>` does not permit being left uninitialized
--> $DIR/invalid_value.rs:158:34 --> $DIR/invalid_value.rs:157:34
| |
LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init(); LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -638,7 +638,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
= note: raw pointers must be initialized = note: raw pointers must be initialized
error: the type `bool` does not permit being left uninitialized error: the type `bool` does not permit being left uninitialized
--> $DIR/invalid_value.rs:159:26 --> $DIR/invalid_value.rs:158:26
| |
LL | let _val: bool = MaybeUninit::uninit().assume_init(); LL | let _val: bool = MaybeUninit::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,7 +1,8 @@
#![feature(transparent_unions)]
#![feature(ptr_internals)]
#![deny(improper_ctypes)]
#![allow(dead_code)] #![allow(dead_code)]
#![deny(improper_ctypes)]
#![feature(generic_nonzero)]
#![feature(ptr_internals)]
#![feature(transparent_unions)]
use std::num; use std::num;
@ -67,26 +68,26 @@ extern "C" {
fn option_fn(x: Option<extern "C" fn()>); fn option_fn(x: Option<extern "C" fn()>);
fn nonnull(x: Option<std::ptr::NonNull<u8>>); fn nonnull(x: Option<std::ptr::NonNull<u8>>);
fn unique(x: Option<std::ptr::Unique<u8>>); fn unique(x: Option<std::ptr::Unique<u8>>);
fn nonzero_u8(x: Option<num::NonZeroU8>); fn nonzero_u8(x: Option<num::NonZero<u8>>);
fn nonzero_u16(x: Option<num::NonZeroU16>); fn nonzero_u16(x: Option<num::NonZero<u16>>);
fn nonzero_u32(x: Option<num::NonZeroU32>); fn nonzero_u32(x: Option<num::NonZero<u32>>);
fn nonzero_u64(x: Option<num::NonZeroU64>); fn nonzero_u64(x: Option<num::NonZero<u64>>);
fn nonzero_u128(x: Option<num::NonZeroU128>); fn nonzero_u128(x: Option<num::NonZero<u128>>);
//~^ ERROR `extern` block uses type `u128` //~^ ERROR `extern` block uses type `u128`
fn nonzero_usize(x: Option<num::NonZeroUsize>); fn nonzero_usize(x: Option<num::NonZero<usize>>);
fn nonzero_i8(x: Option<num::NonZeroI8>); fn nonzero_i8(x: Option<num::NonZero<i8>>);
fn nonzero_i16(x: Option<num::NonZeroI16>); fn nonzero_i16(x: Option<num::NonZero<i16>>);
fn nonzero_i32(x: Option<num::NonZeroI32>); fn nonzero_i32(x: Option<num::NonZero<i32>>);
fn nonzero_i64(x: Option<num::NonZeroI64>); fn nonzero_i64(x: Option<num::NonZero<i64>>);
fn nonzero_i128(x: Option<num::NonZeroI128>); fn nonzero_i128(x: Option<num::NonZero<i128>>);
//~^ ERROR `extern` block uses type `i128` //~^ ERROR `extern` block uses type `i128`
fn nonzero_isize(x: Option<num::NonZeroIsize>); fn nonzero_isize(x: Option<num::NonZero<isize>>);
fn transparent_struct(x: Option<TransparentStruct<num::NonZeroU8>>); fn transparent_struct(x: Option<TransparentStruct<num::NonZero<u8>>>);
fn transparent_enum(x: Option<TransparentEnum<num::NonZeroU8>>); fn transparent_enum(x: Option<TransparentEnum<num::NonZero<u8>>>);
fn transparent_union(x: Option<TransparentUnion<num::NonZeroU8>>); fn transparent_union(x: Option<TransparentUnion<num::NonZero<u8>>>);
//~^ ERROR `extern` block uses type //~^ ERROR `extern` block uses type
fn repr_rust(x: Option<Rust<num::NonZeroU8>>); //~ ERROR `extern` block uses type fn repr_rust(x: Option<Rust<num::NonZero<u8>>>); //~ ERROR `extern` block uses type
fn no_result(x: Result<(), num::NonZeroI32>); //~ ERROR `extern` block uses type fn no_result(x: Result<(), num::NonZero<i32>>); //~ ERROR `extern` block uses type
} }
pub fn main() {} pub fn main() {}

View File

@ -1,5 +1,5 @@
error: `extern` block uses type `U`, which is not FFI-safe error: `extern` block uses type `U`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:60:13 --> $DIR/lint-ctypes-enum.rs:61:13
| |
LL | fn uf(x: U); LL | fn uf(x: U);
| ^ not FFI-safe | ^ not FFI-safe
@ -7,18 +7,18 @@ LL | fn uf(x: U);
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint
note: the type is defined here note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:9:1 --> $DIR/lint-ctypes-enum.rs:10:1
| |
LL | enum U { LL | enum U {
| ^^^^^^ | ^^^^^^
note: the lint level is defined here note: the lint level is defined here
--> $DIR/lint-ctypes-enum.rs:3:9 --> $DIR/lint-ctypes-enum.rs:2:9
| |
LL | #![deny(improper_ctypes)] LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
error: `extern` block uses type `B`, which is not FFI-safe error: `extern` block uses type `B`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:61:13 --> $DIR/lint-ctypes-enum.rs:62:13
| |
LL | fn bf(x: B); LL | fn bf(x: B);
| ^ not FFI-safe | ^ not FFI-safe
@ -26,13 +26,13 @@ LL | fn bf(x: B);
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint
note: the type is defined here note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:12:1 --> $DIR/lint-ctypes-enum.rs:13:1
| |
LL | enum B { LL | enum B {
| ^^^^^^ | ^^^^^^
error: `extern` block uses type `T`, which is not FFI-safe error: `extern` block uses type `T`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:62:13 --> $DIR/lint-ctypes-enum.rs:63:13
| |
LL | fn tf(x: T); LL | fn tf(x: T);
| ^ not FFI-safe | ^ not FFI-safe
@ -40,50 +40,50 @@ LL | fn tf(x: T);
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint
note: the type is defined here note: the type is defined here
--> $DIR/lint-ctypes-enum.rs:16:1 --> $DIR/lint-ctypes-enum.rs:17:1
| |
LL | enum T { LL | enum T {
| ^^^^^^ | ^^^^^^
error: `extern` block uses type `u128`, which is not FFI-safe error: `extern` block uses type `u128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:74:23 --> $DIR/lint-ctypes-enum.rs:75:23
| |
LL | fn nonzero_u128(x: Option<num::NonZeroU128>); LL | fn nonzero_u128(x: Option<num::NonZero<u128>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
| |
= note: 128-bit integers don't currently have a known stable ABI = note: 128-bit integers don't currently have a known stable ABI
error: `extern` block uses type `i128`, which is not FFI-safe error: `extern` block uses type `i128`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:81:23 --> $DIR/lint-ctypes-enum.rs:82:23
| |
LL | fn nonzero_i128(x: Option<num::NonZeroI128>); LL | fn nonzero_i128(x: Option<num::NonZero<i128>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
| |
= note: 128-bit integers don't currently have a known stable ABI = note: 128-bit integers don't currently have a known stable ABI
error: `extern` block uses type `Option<TransparentUnion<NonZero<u8>>>`, which is not FFI-safe error: `extern` block uses type `Option<TransparentUnion<NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:86:28 --> $DIR/lint-ctypes-enum.rs:87:28
| |
LL | fn transparent_union(x: Option<TransparentUnion<num::NonZeroU8>>); LL | fn transparent_union(x: Option<TransparentUnion<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
| |
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint
error: `extern` block uses type `Option<Rust<NonZero<u8>>>`, which is not FFI-safe error: `extern` block uses type `Option<Rust<NonZero<u8>>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:88:20 --> $DIR/lint-ctypes-enum.rs:89:20
| |
LL | fn repr_rust(x: Option<Rust<num::NonZeroU8>>); LL | fn repr_rust(x: Option<Rust<num::NonZero<u8>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
| |
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint
error: `extern` block uses type `Result<(), NonZero<i32>>`, which is not FFI-safe error: `extern` block uses type `Result<(), NonZero<i32>>`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:89:20 --> $DIR/lint-ctypes-enum.rs:90:20
| |
LL | fn no_result(x: Result<(), num::NonZeroI32>); LL | fn no_result(x: Result<(), num::NonZero<i32>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
| |
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint = note: enum has no representation hint

View File

@ -2,11 +2,11 @@
//@ error-pattern:attempt to negate with overflow //@ error-pattern:attempt to negate with overflow
//@ ignore-emscripten no processes //@ ignore-emscripten no processes
//@ compile-flags: -C debug-assertions //@ compile-flags: -C debug-assertions
#![allow(arithmetic_overflow)] #![allow(arithmetic_overflow)]
#![feature(generic_nonzero)]
use std::num::NonZeroI8; use std::num::NonZero;
fn main() { fn main() {
let _x = -NonZeroI8::new(i8::MIN).unwrap(); let _x = -NonZero::new(i8::MIN).unwrap();
} }

View File

@ -1,24 +1,24 @@
//! This file illustrates how niche-filling enums are handled,
//! modelled after cases like `Option<&u32>`, `Option<bool>` and such.
//!
//! It uses `NonZero<u32>` rather than `&_` or `Unique<_>`, because
//! the test is not set up to deal with target-dependent pointer width.
//!
//! It avoids using `u64`/`i64` because on some targets that is only 4-byte
//! aligned (while on most it is 8-byte aligned) and so the resulting
//! padding and overall computed sizes can be quite different.
//!
//@ compile-flags: -Z print-type-sizes --crate-type lib //@ compile-flags: -Z print-type-sizes --crate-type lib
//@ ignore-debug: debug assertions will print more types //@ ignore-debug: debug assertions will print more types
//@ build-pass //@ build-pass
//@ ignore-pass //@ ignore-pass
// ^-- needed because `--pass check` does not emit the output needed. // ^-- needed because `--pass check` does not emit the output needed.
// FIXME: consider using an attribute instead of side-effects. // FIXME: consider using an attribute instead of side-effects.
// This file illustrates how niche-filling enums are handled,
// modelled after cases like `Option<&u32>`, `Option<bool>` and such.
//
// It uses NonZeroU32 rather than `&_` or `Unique<_>`, because
// the test is not set up to deal with target-dependent pointer width.
//
// It avoids using u64/i64 because on some targets that is only 4-byte
// aligned (while on most it is 8-byte aligned) and so the resulting
// padding and overall computed sizes can be quite different.
#![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]
#![feature(generic_nonzero)]
#![feature(rustc_attrs)]
use std::num::NonZeroU32; use std::num::NonZero;
pub enum MyOption<T> { None, Some(T) } pub enum MyOption<T> { None, Some(T) }
@ -34,7 +34,7 @@ impl<T> Default for MyOption<T> {
pub enum EmbeddedDiscr { pub enum EmbeddedDiscr {
None, None,
Record { pre: u8, val: NonZeroU32, post: u16 }, Record { pre: u8, val: NonZero<u32>, post: u16 },
} }
impl Default for EmbeddedDiscr { impl Default for EmbeddedDiscr {
@ -50,13 +50,13 @@ pub struct IndirectNonZero {
pub struct NestedNonZero { pub struct NestedNonZero {
pre: u8, pre: u8,
val: NonZeroU32, val: NonZero<u32>,
post: u16, post: u16,
} }
impl Default for NestedNonZero { impl Default for NestedNonZero {
fn default() -> Self { fn default() -> Self {
NestedNonZero { pre: 0, val: unsafe { NonZeroU32::new_unchecked(1) }, post: 0 } NestedNonZero { pre: 0, val: unsafe { NonZero::new_unchecked(1) }, post: 0 }
} }
} }
@ -77,7 +77,7 @@ pub union Union2<A: Copy, B: Copy> {
} }
pub fn test() { pub fn test() {
let _x: MyOption<NonZeroU32> = Default::default(); let _x: MyOption<NonZero<u32>> = Default::default();
let _y: EmbeddedDiscr = Default::default(); let _y: EmbeddedDiscr = Default::default();
let _z: MyOption<IndirectNonZero> = Default::default(); let _z: MyOption<IndirectNonZero> = Default::default();
let _a: MyOption<bool> = Default::default(); let _a: MyOption<bool> = Default::default();
@ -90,9 +90,9 @@ pub fn test() {
let _h: MyOption<MyNotNegativeOne> = Default::default(); let _h: MyOption<MyNotNegativeOne> = Default::default();
// Unions do not currently participate in niche filling. // Unions do not currently participate in niche filling.
let _i: MyOption<Union2<NonZeroU32, u32>> = Default::default(); let _i: MyOption<Union2<NonZero<u32>, u32>> = Default::default();
// ...even when theoretically possible. // ...even when theoretically possible.
let _j: MyOption<Union1<NonZeroU32>> = Default::default(); let _j: MyOption<Union1<NonZero<u32>>> = Default::default();
let _k: MyOption<Union2<NonZeroU32, NonZeroU32>> = Default::default(); let _k: MyOption<Union2<NonZero<u32>, NonZero<u32>>> = Default::default();
} }

View File

@ -1,8 +1,9 @@
//@ run-pass //@ run-pass
#![feature(generic_nonzero)]
#![feature(transparent_unions)] #![feature(transparent_unions)]
use std::mem::size_of; use std::mem::size_of;
use std::num::NonZeroUsize; use std::num::NonZero;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
@ -57,7 +58,7 @@ fn main() {
assert_eq!(size_of::<[Box<isize>; 1]>(), size_of::<Option<[Box<isize>; 1]>>()); assert_eq!(size_of::<[Box<isize>; 1]>(), size_of::<Option<[Box<isize>; 1]>>());
// Should apply to NonZero // Should apply to NonZero
assert_eq!(size_of::<NonZeroUsize>(), size_of::<Option<NonZeroUsize>>()); assert_eq!(size_of::<NonZero<usize>>(), size_of::<Option<NonZero<usize>>>());
assert_eq!(size_of::<NonNull<i8>>(), size_of::<Option<NonNull<i8>>>()); assert_eq!(size_of::<NonNull<i8>>(), size_of::<Option<NonNull<i8>>>());
// Should apply to types that use NonZero internally // Should apply to types that use NonZero internally

View File

@ -1,5 +1,5 @@
warning: method `dummy` is never used warning: method `dummy` is never used
--> $DIR/enum-null-pointer-opt.rs:10:18 --> $DIR/enum-null-pointer-opt.rs:11:18
| |
LL | trait Trait { fn dummy(&self) { } } LL | trait Trait { fn dummy(&self) { } }
| ----- ^^^^^ | ----- ^^^^^

View File

@ -2,12 +2,13 @@
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(dead_code)] #![allow(dead_code)]
#![feature(generic_nonzero)]
#![feature(never_type)] #![feature(never_type)]
#![feature(pointer_is_aligned)] #![feature(pointer_is_aligned)]
#![feature(strict_provenance)] #![feature(strict_provenance)]
use std::mem::size_of; use std::mem::size_of;
use std::num::{NonZeroU8, NonZeroU16}; use std::num::NonZero;
use std::ptr; use std::ptr;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::borrow::Cow; use std::borrow::Cow;
@ -110,14 +111,14 @@ enum Option2<A, B> {
// Two layouts are considered for `CanBeNicheFilledButShouldnt`: // Two layouts are considered for `CanBeNicheFilledButShouldnt`:
// Niche-filling: // Niche-filling:
// { u32 (4 bytes), NonZeroU8 + tag in niche (1 byte), padding (3 bytes) } // { u32 (4 bytes), NonZero<u8> + tag in niche (1 byte), padding (3 bytes) }
// Tagged: // Tagged:
// { tag (1 byte), NonZeroU8 (1 byte), padding (2 bytes), u32 (4 bytes) } // { tag (1 byte), NonZero<u8> (1 byte), padding (2 bytes), u32 (4 bytes) }
// Both are the same size (due to padding), // Both are the same size (due to padding),
// but the tagged layout is better as the tag creates a niche with 254 invalid values, // but the tagged layout is better as the tag creates a niche with 254 invalid values,
// allowing types like `Option<Option<CanBeNicheFilledButShouldnt>>` to fit into 8 bytes. // allowing types like `Option<Option<CanBeNicheFilledButShouldnt>>` to fit into 8 bytes.
pub enum CanBeNicheFilledButShouldnt { pub enum CanBeNicheFilledButShouldnt {
A(NonZeroU8, u32), A(NonZero<u8>, u32),
B B
} }
pub enum AlwaysTaggedBecauseItHasNoNiche { pub enum AlwaysTaggedBecauseItHasNoNiche {
@ -135,7 +136,7 @@ pub enum NicheFilledMultipleFields {
G, G,
} }
struct BoolInTheMiddle(std::num::NonZeroU16, bool, u8); struct BoolInTheMiddle(NonZero<u16>, bool, u8);
enum NicheWithData { enum NicheWithData {
A, A,
@ -275,7 +276,7 @@ pub fn main() {
assert_eq!(size_of::<Option<NicheFilledMultipleFields>>(), 2); assert_eq!(size_of::<Option<NicheFilledMultipleFields>>(), 2);
assert_eq!(size_of::<Option<Option<NicheFilledMultipleFields>>>(), 2); assert_eq!(size_of::<Option<Option<NicheFilledMultipleFields>>>(), 2);
struct S1{ a: u16, b: std::num::NonZeroU16, c: u16, d: u8, e: u32, f: u64, g:[u8;2] } struct S1{ a: u16, b: NonZero<u16>, c: u16, d: u8, e: u32, f: u64, g:[u8;2] }
assert_eq!(size_of::<S1>(), 24); assert_eq!(size_of::<S1>(), 24);
assert_eq!(size_of::<Option<S1>>(), 24); assert_eq!(size_of::<Option<S1>>(), 24);
@ -287,14 +288,14 @@ pub fn main() {
size_of::<(&(), NicheWithData)>() size_of::<(&(), NicheWithData)>()
); );
pub enum FillPadding { A(std::num::NonZeroU8, u32), B } pub enum FillPadding { A(NonZero<u8>, u32), B }
assert_eq!(size_of::<FillPadding>(), 8); assert_eq!(size_of::<FillPadding>(), 8);
assert_eq!(size_of::<Option<FillPadding>>(), 8); assert_eq!(size_of::<Option<FillPadding>>(), 8);
assert_eq!(size_of::<Option<Option<FillPadding>>>(), 8); assert_eq!(size_of::<Option<Option<FillPadding>>>(), 8);
assert_eq!(size_of::<Result<(std::num::NonZeroU8, u8, u8), u16>>(), 4); assert_eq!(size_of::<Result<(NonZero<u8>, u8, u8), u16>>(), 4);
assert_eq!(size_of::<Option<Result<(std::num::NonZeroU8, u8, u8), u16>>>(), 4); assert_eq!(size_of::<Option<Result<(NonZero<u8>, u8, u8), u16>>>(), 4);
assert_eq!(size_of::<Result<(std::num::NonZeroU8, u8, u8, u8), u16>>(), 4); assert_eq!(size_of::<Result<(NonZero<u8>, u8, u8, u8), u16>>(), 4);
assert_eq!(size_of::<EnumManyVariant<u16>>(), 6); assert_eq!(size_of::<EnumManyVariant<u16>>(), 6);
assert_eq!(size_of::<EnumManyVariant<NicheU16>>(), 4); assert_eq!(size_of::<EnumManyVariant<NicheU16>>(), 4);
@ -314,10 +315,10 @@ pub fn main() {
assert_eq!(ptr::from_ref(&v), ptr::from_ref(&v.r.ptr).cast(), assert_eq!(ptr::from_ref(&v), ptr::from_ref(&v.r.ptr).cast(),
"sort niches to the front where possible"); "sort niches to the front where possible");
// Ideal layouts: (bool, u8, NonZeroU16) or (NonZeroU16, u8, bool) // Ideal layouts: (bool, u8, NonZero<u16>) or (NonZero<u16>, u8, bool)
// Currently the layout algorithm will choose the latter because it doesn't attempt // Currently the layout algorithm will choose the latter because it doesn't attempt
// to aggregate multiple smaller fields to move a niche before a higher-alignment one. // to aggregate multiple smaller fields to move a niche before a higher-alignment one.
let b = BoolInTheMiddle( NonZeroU16::new(1).unwrap(), true, 0); let b = BoolInTheMiddle(NonZero::new(1).unwrap(), true, 0);
assert!(ptr::from_ref(&b.1).addr() > ptr::from_ref(&b.2).addr()); assert!(ptr::from_ref(&b.1).addr() > ptr::from_ref(&b.2).addr());
assert_eq!(size_of::<Cow<'static, str>>(), size_of::<String>()); assert_eq!(size_of::<Cow<'static, str>>(), size_of::<String>());

View File

@ -1,10 +1,11 @@
//@ edition:2018 //@ edition:2018
//
// This is a regression test for #83564. // This is a regression test for #83564.
// For some reason, Rust 2018 or higher is required to reproduce the bug. // For some reason, Rust 2018 or higher is required to reproduce the bug.
#![feature(generic_nonzero)]
fn main() { fn main() {
//~^ HELP consider importing one of these items //~^ HELP consider importing one of these items
let _x = NonZeroU32::new(5).unwrap(); let _x = NonZero::new(5u32).unwrap();
//~^ ERROR failed to resolve: use of undeclared type `NonZeroU32` //~^ ERROR failed to resolve: use of undeclared type `NonZero`
} }

View File

@ -1,14 +1,14 @@
error[E0433]: failed to resolve: use of undeclared type `NonZeroU32` error[E0433]: failed to resolve: use of undeclared type `NonZero`
--> $DIR/core-std-import-order-issue-83564.rs:8:14 --> $DIR/core-std-import-order-issue-83564.rs:9:14
| |
LL | let _x = NonZeroU32::new(5).unwrap(); LL | let _x = NonZero::new(5u32).unwrap();
| ^^^^^^^^^^ use of undeclared type `NonZeroU32` | ^^^^^^^ use of undeclared type `NonZero`
| |
help: consider importing one of these items help: consider importing one of these items
| |
LL + use core::num::NonZeroU32; LL + use core::num::NonZero;
| |
LL + use std::num::NonZeroU32; LL + use std::num::NonZero;
| |
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -1,6 +1,6 @@
//@ compile-flags: -Znext-solver //@ compile-flags: -Znext-solver
//~^ ERROR cannot normalize `<T as Default>::Id: '_` //~^ ERROR cannot normalize `<T as Default>::Id: '_`
#![feature(generic_nonzero)]
#![feature(specialization)] #![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete //~^ WARN the feature `specialization` is incomplete
@ -23,8 +23,9 @@ fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U {
*t.intu() *t.intu()
} }
use std::num::NonZeroU8; use std::num::NonZero;
fn main() { fn main() {
let s = transmute::<u8, Option<NonZeroU8>>(0); //~ ERROR cannot satisfy let s = transmute::<u8, Option<NonZero<u8>>>(0); //~ ERROR cannot satisfy
assert_eq!(s, None); assert_eq!(s, None);
} }

View File

@ -23,10 +23,10 @@ LL | self
| ^^^^ cannot satisfy `T <: <T as Default>::Id` | ^^^^ cannot satisfy `T <: <T as Default>::Id`
error[E0284]: type annotations needed: cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>` error[E0284]: type annotations needed: cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>`
--> $DIR/specialization-transmute.rs:28:13 --> $DIR/specialization-transmute.rs:29:13
| |
LL | let s = transmute::<u8, Option<NonZeroU8>>(0); LL | let s = transmute::<u8, Option<NonZero<u8>>>(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<u8 as Default>::Id == Option<NonZero<u8>>`
| |
note: required by a bound in `transmute` note: required by a bound in `transmute`
--> $DIR/specialization-transmute.rs:22:25 --> $DIR/specialization-transmute.rs:22:25