From b2fbb8a05392be976c67e3b0063203d5b049da5c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 22 Feb 2024 14:59:52 +0100 Subject: [PATCH] Use generic `NonZero` in tests. --- tests/codegen/array-equality.rs | 4 +- tests/codegen/enum/enum-debug-niche-2.rs | 17 +- tests/codegen/function-arguments.rs | 8 +- tests/codegen/intrinsics/transmute-niched.rs | 6 +- tests/codegen/issues/issue-119422.rs | 22 +-- tests/codegen/loads.rs | 8 +- tests/codegen/option-as-slice.rs | 9 +- tests/codegen/option-nonzero-eq.rs | 8 +- tests/codegen/slice-ref-equality.rs | 8 +- tests/codegen/transmute-optimized.rs | 6 +- tests/debuginfo/msvc-pretty-enums.rs | 80 ++++---- tests/debuginfo/numeric-types.rs | 28 +-- .../instsimplify/combine_transmutes.rs | 4 +- tests/rustdoc/type-layout.rs | 2 +- tests/ui/abi/compatibility.rs | 9 +- .../consts/const-eval/raw-bytes.32bit.stderr | 114 +++++------ .../consts/const-eval/raw-bytes.64bit.stderr | 114 +++++------ tests/ui/consts/const-eval/raw-bytes.rs | 9 +- tests/ui/consts/const-eval/ub-nonnull.rs | 10 +- tests/ui/consts/const-eval/ub-nonnull.stderr | 14 +- tests/ui/consts/const-eval/valid-const.rs | 9 +- tests/ui/consts/ice-48279.rs | 2 +- tests/ui/consts/tuple-struct-constructors.rs | 7 +- .../intrinsics/panic-uninitialized-zeroed.rs | 12 +- tests/ui/issues/issue-64593.rs | 3 +- tests/ui/layout/unsafe-cell-hides-niche.rs | 28 +-- .../ui/layout/zero-sized-array-enum-niche.rs | 5 +- .../layout/zero-sized-array-enum-niche.stderr | 10 +- tests/ui/lint/clashing-extern-fn.rs | 33 ++-- tests/ui/lint/clashing-extern-fn.stderr | 50 ++--- tests/ui/lint/invalid_value.rs | 13 +- tests/ui/lint/invalid_value.stderr | 186 +++++++++--------- tests/ui/lint/lint-ctypes-enum.rs | 41 ++-- tests/ui/lint/lint-ctypes-enum.stderr | 44 ++--- .../overflowing-neg-nonzero.rs | 6 +- tests/ui/print_type_sizes/niche-filling.rs | 44 ++--- .../ui/structs-enums/enum-null-pointer-opt.rs | 5 +- .../enum-null-pointer-opt.stderr | 2 +- tests/ui/structs-enums/type-sizes.rs | 25 +-- .../core-std-import-order-issue-83564.rs | 7 +- .../core-std-import-order-issue-83564.stderr | 12 +- .../next-solver/specialization-transmute.rs | 7 +- .../specialization-transmute.stderr | 6 +- 43 files changed, 520 insertions(+), 517 deletions(-) diff --git a/tests/codegen/array-equality.rs b/tests/codegen/array-equality.rs index 9435422888634..5b85da1d4a0c5 100644 --- a/tests/codegen/array-equality.rs +++ b/tests/codegen/array-equality.rs @@ -1,7 +1,7 @@ //@ compile-flags: -O -Z merge-functions=disabled //@ only-x86_64 - #![crate_type = "lib"] +#![feature(generic_nonzero)] // CHECK-LABEL: @array_eq_value #[no_mangle] @@ -63,7 +63,7 @@ pub fn array_eq_zero_short(x: [u16; 3]) -> bool { // CHECK-LABEL: @array_eq_none_short(i40 #[no_mangle] -pub fn array_eq_none_short(x: [Option; 5]) -> bool { +pub fn array_eq_none_short(x: [Option>; 5]) -> bool { // CHECK-NEXT: start: // CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0 // CHECK-NEXT: ret i1 %[[EQ]] diff --git a/tests/codegen/enum/enum-debug-niche-2.rs b/tests/codegen/enum/enum-debug-niche-2.rs index 4315741e0bdd9..25871885e7ea9 100644 --- a/tests/codegen/enum/enum-debug-niche-2.rs +++ b/tests/codegen/enum/enum-debug-niche-2.rs @@ -1,20 +1,17 @@ -// 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. - -// -//@ ignore-msvc - +//! 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. +//! //@ compile-flags: -g -C no-prepopulate-passes - +//@ ignore-msvc +// // 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: "Error",{{.*}}extraData: i128 0{{[,)].*}} - -#![feature(never_type)] +#![feature(generic_nonzero, never_type)] #[derive(Copy, Clone)] pub struct Entity { - private: std::num::NonZeroU32, + private: std::num::NonZero, } #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/tests/codegen/function-arguments.rs b/tests/codegen/function-arguments.rs index 88cedcf46b696..b75c188f51a9b 100644 --- a/tests/codegen/function-arguments.rs +++ b/tests/codegen/function-arguments.rs @@ -1,10 +1,10 @@ //@ compile-flags: -O -C no-prepopulate-passes - #![crate_type = "lib"] #![feature(dyn_star)] +#![feature(generic_nonzero)] use std::mem::MaybeUninit; -use std::num::NonZeroU64; +use std::num::NonZero; use std::marker::PhantomPinned; use std::ptr::NonNull; @@ -70,13 +70,13 @@ pub fn int(x: u64) -> u64 { // CHECK: noundef i64 @nonzero_int(i64 noundef %x) #[no_mangle] -pub fn nonzero_int(x: NonZeroU64) -> NonZeroU64 { +pub fn nonzero_int(x: NonZero) -> NonZero { x } // CHECK: noundef i64 @option_nonzero_int(i64 noundef %x) #[no_mangle] -pub fn option_nonzero_int(x: Option) -> Option { +pub fn option_nonzero_int(x: Option>) -> Option> { x } diff --git a/tests/codegen/intrinsics/transmute-niched.rs b/tests/codegen/intrinsics/transmute-niched.rs index 7c448c82e4b24..b5e0da1b2f5f6 100644 --- a/tests/codegen/intrinsics/transmute-niched.rs +++ b/tests/codegen/intrinsics/transmute-niched.rs @@ -2,11 +2,11 @@ //@ [OPT] compile-flags: -C opt-level=3 -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) - #![crate_type = "lib"] +#![feature(generic_nonzero)] use std::mem::transmute; -use std::num::NonZeroU32; +use std::num::NonZero; #[repr(u8)] pub enum SmallEnum { @@ -130,7 +130,7 @@ pub unsafe fn check_enum_to_char(x: Minus100ToPlus100) -> char { // CHECK-LABEL: @check_swap_pair( #[no_mangle] -pub unsafe fn check_swap_pair(x: (char, NonZeroU32)) -> (NonZeroU32, char) { +pub unsafe fn check_swap_pair(x: (char, NonZero)) -> (NonZero, char) { // OPT: %0 = icmp ule i32 %x.0, 1114111 // OPT: call void @llvm.assume(i1 %0) // OPT: %1 = icmp uge i32 %x.0, 1 diff --git a/tests/codegen/issues/issue-119422.rs b/tests/codegen/issues/issue-119422.rs index 937fdcf28f5d6..19480b4dc9e11 100644 --- a/tests/codegen/issues/issue-119422.rs +++ b/tests/codegen/issues/issue-119422.rs @@ -1,13 +1,13 @@ //! 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 //@ only-64bit (because the LLVM type of i64 for usize shows up) - #![crate_type = "lib"] +#![feature(generic_nonzero)] -use core::num::*; use core::ptr::NonNull; +use core::num::NonZero; // CHECK-LABEL: @check_non_null #[no_mangle] @@ -18,7 +18,7 @@ pub fn check_non_null(x: NonNull) -> bool { // CHECK-LABEL: @equals_zero_is_false_u8 #[no_mangle] -pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool { +pub fn equals_zero_is_false_u8(x: NonZero) -> bool { // CHECK-NOT: br // CHECK: ret i1 false // 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 #[no_mangle] -pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool { +pub fn not_equals_zero_is_true_u8(x: NonZero) -> bool { // CHECK-NOT: br // CHECK: ret i1 true // 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 #[no_mangle] -pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool { +pub fn equals_zero_is_false_i8(x: NonZero) -> bool { // CHECK-NOT: br // CHECK: ret i1 false // 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 #[no_mangle] -pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool { +pub fn not_equals_zero_is_true_i8(x: NonZero) -> bool { // CHECK-NOT: br // CHECK: ret i1 true // CHECK-NOT: br @@ -54,7 +54,7 @@ pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool { // CHECK-LABEL: @usize_try_from_u32 #[no_mangle] -pub fn usize_try_from_u32(x: NonZeroU32) -> NonZeroUsize { +pub fn usize_try_from_u32(x: NonZero) -> NonZero { // CHECK-NOT: br // CHECK: zext i32 %{{.*}} to i64 // CHECK-NOT: br @@ -64,7 +64,7 @@ pub fn usize_try_from_u32(x: NonZeroU32) -> NonZeroUsize { // CHECK-LABEL: @isize_try_from_i32 #[no_mangle] -pub fn isize_try_from_i32(x: NonZeroI32) -> NonZeroIsize { +pub fn isize_try_from_i32(x: NonZero) -> NonZero { // CHECK-NOT: br // CHECK: sext i32 %{{.*}} to i64 // CHECK-NOT: br @@ -74,7 +74,7 @@ pub fn isize_try_from_i32(x: NonZeroI32) -> NonZeroIsize { // CHECK-LABEL: @u64_from_nonzero_is_not_zero #[no_mangle] -pub fn u64_from_nonzero_is_not_zero(x: NonZeroU64)->bool { +pub fn u64_from_nonzero_is_not_zero(x: NonZero)->bool { // CHECK-NOT: br // CHECK: ret i1 false // CHECK-NOT: br diff --git a/tests/codegen/loads.rs b/tests/codegen/loads.rs index 0471d83c25a38..b86b3dd3a1967 100644 --- a/tests/codegen/loads.rs +++ b/tests/codegen/loads.rs @@ -1,9 +1,9 @@ //@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0 - #![crate_type = "lib"] +#![feature(generic_nonzero)] use std::mem::MaybeUninit; -use std::num::NonZeroU16; +use std::num::NonZero; pub struct Bytes { a: u8, @@ -99,14 +99,14 @@ pub fn load_int(x: &u16) -> u16 { // CHECK-LABEL: @load_nonzero_int #[no_mangle] -pub fn load_nonzero_int(x: &NonZeroU16) -> NonZeroU16 { +pub fn load_nonzero_int(x: &NonZero) -> NonZero { // CHECK: load i16, ptr %x, align 2, !range ![[NONZEROU16_RANGE:[0-9]+]], !noundef !{{[0-9]+}} *x } // CHECK-LABEL: @load_option_nonzero_int #[no_mangle] -pub fn load_option_nonzero_int(x: &Option) -> Option { +pub fn load_option_nonzero_int(x: &Option>) -> Option> { // CHECK: load i16, ptr %x, align 2, !noundef ![[NOUNDEF]]{{$}} *x } diff --git a/tests/codegen/option-as-slice.rs b/tests/codegen/option-as-slice.rs index 990ec1d1f66be..14a3924360786 100644 --- a/tests/codegen/option-as-slice.rs +++ b/tests/codegen/option-as-slice.rs @@ -1,14 +1,13 @@ //@ compile-flags: -O -Z randomize-layout=no //@ only-x86_64 //@ 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"] -#![feature(option_as_slice)] +#![feature(generic_nonzero)] extern crate core; -use core::num::NonZeroU64; +use core::num::NonZero; use core::option::Option; // CHECK-LABEL: @u64_opt_as_slice @@ -23,7 +22,7 @@ pub fn u64_opt_as_slice(o: &Option) -> &[u64] { // CHECK-LABEL: @nonzero_u64_opt_as_slice #[no_mangle] -pub fn nonzero_u64_opt_as_slice(o: &Option) -> &[NonZeroU64] { +pub fn nonzero_u64_opt_as_slice(o: &Option>) -> &[NonZero] { // CHECK-NOT: select // CHECK-NOT: br // CHECK-NOT: switch diff --git a/tests/codegen/option-nonzero-eq.rs b/tests/codegen/option-nonzero-eq.rs index f6be90a5ddeb5..f637b1aef9757 100644 --- a/tests/codegen/option-nonzero-eq.rs +++ b/tests/codegen/option-nonzero-eq.rs @@ -1,18 +1,18 @@ //@ compile-flags: -O -Zmerge-functions=disabled - #![crate_type = "lib"] +#![feature(generic_nonzero)] extern crate core; use core::cmp::Ordering; -use core::num::{NonZeroU32, NonZeroI64}; use core::ptr::NonNull; +use core::num::NonZero; // 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. // CHECK-lABEL: @non_zero_eq #[no_mangle] -pub fn non_zero_eq(l: Option, r: Option) -> bool { +pub fn non_zero_eq(l: Option>, r: Option>) -> bool { // CHECK: start: // CHECK-NEXT: icmp eq i32 // CHECK-NEXT: ret i1 @@ -21,7 +21,7 @@ pub fn non_zero_eq(l: Option, r: Option) -> bool { // CHECK-lABEL: @non_zero_signed_eq #[no_mangle] -pub fn non_zero_signed_eq(l: Option, r: Option) -> bool { +pub fn non_zero_signed_eq(l: Option>, r: Option>) -> bool { // CHECK: start: // CHECK-NEXT: icmp eq i64 // CHECK-NEXT: ret i1 diff --git a/tests/codegen/slice-ref-equality.rs b/tests/codegen/slice-ref-equality.rs index 371e685ec6c92..85d9c34a30b5a 100644 --- a/tests/codegen/slice-ref-equality.rs +++ b/tests/codegen/slice-ref-equality.rs @@ -1,8 +1,8 @@ //@ compile-flags: -O -Zmerge-functions=disabled - #![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. // 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]] noundef %3 #[no_mangle] -fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool { +fn eq_slice_of_nonzero(x: &[NonZero], y: &[NonZero]) -> bool { // CHECK: icmp eq [[USIZE]] %1, %3 // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2 // 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]] noundef %3 #[no_mangle] -fn eq_slice_of_option_of_nonzero(x: &[Option], y: &[Option]) -> bool { +fn eq_slice_of_option_of_nonzero(x: &[Option>], y: &[Option>]) -> bool { // CHECK: icmp eq [[USIZE]] %1, %3 // CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1 // CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr diff --git a/tests/codegen/transmute-optimized.rs b/tests/codegen/transmute-optimized.rs index 9217def76b519..1a5f53e625ae5 100644 --- a/tests/codegen/transmute-optimized.rs +++ b/tests/codegen/transmute-optimized.rs @@ -1,6 +1,6 @@ //@ compile-flags: -O -Z merge-functions=disabled - #![crate_type = "lib"] +#![feature(generic_nonzero)] // This tests that LLVM can optimize based on the niches in the source or // destination types for transmutes. @@ -33,7 +33,7 @@ pub fn non_null_is_null(x: std::ptr::NonNull) -> bool { // CHECK-LABEL: i1 @non_zero_is_null( #[no_mangle] -pub fn non_zero_is_null(x: std::num::NonZeroUsize) -> bool { +pub fn non_zero_is_null(x: std::num::NonZero) -> bool { // CHECK: ret i1 false let p: *const i32 = unsafe { std::mem::transmute(x) }; p.is_null() @@ -72,7 +72,7 @@ pub fn normal_div(a: u32, b: u32) -> u32 { // CHECK-LABEL: i32 @div_transmute_nonzero(i32 #[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) -> u32 { // CHECK-NOT: call core::panicking::panic // CHECK: %[[R:.+]] = udiv i32 %a, %b // CHECK-NEXT: ret i32 %[[R]] diff --git a/tests/debuginfo/msvc-pretty-enums.rs b/tests/debuginfo/msvc-pretty-enums.rs index c6dd9f7939df4..cfac14a22c418 100644 --- a/tests/debuginfo/msvc-pretty-enums.rs +++ b/tests/debuginfo/msvc-pretty-enums.rs @@ -1,143 +1,143 @@ //@ only-cdb //@ compile-flags:-g - +// // cdb-command: g - +// // cdb-command: dx a // cdb-check:a : Some [Type: enum2$ >] // cdb-check: [+0x000] __0 : Low (0x2) [Type: msvc_pretty_enums::CStyleEnum] - +// // cdb-command: dx b // cdb-check:b : None [Type: enum2$ >] - +// // cdb-command: dx c // cdb-check:c : Tag1 [Type: enum2$] - +// // cdb-command: dx d // cdb-check:d : Data [Type: enum2$] // cdb-check: [+0x000] my_data : High (0x10) [Type: msvc_pretty_enums::CStyleEnum] - +// // cdb-command: dx e // cdb-check:e : Tag2 [Type: enum2$] - +// // cdb-command: dx f // cdb-check:f : Some [Type: enum2$ > >] // cdb-check: [+0x000] __0 : 0x[...] : 0x1 [Type: unsigned int *] - +// // cdb-command: dx g // cdb-check:g : None [Type: enum2$ > >] - +// // cdb-command: dx h // cdb-check:h : Some [Type: enum2$ >] // cdb-check: [+0x004] __0 : 0xc [Type: unsigned int] - +// // cdb-command: dx i // cdb-check:i : None [Type: enum2$ >] - +// // cdb-command: dx j // cdb-check:j : High (0x10) [Type: msvc_pretty_enums::CStyleEnum] - +// // cdb-command: dx k // cdb-check:k : Some [Type: enum2$ >] // cdb-check: [+0x000] __0 : "IAMA optional string!" [Type: alloc::string::String] - +// // cdb-command: dx l // cdb-check:l : Ok [Type: enum2$ > >] // cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int] - +// // cdb-command: dx niche128_some // cdb-check: niche128_some : Some [Type: enum2$ > >] // 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] - +// // cdb-command: dx niche128_none // cdb-check: niche128_none : None [Type: enum2$ > >] - +// // cdb-command: dx wrapping_niche128_untagged // cdb-check: wrapping_niche128_untagged : X [Type: enum2$] // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128] - +// // cdb-command: dx wrapping_niche128_none1 // cdb-check: wrapping_niche128_none1 : Y [Type: enum2$] // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128] - +// // cdb-command: dx wrapping_niche128_none2 // cdb-check: wrapping_niche128_none2 : Z [Type: enum2$] // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128] - +// // cdb-command: dx direct_tag_128_a,d // cdb-check: direct_tag_128_a,d : A [Type: enum2$] // cdb-check: [+0x[...]] __0 : 42 [Type: unsigned int] - +// // cdb-command: dx direct_tag_128_b,d // cdb-check: direct_tag_128_b,d : B [Type: enum2$] // cdb-check: [+0x[...]] __0 : 137 [Type: unsigned int] - +// // cdb-command: dx niche_w_fields_1_some,d // cdb-check: niche_w_fields_1_some,d : A [Type: enum2$] // cdb-check: [+0x[...]] __0 : 0x[...] : 77 [Type: unsigned char *] // cdb-check: [+0x[...]] __1 : 7 [Type: unsigned int] - +// // cdb-command: dx niche_w_fields_1_none,d // cdb-check: niche_w_fields_1_none,d : B [Type: enum2$] // cdb-check: [+0x[...]] __0 : 99 [Type: unsigned int] - +// // cdb-command: dx niche_w_fields_2_some,d // cdb-check: niche_w_fields_2_some,d : A [Type: enum2$] // cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZero] // cdb-check: [+0x[...]] __1 : 900 [Type: unsigned __int64] - +// // cdb-command: dx niche_w_fields_2_none,d // cdb-check: niche_w_fields_2_none,d : B [Type: enum2$] // cdb-check: [+0x[...]] __0 : 1000 [Type: unsigned __int64] - +// // cdb-command: dx niche_w_fields_3_some,d // cdb-check: niche_w_fields_3_some,d : A [Type: enum2$] // cdb-check: [+0x[...]] __0 : 137 [Type: unsigned char] // cdb-check: [+0x[...]] __1 : true [Type: bool] - +// // cdb-command: dx niche_w_fields_3_niche1,d // cdb-check: niche_w_fields_3_niche1,d : B [Type: enum2$] // cdb-check: [+0x[...]] __0 : 12 [Type: unsigned char] - +// // cdb-command: dx niche_w_fields_3_niche2,d // cdb-check: niche_w_fields_3_niche2,d : C [Type: enum2$] // cdb-check: [+0x[...]] __0 : false [Type: bool] - +// // cdb-command: dx niche_w_fields_3_niche3,d // cdb-check: niche_w_fields_3_niche3,d : D [Type: enum2$] // cdb-check: [+0x[...]] __0 : 34 [Type: unsigned char] - +// // cdb-command: dx niche_w_fields_3_niche4,d // cdb-check: niche_w_fields_3_niche4,d : E [Type: enum2$] // cdb-check: [+0x[...]] __0 : 56 [Type: unsigned char] - +// // cdb-command: dx niche_w_fields_3_niche5,d // cdb-check: niche_w_fields_3_niche5,d : F [Type: enum2$] - +// // cdb-command: dx -r3 niche_w_fields_std_result_ok,d // cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$,alloc::alloc::Global>,u64> >] // cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box,alloc::alloc::Global>] // cdb-check: [+0x[...]] data_ptr : [...] // cdb-check: [+0x[...]] length : 3 [...] - +// // cdb-command: dx -r3 niche_w_fields_std_result_err,d // cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$,alloc::alloc::Global>,u64> >] // cdb-check: [+0x[...]] __0 : 789 [Type: unsigned __int64] - +// // cdb-command: dx -r2 arbitrary_discr1,d // cdb-check: arbitrary_discr1,d : Abc [Type: enum2$] // cdb-check: [+0x[...]] __0 : 1234 [Type: unsigned int] - +// // cdb-command: dx -r2 arbitrary_discr2,d // cdb-check: arbitrary_discr2,d : Def [Type: enum2$] // cdb-check: [+0x[...]] __0 : 5678 [Type: unsigned int] - +#![feature(generic_nonzero)] #![feature(rustc_attrs)] #![feature(repr128)] #![feature(arbitrary_enum_discriminant)] -use std::num::{NonZeroI128, NonZeroU32}; +use std::num::NonZero; pub enum CStyleEnum { Low = 2, @@ -160,7 +160,7 @@ enum NicheLayoutWithFields1<'a> { } enum NicheLayoutWithFields2 { - A(NonZeroU32, u64), + A(NonZero, u64), B(u64), } @@ -210,8 +210,8 @@ fn main() { let j = CStyleEnum::High; let k = Some("IAMA optional string!".to_string()); let l = Result::::Ok(42); - let niche128_some = Some(NonZeroI128::new(123456).unwrap()); - let niche128_none: Option = None; + let niche128_some = NonZero::new(123456i128); + let niche128_none: Option> = None; let wrapping_niche128_untagged = 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_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_3_some = NicheLayoutWithFields3::A(137, true); diff --git a/tests/debuginfo/numeric-types.rs b/tests/debuginfo/numeric-types.rs index e3df1fbc52014..74c9e5e1dc3f3 100644 --- a/tests/debuginfo/numeric-types.rs +++ b/tests/debuginfo/numeric-types.rs @@ -237,25 +237,25 @@ // lldb-command:print nz_usize // lldb-check:[...]$11 = 122 { __0 = 122 } - +#![feature(generic_nonzero)] use std::num::*; use std::sync::atomic::*; fn main() { - let nz_i8 = NonZeroI8::new(11).unwrap(); - let nz_i16 = NonZeroI16::new(22).unwrap(); - let nz_i32 = NonZeroI32::new(33).unwrap(); - let nz_i64 = NonZeroI64::new(44).unwrap(); - let nz_i128 = NonZeroI128::new(55).unwrap(); - let nz_isize = NonZeroIsize::new(66).unwrap(); - - let nz_u8 = NonZeroU8::new(77).unwrap(); - let nz_u16 = NonZeroU16::new(88).unwrap(); - let nz_u32 = NonZeroU32::new(99).unwrap(); - let nz_u64 = NonZeroU64::new(100).unwrap(); - let nz_u128 = NonZeroU128::new(111).unwrap(); - let nz_usize = NonZeroUsize::new(122).unwrap(); + let nz_i8 = NonZero::new(11i8).unwrap(); + let nz_i16 = NonZero::new(22i16).unwrap(); + let nz_i32 = NonZero::new(33i32).unwrap(); + let nz_i64 = NonZero::new(44i64).unwrap(); + let nz_i128 = NonZero::new(55i128).unwrap(); + let nz_isize = NonZero::new(66isize).unwrap(); + + let nz_u8 = NonZero::new(77u8).unwrap(); + let nz_u16 = NonZero::new(88u16).unwrap(); + let nz_u32 = NonZero::new(99u32).unwrap(); + let nz_u64 = NonZero::new(100u64).unwrap(); + let nz_u128 = NonZero::new(111u128).unwrap(); + let nz_usize = NonZero::new(122usize).unwrap(); let w_i8 = Wrapping(10i8); let w_i16 = Wrapping(20i16); diff --git a/tests/mir-opt/instsimplify/combine_transmutes.rs b/tests/mir-opt/instsimplify/combine_transmutes.rs index 7f45ebf2c863c..3707ee17690da 100644 --- a/tests/mir-opt/instsimplify/combine_transmutes.rs +++ b/tests/mir-opt/instsimplify/combine_transmutes.rs @@ -1,9 +1,9 @@ //@ unit-test: InstSimplify //@ compile-flags: -C panic=abort - #![crate_type = "lib"] #![feature(core_intrinsics)] #![feature(custom_mir)] +#![feature(generic_nonzero)] use std::intrinsics::mir::*; use std::mem::{MaybeUninit, ManuallyDrop, transmute}; @@ -54,7 +54,7 @@ pub unsafe fn adt_transmutes() { // CHECK: as i32 (Transmute); // CHECK: ({{_.*}}.1: std::mem::ManuallyDrop); - let _a: u8 = transmute(Some(std::num::NonZeroU8::MAX)); + let _a: u8 = transmute(Some(std::num::NonZero::::MAX)); let _a: i16 = transmute(std::num::Wrapping(0_i16)); let _a: u16 = transmute(std::num::Wrapping(0_i16)); let _a: u32 = transmute(Union32 { i32: 0 }); diff --git a/tests/rustdoc/type-layout.rs b/tests/rustdoc/type-layout.rs index 05f8e4dc9e9e5..b2ff4add63e2b 100644 --- a/tests/rustdoc/type-layout.rs +++ b/tests/rustdoc/type-layout.rs @@ -81,7 +81,7 @@ pub enum Variants { // @hasraw - 'Some: 4 bytes' pub enum WithNiche { None, - Some(std::num::NonZeroU32), + Some(std::num::NonZero), } // @hasraw type_layout/enum.Uninhabited.html 'Size: ' diff --git a/tests/ui/abi/compatibility.rs b/tests/ui/abi/compatibility.rs index 911438e0d5406..fcf31aa970cd0 100644 --- a/tests/ui/abi/compatibility.rs +++ b/tests/ui/abi/compatibility.rs @@ -64,6 +64,7 @@ [csky] needs-llvm-components: csky */ #![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)] #![allow(unused, improper_ctypes_definitions, internal_features)] @@ -74,7 +75,7 @@ #[cfg(host)] 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, }; @@ -145,7 +146,7 @@ mod prelude { #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] - pub struct NonZeroI32(i32); + pub struct NonZero(T); // This just stands in for a non-trivial type. pub struct Vec { @@ -274,7 +275,7 @@ test_abi_compatible!(isize_int, isize, i64); test_abi_compatible!(zst_unit, Zst, ()); #[cfg(not(any(target_arch = "sparc64")))] test_abi_compatible!(zst_array, Zst, [u8; 0]); -test_abi_compatible!(nonzero_int, NonZeroI32, i32); +test_abi_compatible!(nonzero_int, NonZero, i32); // `DispatchFromDyn` relies on ABI compatibility. // 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!(nonnull, NonNull); test_nonnull!(nonnull_unsized, NonNull); -test_nonnull!(non_zero, NonZeroI32); +test_nonnull!(non_zero, NonZero); fn main() {} diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index 57815e6af65c9..c06c30741164a 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -1,5 +1,5 @@ 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) }; | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:30:1 + --> $DIR/raw-bytes.rs:29:1 | LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:44:1 + --> $DIR/raw-bytes.rs:43:1 | LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:46:1 + --> $DIR/raw-bytes.rs:45:1 | LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $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) })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:57:1 + --> $DIR/raw-bytes.rs:56:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 @@ -65,10 +65,10 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; } 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) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 - --> $DIR/raw-bytes.rs:62:1 + --> $DIR/raw-bytes.rs:61:1 | -LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 - --> $DIR/raw-bytes.rs:68:1 + --> $DIR/raw-bytes.rs:67:1 | LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:74:1 + --> $DIR/raw-bytes.rs:73:1 | 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 @@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; } 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 = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 @@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } 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]) }; | ^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:89:1 + --> $DIR/raw-bytes.rs:88:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) @@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; } 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) }; | ^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:96:1 + --> $DIR/raw-bytes.rs:95:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box @@ -164,7 +164,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } 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) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:102:1 + --> $DIR/raw-bytes.rs:101:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance) @@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } 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) }; | ^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:107:1 + --> $DIR/raw-bytes.rs:106:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:109:1 + --> $DIR/raw-bytes.rs:108:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC3, 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 - --> $DIR/raw-bytes.rs:115:1 + --> $DIR/raw-bytes.rs:114:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:140:1 + --> $DIR/raw-bytes.rs:139:1 | 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) @@ -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 - --> $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)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:147:1 + --> $DIR/raw-bytes.rs:146:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:149:1 + --> $DIR/raw-bytes.rs:148:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:151:1 + --> $DIR/raw-bytes.rs:150:1 | LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:163:1 + --> $DIR/raw-bytes.rs:162:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:163:40 + --> $DIR/raw-bytes.rs:162:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:169:42 + --> $DIR/raw-bytes.rs:168:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:173:42 + --> $DIR/raw-bytes.rs:172:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC17, 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 - --> $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))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC19, 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 - --> $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))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC22, 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 - --> $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) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..: 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC27, 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 - --> $DIR/raw-bytes.rs:203:1 + --> $DIR/raw-bytes.rs:202:1 | LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 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 - --> $DIR/raw-bytes.rs:204:1 + --> $DIR/raw-bytes.rs:203:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:205:1 + --> $DIR/raw-bytes.rs:204:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; | ^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $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) }; | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $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>()) }; | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 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) }; | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:219:1 + --> $DIR/raw-bytes.rs:218:1 | LL | pub static S7: &[u16] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:226:1 + --> $DIR/raw-bytes.rs:225:1 | LL | pub static R4: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:231:1 + --> $DIR/raw-bytes.rs:230:1 | LL | pub static R5: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 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 { | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[0]: encountered 0x11, but expected a boolean diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index c875d91ccb87a..0589280524cab 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -1,5 +1,5 @@ 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) }; | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:30:1 + --> $DIR/raw-bytes.rs:29:1 | LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:44:1 + --> $DIR/raw-bytes.rs:43:1 | LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:46:1 + --> $DIR/raw-bytes.rs:45:1 | LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $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) })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:57:1 + --> $DIR/raw-bytes.rs:56:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 @@ -65,10 +65,10 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; } 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) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 - --> $DIR/raw-bytes.rs:62:1 + --> $DIR/raw-bytes.rs:61:1 | -LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 - --> $DIR/raw-bytes.rs:68:1 + --> $DIR/raw-bytes.rs:67:1 | LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:74:1 + --> $DIR/raw-bytes.rs:73:1 | 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 @@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; } 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 = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 @@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } 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]) }; | ^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:89:1 + --> $DIR/raw-bytes.rs:88:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) @@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; } 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) }; | ^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:96:1 + --> $DIR/raw-bytes.rs:95:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box @@ -164,7 +164,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } 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) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:102:1 + --> $DIR/raw-bytes.rs:101:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance) @@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } 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) }; | ^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:107:1 + --> $DIR/raw-bytes.rs:106:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:109:1 + --> $DIR/raw-bytes.rs:108:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC3, 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 - --> $DIR/raw-bytes.rs:115:1 + --> $DIR/raw-bytes.rs:114:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:140:1 + --> $DIR/raw-bytes.rs:139:1 | 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) @@ -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 - --> $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)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:147:1 + --> $DIR/raw-bytes.rs:146:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .: 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 - --> $DIR/raw-bytes.rs:149:1 + --> $DIR/raw-bytes.rs:148:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:151:1 + --> $DIR/raw-bytes.rs:150:1 | LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $DIR/raw-bytes.rs:163:1 + --> $DIR/raw-bytes.rs:162:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:163:40 + --> $DIR/raw-bytes.rs:162:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:169:42 + --> $DIR/raw-bytes.rs:168:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..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 - --> $DIR/raw-bytes.rs:173:42 + --> $DIR/raw-bytes.rs:172:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC17, 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 - --> $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))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC19, 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 - --> $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))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered ALLOC22, 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 - --> $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) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..: 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - --> $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)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered ALLOC27, 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 - --> $DIR/raw-bytes.rs:203:1 + --> $DIR/raw-bytes.rs:202:1 | LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 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 - --> $DIR/raw-bytes.rs:204:1 + --> $DIR/raw-bytes.rs:203:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:205:1 + --> $DIR/raw-bytes.rs:204:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; | ^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $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) }; | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $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>()) }; | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 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) }; | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:219:1 + --> $DIR/raw-bytes.rs:218:1 | LL | pub static S7: &[u16] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:226:1 + --> $DIR/raw-bytes.rs:225:1 | LL | pub static R4: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 - --> $DIR/raw-bytes.rs:231:1 + --> $DIR/raw-bytes.rs:230:1 | LL | pub static R5: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[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 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 { | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .[0]: encountered 0x11, but expected a boolean diff --git a/tests/ui/consts/const-eval/raw-bytes.rs b/tests/ui/consts/const-eval/raw-bytes.rs index 96903b322e45b..e5dfd5ca29397 100644 --- a/tests/ui/consts/const-eval/raw-bytes.rs +++ b/tests/ui/consts/const-eval/raw-bytes.rs @@ -2,14 +2,13 @@ //@ ignore-endian-big // ignore-tidy-linelength //@ normalize-stderr-test "╾─*ALLOC[0-9]+(\+[a-z0-9]+)?()?─*╼" -> "╾ALLOC_ID$1╼" - -#![feature(never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range)] #![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::alloc::Layout; use std::ptr::NonNull; -use std::num::{NonZeroU8, NonZeroUsize}; +use std::num::NonZero; use std::slice::{from_ptr_range, from_raw_parts}; // # Bad enums and chars @@ -57,9 +56,9 @@ const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; //~^ ERROR it is undefined behavior to use this value -const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; +const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; //~^ ERROR it is undefined behavior to use this value -const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; +const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; //~^ ERROR it is undefined behavior to use this value #[rustc_layout_scalar_valid_range_start(10)] diff --git a/tests/ui/consts/const-eval/ub-nonnull.rs b/tests/ui/consts/const-eval/ub-nonnull.rs index 229ce9a7df382..76bd5248ffd89 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.rs +++ b/tests/ui/consts/const-eval/ub-nonnull.rs @@ -1,12 +1,12 @@ // 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 "([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 +#![feature(generic_nonzero, rustc_attrs, ptr_metadata)] use std::mem; use std::ptr::NonNull; -use std::num::{NonZeroU8, NonZeroUsize}; +use std::num::NonZero; const NON_NULL: NonNull = unsafe { mem::transmute(1usize) }; const NON_NULL_PTR: NonNull = unsafe { mem::transmute(&1) }; @@ -21,9 +21,9 @@ const OUT_OF_BOUNDS_PTR: NonNull = { unsafe { mem::transmute(out_of_bounds_ptr) } }; -const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; +const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; //~^ ERROR it is undefined behavior to use this value -const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; +const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; //~^ ERROR it is undefined behavior to use this value #[repr(C)] @@ -31,7 +31,7 @@ union MaybeUninit { uninit: (), init: T, } -const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init }; +const UNINIT: NonZero = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR evaluation of constant value failed //~| uninitialized diff --git a/tests/ui/consts/const-eval/ub-nonnull.stderr b/tests/ui/consts/const-eval/ub-nonnull.stderr index 7822306b654ca..70b961fe1cd4f 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.stderr +++ b/tests/ui/consts/const-eval/ub-nonnull.stderr @@ -18,8 +18,8 @@ LL | let out_of_bounds_ptr = &ptr[255]; error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:24:1 | -LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 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 --> $DIR/ub-nonnull.rs:26:1 | -LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 raw bytes of the constant (size: $SIZE, align: $ALIGN) { @@ -38,10 +38,10 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) }; } 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 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory +LL | const UNINIT: NonZero = unsafe { MaybeUninit { uninit: () }.init }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:43:1 diff --git a/tests/ui/consts/const-eval/valid-const.rs b/tests/ui/consts/const-eval/valid-const.rs index 1c8c048ae28cb..15d3e88345658 100644 --- a/tests/ui/consts/const-eval/valid-const.rs +++ b/tests/ui/consts/const-eval/valid-const.rs @@ -1,16 +1,17 @@ //@ check-pass - +// // Some constants that *are* valid +#![feature(generic_nonzero)] use std::mem; use std::ptr::NonNull; -use std::num::{NonZeroU8, NonZeroUsize}; +use std::num::NonZero; const NON_NULL_PTR1: NonNull = unsafe { mem::transmute(1usize) }; const NON_NULL_PTR2: NonNull = unsafe { mem::transmute(&0) }; -const NON_NULL_U8: NonZeroU8 = unsafe { mem::transmute(1u8) }; -const NON_NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(1usize) }; +const NON_NULL_U8: NonZero = unsafe { mem::transmute(1u8) }; +const NON_NULL_USIZE: NonZero = unsafe { mem::transmute(1usize) }; const UNIT: () = (); diff --git a/tests/ui/consts/ice-48279.rs b/tests/ui/consts/ice-48279.rs index 5316974b80ad3..a4f687a3e9ce1 100644 --- a/tests/ui/consts/ice-48279.rs +++ b/tests/ui/consts/ice-48279.rs @@ -15,7 +15,7 @@ impl NonZeroU32 { } } -//pub const FOO_ATOM: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(7) }; +// pub const FOO_ATOM: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(7) }; pub const FOO_ATOM: NonZeroU32 = unsafe { NonZeroU32 { value: 7 } }; fn main() { diff --git a/tests/ui/consts/tuple-struct-constructors.rs b/tests/ui/consts/tuple-struct-constructors.rs index 8472a09844bb9..d2f25aeec9b17 100644 --- a/tests/ui/consts/tuple-struct-constructors.rs +++ b/tests/ui/consts/tuple-struct-constructors.rs @@ -1,10 +1,11 @@ //@ run-pass - +// // https://github.com/rust-lang/rust/issues/41898 +#![feature(generic_nonzero)] -use std::num::NonZeroU64; +use std::num::NonZero; fn main() { - const FOO: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(2) }; + const FOO: NonZero = unsafe { NonZero::new_unchecked(2) }; if let FOO = FOO {} } diff --git a/tests/ui/intrinsics/panic-uninitialized-zeroed.rs b/tests/ui/intrinsics/panic-uninitialized-zeroed.rs index 2420aec505889..fb3b0652ddbf7 100644 --- a/tests/ui/intrinsics/panic-uninitialized-zeroed.rs +++ b/tests/ui/intrinsics/panic-uninitialized-zeroed.rs @@ -4,11 +4,11 @@ // ignore-tidy-linelength //@ ignore-emscripten spawning processes is not supported //@ ignore-sgx no processes - +// // This test checks panic emitted from `mem::{uninitialized,zeroed}`. - -#![feature(never_type)] #![allow(deprecated, invalid_value)] +#![feature(generic_nonzero)] +#![feature(never_type)] use std::{ mem::{self, MaybeUninit, ManuallyDrop}, @@ -29,7 +29,7 @@ enum OneVariant { Variant(i32) } #[allow(dead_code, non_camel_case_types)] enum OneVariant_NonZero { - Variant(i32, i32, num::NonZeroI32), + Variant(i32, i32, num::NonZero), DeadVariant(Bar), } @@ -55,8 +55,8 @@ enum LR { } #[allow(dead_code, non_camel_case_types)] enum LR_NonZero { - Left(num::NonZeroI64), - Right(num::NonZeroI64), + Left(num::NonZero), + Right(num::NonZero), } struct ZeroSized; diff --git a/tests/ui/issues/issue-64593.rs b/tests/ui/issues/issue-64593.rs index e553538100676..091c3a2f316dd 100644 --- a/tests/ui/issues/issue-64593.rs +++ b/tests/ui/issues/issue-64593.rs @@ -1,7 +1,8 @@ //@ check-pass #![deny(improper_ctypes)] +#![feature(generic_nonzero)] -pub struct Error(std::num::NonZeroU32); +pub struct Error(std::num::NonZero); extern "Rust" { fn foo(dest: &mut [u8]) -> Result<(), Error>; diff --git a/tests/ui/layout/unsafe-cell-hides-niche.rs b/tests/ui/layout/unsafe-cell-hides-niche.rs index b3158839de0d6..568eb819be2e6 100644 --- a/tests/ui/layout/unsafe-cell-hides-niche.rs +++ b/tests/ui/layout/unsafe-cell-hides-niche.rs @@ -1,17 +1,17 @@ // For rust-lang/rust#68303: the contents of `UnsafeCell` cannot // participate in the niche-optimization for enum discriminants. This -// test checks that an `Option>` has the same +// test checks that an `Option>>` has the same // size in memory as an `Option>` (namely, 8 bytes). - +// //@ check-pass //@ compile-flags: --crate-type=lib //@ only-x86 - +#![feature(generic_nonzero)] #![feature(repr_simd)] use std::cell::{UnsafeCell, RefCell, Cell}; use std::mem::size_of; -use std::num::NonZeroU32 as N32; +use std::num::NonZero; use std::sync::{Mutex, RwLock}; struct Wrapper(#[allow(dead_code)] T); @@ -54,15 +54,17 @@ macro_rules! check_sizes { const PTR_SIZE: usize = std::mem::size_of::<*const ()>(); -check_sizes!(Wrapper: 4 => 8); -check_sizes!(Wrapper: 4 => 4); // (✓ niche opt) -check_sizes!(Transparent: 4 => 8); -check_sizes!(Transparent: 4 => 4); // (✓ niche opt) -check_sizes!(NoNiche: 4 => 8); -check_sizes!(NoNiche: 4 => 8); +check_sizes!(Wrapper: 4 => 8); +check_sizes!(Wrapper>: 4 => 4); // (✓ niche opt) + +check_sizes!(Transparent: 4 => 8); +check_sizes!(Transparent>: 4 => 4); // (✓ niche opt) + +check_sizes!(NoNiche: 4 => 8); +check_sizes!(NoNiche>: 4 => 8); -check_sizes!(UnsafeCell: 4 => 8); -check_sizes!(UnsafeCell: 4 => 8); +check_sizes!(UnsafeCell: 4 => 8); +check_sizes!(UnsafeCell>: 4 => 8); check_sizes!(UnsafeCell<&()>: PTR_SIZE => PTR_SIZE * 2); 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)] pub struct Vec4([T; 4]); -check_sizes!(UnsafeCell>: 16 => 32); +check_sizes!(UnsafeCell>>: 16 => 32); diff --git a/tests/ui/layout/zero-sized-array-enum-niche.rs b/tests/ui/layout/zero-sized-array-enum-niche.rs index 095afc4337a55..058f59234878f 100644 --- a/tests/ui/layout/zero-sized-array-enum-niche.rs +++ b/tests/ui/layout/zero-sized-array-enum-niche.rs @@ -1,6 +1,7 @@ //@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN" -#![feature(rustc_attrs)] #![crate_type = "lib"] +#![feature(generic_nonzero)] +#![feature(rustc_attrs)] // Various tests around the behavior of zero-sized arrays and // enum niches, especially that they have coherent size and alignment. @@ -34,7 +35,7 @@ enum MultipleAlignments { //~ ERROR: layout_of struct Packed(T); #[rustc_layout(debug)] -type NicheLosesToTagged = Result<[u32; 0], Packed>; //~ ERROR: layout_of +type NicheLosesToTagged = Result<[u32; 0], Packed>>; //~ ERROR: layout_of // Should get tag_encoding: Direct, size == align == 4. #[repr(u16)] diff --git a/tests/ui/layout/zero-sized-array-enum-niche.stderr b/tests/ui/layout/zero-sized-array-enum-niche.stderr index 0ed743818c573..af049125de467 100644 --- a/tests/ui/layout/zero-sized-array-enum-niche.stderr +++ b/tests/ui/layout/zero-sized-array-enum-niche.stderr @@ -98,7 +98,7 @@ error: layout_of(Result<[u32; 0], bool>) = Layout { max_repr_align: None, 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>; | ^^^^^^^^^^^^^^^^^^ @@ -227,7 +227,7 @@ error: layout_of(MultipleAlignments) = Layout { max_repr_align: None, 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 { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -332,9 +332,9 @@ error: layout_of(Result<[u32; 0], Packed>>) = Layout { max_repr_align: None, 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>; +LL | type NicheLosesToTagged = Result<[u32; 0], Packed>>; | ^^^^^^^^^^^^^^^^^^^^^^^ error: layout_of(Result<[u32; 0], Packed>) = Layout { @@ -441,7 +441,7 @@ error: layout_of(Result<[u32; 0], Packed>) = Layout { max_repr_align: None, 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>; | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/clashing-extern-fn.rs b/tests/ui/lint/clashing-extern-fn.rs index ce027c8255459..cb63af0ea4228 100644 --- a/tests/ui/lint/clashing-extern-fn.rs +++ b/tests/ui/lint/clashing-extern-fn.rs @@ -2,6 +2,7 @@ //@ aux-build:external_extern_fn.rs #![crate_type = "lib"] #![warn(clashing_extern_declarations)] +#![feature(generic_nonzero)] mod redeclared_different_signature { mod a { @@ -265,7 +266,7 @@ mod missing_return_type { mod non_zero_and_non_null { mod a { extern "C" { - fn non_zero_usize() -> core::num::NonZeroUsize; + fn non_zero_usize() -> core::num::NonZero; fn non_null_ptr() -> core::ptr::NonNull; } } @@ -285,36 +286,33 @@ mod non_zero_and_non_null { // See #75739 mod non_zero_transparent { mod a1 { - use std::num::NonZeroUsize; extern "C" { - fn f1() -> NonZeroUsize; + fn f1() -> std::num::NonZero; } } mod b1 { #[repr(transparent)] - struct X(NonZeroUsize); - use std::num::NonZeroUsize; + struct X(std::num::NonZero); + extern "C" { fn f1() -> X; } } mod a2 { - use std::num::NonZeroUsize; extern "C" { - fn f2() -> NonZeroUsize; + fn f2() -> std::num::NonZero; } } mod b2 { #[repr(transparent)] - struct X1(NonZeroUsize); + struct X1(std::num::NonZero); #[repr(transparent)] struct X(X1); - use std::num::NonZeroUsize; extern "C" { // Same case as above, but with two layers of newtyping. fn f2() -> X; @@ -325,7 +323,6 @@ mod non_zero_transparent { #[repr(transparent)] struct X(core::ptr::NonNull); - use std::num::NonZeroUsize; extern "C" { fn f3() -> X; } @@ -340,7 +337,7 @@ mod non_zero_transparent { mod a4 { #[repr(transparent)] enum E { - X(std::num::NonZeroUsize), + X(std::num::NonZero), } extern "C" { fn f4() -> E; @@ -349,7 +346,7 @@ mod non_zero_transparent { mod b4 { extern "C" { - fn f4() -> std::num::NonZeroUsize; + fn f4() -> std::num::NonZero; } } } @@ -369,8 +366,8 @@ mod null_optimised_enums { extern "C" { // This should be allowed, because these conversions are guaranteed to be FFI-safe (see // #60300) - fn option_non_zero_usize() -> Option; - fn option_non_zero_isize() -> Option; + fn option_non_zero_usize() -> Option>; + fn option_non_zero_isize() -> Option>; fn option_non_null_ptr() -> Option>; // However, these should be incorrect (note isize instead of usize) @@ -415,16 +412,16 @@ mod hidden_niche { } mod b { use std::cell::UnsafeCell; - use std::num::NonZeroUsize; + use std::num::NonZero; #[repr(transparent)] struct Transparent { - x: NonZeroUsize, + x: NonZero, } #[repr(transparent)] struct TransparentNoNiche { - y: UnsafeCell, + y: UnsafeCell>, } extern "C" { @@ -434,7 +431,7 @@ mod hidden_niche { //~^ WARN redeclared with a different signature //~| WARN block uses type `Option`, which is not FFI-safe - fn hidden_niche_unsafe_cell() -> Option>; + fn hidden_niche_unsafe_cell() -> Option>>; //~^ WARN redeclared with a different signature //~| WARN block uses type `Option>>`, which is not FFI-safe } diff --git a/tests/ui/lint/clashing-extern-fn.stderr b/tests/ui/lint/clashing-extern-fn.stderr index 5b9244b699311..86ee789aeb22d 100644 --- a/tests/ui/lint/clashing-extern-fn.stderr +++ b/tests/ui/lint/clashing-extern-fn.stderr @@ -1,5 +1,5 @@ warning: `extern` block uses type `Option`, 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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -9,16 +9,16 @@ LL | fn hidden_niche_transparent_no_niche() -> Option>>`, 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>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe +LL | fn hidden_niche_unsafe_cell() -> Option>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint 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); | --------------- `clash` previously declared here @@ -35,7 +35,7 @@ LL | #![warn(clashing_extern_declarations)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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"] | --------------------------------- `extern_link_name` previously declared here @@ -47,7 +47,7 @@ LL | fn extern_link_name(x: u32); found `unsafe extern "C" fn(u32)` warning: `some_other_extern_link_name` redeclares `some_other_new_name` with a different signature - --> $DIR/clashing-extern-fn.rs:55:9 + --> $DIR/clashing-extern-fn.rs:56:9 | LL | fn some_other_new_name(x: i16); | ------------------------------ `some_other_new_name` previously declared here @@ -59,7 +59,7 @@ LL | #[link_name = "some_other_new_name"] found `unsafe extern "C" fn(u32)` 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"] | ------------------------------- `link_name_same` previously declared here @@ -71,7 +71,7 @@ LL | #[link_name = "link_name_same"] found `unsafe extern "C" fn(u32)` 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); | ----------------------- `different_mod` previously declared here @@ -83,7 +83,7 @@ LL | fn different_mod(x: u64); found `unsafe extern "C" fn(u64)` warning: `variadic_decl` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:82:9 + --> $DIR/clashing-extern-fn.rs:83:9 | LL | fn variadic_decl(x: u8, ...); | ---------------------------- `variadic_decl` previously declared here @@ -95,7 +95,7 @@ LL | fn variadic_decl(x: u8); found `unsafe extern "C" fn(u8)` warning: `weigh_banana` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:142:13 + --> $DIR/clashing-extern-fn.rs:143:13 | LL | fn weigh_banana(count: *const Banana) -> u64; | -------------------------------------------- `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` 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); | ----------------------- `draw_point` previously declared here @@ -119,7 +119,7 @@ LL | fn draw_point(p: Point); found `unsafe extern "C" fn(sameish_members::b::Point)` warning: `origin` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:197:13 + --> $DIR/clashing-extern-fn.rs:198:13 | LL | fn origin() -> Point3; | --------------------- `origin` previously declared here @@ -131,7 +131,7 @@ LL | fn origin() -> Point3; found `unsafe extern "C" fn() -> same_sized_members_clash::b::Point3` warning: `transparent_incorrect` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:220:13 + --> $DIR/clashing-extern-fn.rs:221:13 | LL | fn transparent_incorrect() -> T; | ------------------------------- `transparent_incorrect` previously declared here @@ -143,7 +143,7 @@ LL | fn transparent_incorrect() -> isize; found `unsafe extern "C" fn() -> isize` warning: `missing_return_type` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:259:13 + --> $DIR/clashing-extern-fn.rs:260:13 | LL | fn missing_return_type() -> usize; | --------------------------------- `missing_return_type` previously declared here @@ -155,10 +155,10 @@ LL | fn missing_return_type(); found `unsafe extern "C" fn()` 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; - | ---------------------------------------------- `non_zero_usize` previously declared here +LL | fn non_zero_usize() -> core::num::NonZero; + | ------------------------------------------------ `non_zero_usize` previously declared here ... LL | fn non_zero_usize() -> usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration @@ -167,7 +167,7 @@ LL | fn non_zero_usize() -> usize; found `unsafe extern "C" fn() -> usize` warning: `non_null_ptr` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:279:13 + --> $DIR/clashing-extern-fn.rs:280:13 | LL | fn non_null_ptr() -> core::ptr::NonNull; | ---------------------------------------------- `non_null_ptr` previously declared here @@ -179,7 +179,7 @@ LL | fn non_null_ptr() -> *const usize; found `unsafe extern "C" fn() -> *const usize` warning: `option_non_zero_usize_incorrect` redeclared with a different signature - --> $DIR/clashing-extern-fn.rs:377:13 + --> $DIR/clashing-extern-fn.rs:374:13 | LL | fn option_non_zero_usize_incorrect() -> usize; | --------------------------------------------- `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` 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; | -------------------------------------------------- `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` 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; | ----------------------------------------------- `hidden_niche_transparent_no_niche` previously declared here @@ -215,13 +215,13 @@ LL | fn hidden_niche_transparent_no_niche() -> Option Option` 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; | -------------------------------------- `hidden_niche_unsafe_cell` previously declared here ... -LL | fn hidden_niche_unsafe_cell() -> Option>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration +LL | fn hidden_niche_unsafe_cell() -> Option>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration | = note: expected `unsafe extern "C" fn() -> usize` found `unsafe extern "C" fn() -> Option>>` diff --git a/tests/ui/lint/invalid_value.rs b/tests/ui/lint/invalid_value.rs index 57d8cbe7c9341..1d2f23aaaf6f5 100644 --- a/tests/ui/lint/invalid_value.rs +++ b/tests/ui/lint/invalid_value.rs @@ -1,13 +1,12 @@ // This test checks that calling `mem::{uninitialized,zeroed}` with certain types results // in a lint. - -#![feature(never_type, rustc_attrs)] #![allow(deprecated)] #![deny(invalid_value)] +#![feature(generic_nonzero, never_type, rustc_attrs)] use std::mem::{self, MaybeUninit}; use std::ptr::NonNull; -use std::num::NonZeroU32; +use std::num::NonZero; enum Void {} @@ -36,7 +35,7 @@ enum OneFruit { enum OneFruitNonZero { Apple(!), - Banana(NonZeroU32), + Banana(NonZero), } enum TwoUninhabited { @@ -92,8 +91,8 @@ fn main() { let _val: NonNull = mem::zeroed(); //~ ERROR: does not permit zero-initialization let _val: NonNull = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized - let _val: (NonZeroU32, 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, i32) = mem::zeroed(); //~ ERROR: does not permit zero-initialization + let _val: (NonZero, 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::uninitialized(); //~ ERROR: does not permit being left uninitialized @@ -151,7 +150,7 @@ fn main() { // Transmute-from-0 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: NonZeroU32 = mem::transmute(0); //~ ERROR: does not permit zero-initialization + let _val: NonZero = mem::transmute(0); //~ ERROR: does not permit zero-initialization // `MaybeUninit` cases let _val: NonNull = MaybeUninit::zeroed().assume_init(); //~ ERROR: does not permit zero-initialization diff --git a/tests/ui/lint/invalid_value.stderr b/tests/ui/lint/invalid_value.stderr index bdf47343114c6..955d01bd5d904 100644 --- a/tests/ui/lint/invalid_value.stderr +++ b/tests/ui/lint/invalid_value.stderr @@ -1,5 +1,5 @@ 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(); | ^^^^^^^^^^^^^ @@ -9,13 +9,13 @@ LL | let _val: &'static T = mem::zeroed(); | = note: references must be non-null note: the lint level is defined here - --> $DIR/invalid_value.rs:6:9 + --> $DIR/invalid_value.rs:4:9 | LL | #![deny(invalid_value)] | ^^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _val: &'static T = mem::uninitialized(); = note: references must be non-null 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(); | ^^^^^^^^^^^^^ @@ -36,13 +36,13 @@ LL | let _val: Wrap<&'static T> = mem::zeroed(); | = note: `Wrap<&T>` must be non-null 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 { wrapped: T } | ^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +52,13 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized(); | = note: `Wrap<&T>` must be non-null 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 { wrapped: T } | ^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -66,7 +66,7 @@ LL | let _val: ! = mem::zeroed(); = note: the `!` type has no valid value 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(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -74,7 +74,7 @@ LL | let _val: ! = mem::uninitialized(); = note: the `!` type has no valid value 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(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -82,7 +82,7 @@ LL | let _val: (i32, !) = mem::zeroed(); = note: the `!` type has no valid value 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(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -90,31 +90,31 @@ LL | let _val: (i32, !) = mem::uninitialized(); = note: integers must be initialized 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(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | 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 {} | ^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | 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 {} | ^^^^^^^^^ 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(); | ^^^^^^^^^^^^^ @@ -125,7 +125,7 @@ LL | let _val: &'static i32 = mem::zeroed(); = note: references must be non-null 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let _val: &'static i32 = mem::uninitialized(); = note: references must be non-null 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(); | ^^^^^^^^^^^^^ @@ -146,13 +146,13 @@ LL | let _val: Ref = mem::zeroed(); | = note: `Ref` must be non-null 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); | ^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -162,13 +162,13 @@ LL | let _val: Ref = mem::uninitialized(); | = note: `Ref` must be non-null 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); | ^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL | let _val: fn() = mem::zeroed(); = note: function pointers must be non-null 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -190,7 +190,7 @@ LL | let _val: fn() = mem::uninitialized(); = note: function pointers must be non-null error: the type `Wrap` does not permit zero-initialization - --> $DIR/invalid_value.rs:83:32 + --> $DIR/invalid_value.rs:82:32 | LL | let _val: Wrap = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -200,13 +200,13 @@ LL | let _val: Wrap = mem::zeroed(); | = note: `Wrap` must be non-null 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 { wrapped: T } | ^^^^^^^^^^ error: the type `Wrap` does not permit being left uninitialized - --> $DIR/invalid_value.rs:84:32 + --> $DIR/invalid_value.rs:83:32 | LL | let _val: Wrap = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -216,13 +216,13 @@ LL | let _val: Wrap = mem::uninitialized(); | = note: `Wrap` must be non-null 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 { wrapped: T } | ^^^^^^^^^^ error: the type `WrapEnum` does not permit zero-initialization - --> $DIR/invalid_value.rs:86:36 + --> $DIR/invalid_value.rs:85:36 | LL | let _val: WrapEnum = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -232,13 +232,13 @@ LL | let _val: WrapEnum = mem::zeroed(); | = note: `WrapEnum` must be non-null 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 { Wrapped(T) } | ^ error: the type `WrapEnum` does not permit being left uninitialized - --> $DIR/invalid_value.rs:87:36 + --> $DIR/invalid_value.rs:86:36 | LL | let _val: WrapEnum = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -248,13 +248,13 @@ LL | let _val: WrapEnum = mem::uninitialized(); | = note: `WrapEnum` must be non-null 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 { Wrapped(T) } | ^ 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(); | ^^^^^^^^^^^^^ @@ -263,18 +263,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | 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 { wrapped: T } | ^^^^^^^^^^ 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)); | ^^^^^^^^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -283,18 +283,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | 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 { wrapped: T } | ^^^^^^^^^^ 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)); | ^^^^^^^^^^^^^^^^^^^ error: the type `NonNull` does not permit zero-initialization - --> $DIR/invalid_value.rs:92:34 + --> $DIR/invalid_value.rs:91:34 | LL | let _val: NonNull = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ LL | let _val: NonNull = mem::zeroed(); = note: `std::ptr::NonNull` must be non-null error: the type `NonNull` does not permit being left uninitialized - --> $DIR/invalid_value.rs:93:34 + --> $DIR/invalid_value.rs:92:34 | LL | let _val: NonNull = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -317,30 +317,30 @@ LL | let _val: NonNull = mem::uninitialized(); = note: raw pointers must be initialized error: the type `(NonZero, 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(); - | ^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done +LL | let _val: (NonZero, i32) = mem::zeroed(); + | ^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::num::NonZero` must be non-null error: the type `(NonZero, 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(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done +LL | let _val: (NonZero, i32) = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::num::NonZero` must be non-null = note: integers must be initialized 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(); | ^^^^^^^^^^^^^ @@ -351,7 +351,7 @@ LL | let _val: *const dyn Send = mem::zeroed(); = note: the vtable of a wide raw pointer must be non-null 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | let _val: *const dyn Send = mem::uninitialized(); = note: the vtable of a wide raw pointer must be non-null 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(); | ^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL | let _val: [fn(); 2] = mem::zeroed(); = note: function pointers must be non-null 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -384,31 +384,31 @@ LL | let _val: [fn(); 2] = mem::uninitialized(); = note: function pointers must be non-null 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(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | 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 { | ^^^^^^^^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | 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 { | ^^^^^^^^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^ @@ -418,13 +418,13 @@ LL | let _val: OneFruitNonZero = mem::zeroed(); | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero` 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), + | ^^^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -434,14 +434,14 @@ LL | let _val: OneFruitNonZero = mem::uninitialized(); | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero` 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), + | ^^^^^^^^^^^^ = note: integers must be initialized 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -452,7 +452,7 @@ LL | let _val: bool = mem::uninitialized(); = note: booleans must be either `true` or `false` error: the type `Wrap` does not permit being left uninitialized - --> $DIR/invalid_value.rs:115:32 + --> $DIR/invalid_value.rs:114:32 | LL | let _val: Wrap = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -462,13 +462,13 @@ LL | let _val: Wrap = mem::uninitialized(); | = note: `Wrap` must be initialized inside its custom valid range 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 { wrapped: T } | ^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -478,13 +478,13 @@ LL | let _val: NonBig = mem::uninitialized(); | = note: `NonBig` must be initialized inside its custom valid range 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); | ^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -493,13 +493,13 @@ LL | let _val: Fruit = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | 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 { | ^^^^^^^^^^ 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -510,7 +510,7 @@ LL | let _val: [bool; 2] = mem::uninitialized(); = note: booleans must be either `true` or `false` 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -521,7 +521,7 @@ LL | let _val: i32 = mem::uninitialized(); = note: integers must be initialized 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -532,7 +532,7 @@ LL | let _val: f32 = mem::uninitialized(); = note: floats must be initialized 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +543,7 @@ LL | let _val: *const () = mem::uninitialized(); = note: raw pointers must be initialized 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -554,7 +554,7 @@ LL | let _val: *const [()] = mem::uninitialized(); = note: raw pointers must be initialized 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(); | ^^^^^^^^^^^^^^^^^^^^ @@ -564,13 +564,13 @@ LL | let _val: WrapAroundRange = mem::uninitialized(); | = note: `WrapAroundRange` must be initialized inside its custom valid range 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); | ^^ error: the type `Result` does not permit being left uninitialized - --> $DIR/invalid_value.rs:144:38 + --> $DIR/invalid_value.rs:143:38 | LL | let _val: Result = 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 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); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -593,7 +593,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize); = note: references must be non-null 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)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -604,18 +604,18 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); = note: references must be non-null error: the type `NonZero` does not permit zero-initialization - --> $DIR/invalid_value.rs:154:32 + --> $DIR/invalid_value.rs:153:34 | -LL | let _val: NonZeroU32 = mem::transmute(0); - | ^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done +LL | let _val: NonZero = mem::transmute(0); + | ^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::num::NonZero` must be non-null error: the type `NonNull` does not permit zero-initialization - --> $DIR/invalid_value.rs:157:34 + --> $DIR/invalid_value.rs:156:34 | LL | let _val: NonNull = MaybeUninit::zeroed().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -626,7 +626,7 @@ LL | let _val: NonNull = MaybeUninit::zeroed().assume_init(); = note: `std::ptr::NonNull` must be non-null error: the type `NonNull` does not permit being left uninitialized - --> $DIR/invalid_value.rs:158:34 + --> $DIR/invalid_value.rs:157:34 | LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -638,7 +638,7 @@ LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); = note: raw pointers must be initialized 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(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/lint-ctypes-enum.rs b/tests/ui/lint/lint-ctypes-enum.rs index 7c20608059398..3157b6e240aec 100644 --- a/tests/ui/lint/lint-ctypes-enum.rs +++ b/tests/ui/lint/lint-ctypes-enum.rs @@ -1,7 +1,8 @@ -#![feature(transparent_unions)] -#![feature(ptr_internals)] -#![deny(improper_ctypes)] #![allow(dead_code)] +#![deny(improper_ctypes)] +#![feature(generic_nonzero)] +#![feature(ptr_internals)] +#![feature(transparent_unions)] use std::num; @@ -67,26 +68,26 @@ extern "C" { fn option_fn(x: Option); fn nonnull(x: Option>); fn unique(x: Option>); - fn nonzero_u8(x: Option); - fn nonzero_u16(x: Option); - fn nonzero_u32(x: Option); - fn nonzero_u64(x: Option); - fn nonzero_u128(x: Option); + fn nonzero_u8(x: Option>); + fn nonzero_u16(x: Option>); + fn nonzero_u32(x: Option>); + fn nonzero_u64(x: Option>); + fn nonzero_u128(x: Option>); //~^ ERROR `extern` block uses type `u128` - fn nonzero_usize(x: Option); - fn nonzero_i8(x: Option); - fn nonzero_i16(x: Option); - fn nonzero_i32(x: Option); - fn nonzero_i64(x: Option); - fn nonzero_i128(x: Option); + fn nonzero_usize(x: Option>); + fn nonzero_i8(x: Option>); + fn nonzero_i16(x: Option>); + fn nonzero_i32(x: Option>); + fn nonzero_i64(x: Option>); + fn nonzero_i128(x: Option>); //~^ ERROR `extern` block uses type `i128` - fn nonzero_isize(x: Option); - fn transparent_struct(x: Option>); - fn transparent_enum(x: Option>); - fn transparent_union(x: Option>); + fn nonzero_isize(x: Option>); + fn transparent_struct(x: Option>>); + fn transparent_enum(x: Option>>); + fn transparent_union(x: Option>>); //~^ ERROR `extern` block uses type - fn repr_rust(x: Option>); //~ ERROR `extern` block uses type - fn no_result(x: Result<(), num::NonZeroI32>); //~ ERROR `extern` block uses type + fn repr_rust(x: Option>>); //~ ERROR `extern` block uses type + fn no_result(x: Result<(), num::NonZero>); //~ ERROR `extern` block uses type } pub fn main() {} diff --git a/tests/ui/lint/lint-ctypes-enum.stderr b/tests/ui/lint/lint-ctypes-enum.stderr index 64beefbb7579f..48be3eb5a5630 100644 --- a/tests/ui/lint/lint-ctypes-enum.stderr +++ b/tests/ui/lint/lint-ctypes-enum.stderr @@ -1,5 +1,5 @@ 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); | ^ 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 = note: enum has no representation hint note: the type is defined here - --> $DIR/lint-ctypes-enum.rs:9:1 + --> $DIR/lint-ctypes-enum.rs:10:1 | LL | enum U { | ^^^^^^ 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)] | ^^^^^^^^^^^^^^^ 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); | ^ 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 = note: enum has no representation hint note: the type is defined here - --> $DIR/lint-ctypes-enum.rs:12:1 + --> $DIR/lint-ctypes-enum.rs:13:1 | LL | enum B { | ^^^^^^ 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); | ^ 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 = note: enum has no representation hint note: the type is defined here - --> $DIR/lint-ctypes-enum.rs:16:1 + --> $DIR/lint-ctypes-enum.rs:17:1 | LL | enum T { | ^^^^^^ 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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe +LL | fn nonzero_u128(x: Option>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = note: 128-bit integers don't currently have a known stable ABI 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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe +LL | fn nonzero_i128(x: Option>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `Option>>`, 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>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe +LL | fn transparent_union(x: Option>>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint error: `extern` block uses type `Option>>`, 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>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe +LL | fn repr_rust(x: Option>>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint error: `extern` block uses type `Result<(), NonZero>`, 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>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe +LL | fn no_result(x: Result<(), num::NonZero>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum = note: enum has no representation hint diff --git a/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs b/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs index dc3b6c280f340..bda5cef979ec2 100644 --- a/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs +++ b/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs @@ -2,11 +2,11 @@ //@ error-pattern:attempt to negate with overflow //@ ignore-emscripten no processes //@ compile-flags: -C debug-assertions - #![allow(arithmetic_overflow)] +#![feature(generic_nonzero)] -use std::num::NonZeroI8; +use std::num::NonZero; fn main() { - let _x = -NonZeroI8::new(i8::MIN).unwrap(); + let _x = -NonZero::new(i8::MIN).unwrap(); } diff --git a/tests/ui/print_type_sizes/niche-filling.rs b/tests/ui/print_type_sizes/niche-filling.rs index da11f0c012170..07da1cff27a74 100644 --- a/tests/ui/print_type_sizes/niche-filling.rs +++ b/tests/ui/print_type_sizes/niche-filling.rs @@ -1,24 +1,24 @@ +//! This file illustrates how niche-filling enums are handled, +//! modelled after cases like `Option<&u32>`, `Option` and such. +//! +//! It uses `NonZero` 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 //@ ignore-debug: debug assertions will print more types //@ build-pass //@ ignore-pass -// ^-- needed because `--pass check` does not emit the output needed. -// 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` 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)] +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. #![allow(dead_code)] +#![feature(generic_nonzero)] +#![feature(rustc_attrs)] -use std::num::NonZeroU32; +use std::num::NonZero; pub enum MyOption { None, Some(T) } @@ -34,7 +34,7 @@ impl Default for MyOption { pub enum EmbeddedDiscr { None, - Record { pre: u8, val: NonZeroU32, post: u16 }, + Record { pre: u8, val: NonZero, post: u16 }, } impl Default for EmbeddedDiscr { @@ -50,13 +50,13 @@ pub struct IndirectNonZero { pub struct NestedNonZero { pre: u8, - val: NonZeroU32, + val: NonZero, post: u16, } impl Default for NestedNonZero { 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 { } pub fn test() { - let _x: MyOption = Default::default(); + let _x: MyOption> = Default::default(); let _y: EmbeddedDiscr = Default::default(); let _z: MyOption = Default::default(); let _a: MyOption = Default::default(); @@ -90,9 +90,9 @@ pub fn test() { let _h: MyOption = Default::default(); // Unions do not currently participate in niche filling. - let _i: MyOption> = Default::default(); + let _i: MyOption, u32>> = Default::default(); // ...even when theoretically possible. - let _j: MyOption> = Default::default(); - let _k: MyOption> = Default::default(); + let _j: MyOption>> = Default::default(); + let _k: MyOption, NonZero>> = Default::default(); } diff --git a/tests/ui/structs-enums/enum-null-pointer-opt.rs b/tests/ui/structs-enums/enum-null-pointer-opt.rs index 6f8c81689682b..a8418943ba4f3 100644 --- a/tests/ui/structs-enums/enum-null-pointer-opt.rs +++ b/tests/ui/structs-enums/enum-null-pointer-opt.rs @@ -1,8 +1,9 @@ //@ run-pass +#![feature(generic_nonzero)] #![feature(transparent_unions)] use std::mem::size_of; -use std::num::NonZeroUsize; +use std::num::NonZero; use std::ptr::NonNull; use std::rc::Rc; use std::sync::Arc; @@ -57,7 +58,7 @@ fn main() { assert_eq!(size_of::<[Box; 1]>(), size_of::; 1]>>()); // Should apply to NonZero - assert_eq!(size_of::(), size_of::>()); + assert_eq!(size_of::>(), size_of::>>()); assert_eq!(size_of::>(), size_of::>>()); // Should apply to types that use NonZero internally diff --git a/tests/ui/structs-enums/enum-null-pointer-opt.stderr b/tests/ui/structs-enums/enum-null-pointer-opt.stderr index 64e93ffaffd60..fca62bd1c801b 100644 --- a/tests/ui/structs-enums/enum-null-pointer-opt.stderr +++ b/tests/ui/structs-enums/enum-null-pointer-opt.stderr @@ -1,5 +1,5 @@ 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) { } } | ----- ^^^^^ diff --git a/tests/ui/structs-enums/type-sizes.rs b/tests/ui/structs-enums/type-sizes.rs index 92060e3cade3c..66f663ce0776c 100644 --- a/tests/ui/structs-enums/type-sizes.rs +++ b/tests/ui/structs-enums/type-sizes.rs @@ -2,12 +2,13 @@ #![allow(non_camel_case_types)] #![allow(dead_code)] +#![feature(generic_nonzero)] #![feature(never_type)] #![feature(pointer_is_aligned)] #![feature(strict_provenance)] use std::mem::size_of; -use std::num::{NonZeroU8, NonZeroU16}; +use std::num::NonZero; use std::ptr; use std::ptr::NonNull; use std::borrow::Cow; @@ -110,14 +111,14 @@ enum Option2 { // Two layouts are considered for `CanBeNicheFilledButShouldnt`: // Niche-filling: -// { u32 (4 bytes), NonZeroU8 + tag in niche (1 byte), padding (3 bytes) } +// { u32 (4 bytes), NonZero + tag in niche (1 byte), padding (3 bytes) } // Tagged: -// { tag (1 byte), NonZeroU8 (1 byte), padding (2 bytes), u32 (4 bytes) } +// { tag (1 byte), NonZero (1 byte), padding (2 bytes), u32 (4 bytes) } // Both are the same size (due to padding), // but the tagged layout is better as the tag creates a niche with 254 invalid values, // allowing types like `Option>` to fit into 8 bytes. pub enum CanBeNicheFilledButShouldnt { - A(NonZeroU8, u32), + A(NonZero, u32), B } pub enum AlwaysTaggedBecauseItHasNoNiche { @@ -135,7 +136,7 @@ pub enum NicheFilledMultipleFields { G, } -struct BoolInTheMiddle(std::num::NonZeroU16, bool, u8); +struct BoolInTheMiddle(NonZero, bool, u8); enum NicheWithData { A, @@ -275,7 +276,7 @@ pub fn main() { assert_eq!(size_of::>(), 2); assert_eq!(size_of::>>(), 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, c: u16, d: u8, e: u32, f: u64, g:[u8;2] } assert_eq!(size_of::(), 24); assert_eq!(size_of::>(), 24); @@ -287,14 +288,14 @@ pub fn main() { size_of::<(&(), NicheWithData)>() ); - pub enum FillPadding { A(std::num::NonZeroU8, u32), B } + pub enum FillPadding { A(NonZero, u32), B } assert_eq!(size_of::(), 8); assert_eq!(size_of::>(), 8); assert_eq!(size_of::>>(), 8); - assert_eq!(size_of::>(), 4); - assert_eq!(size_of::>>(), 4); - assert_eq!(size_of::>(), 4); + assert_eq!(size_of::, u8, u8), u16>>(), 4); + assert_eq!(size_of::, u8, u8), u16>>>(), 4); + assert_eq!(size_of::, u8, u8, u8), u16>>(), 4); assert_eq!(size_of::>(), 6); assert_eq!(size_of::>(), 4); @@ -314,10 +315,10 @@ pub fn main() { assert_eq!(ptr::from_ref(&v), ptr::from_ref(&v.r.ptr).cast(), "sort niches to the front where possible"); - // Ideal layouts: (bool, u8, NonZeroU16) or (NonZeroU16, u8, bool) + // Ideal layouts: (bool, u8, NonZero) or (NonZero, u8, bool) // 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. - 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_eq!(size_of::>(), size_of::()); diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.rs b/tests/ui/suggestions/core-std-import-order-issue-83564.rs index 2cf1983858a65..62b9b246cc81b 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.rs +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.rs @@ -1,10 +1,11 @@ //@ edition:2018 - +// // This is a regression test for #83564. // For some reason, Rust 2018 or higher is required to reproduce the bug. +#![feature(generic_nonzero)] fn main() { //~^ HELP consider importing one of these items - let _x = NonZeroU32::new(5).unwrap(); - //~^ ERROR failed to resolve: use of undeclared type `NonZeroU32` + let _x = NonZero::new(5u32).unwrap(); + //~^ ERROR failed to resolve: use of undeclared type `NonZero` } diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr index c2634e3070ea9..56e10b9340c0b 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr @@ -1,14 +1,14 @@ -error[E0433]: failed to resolve: use of undeclared type `NonZeroU32` - --> $DIR/core-std-import-order-issue-83564.rs:8:14 +error[E0433]: failed to resolve: use of undeclared type `NonZero` + --> $DIR/core-std-import-order-issue-83564.rs:9:14 | -LL | let _x = NonZeroU32::new(5).unwrap(); - | ^^^^^^^^^^ use of undeclared type `NonZeroU32` +LL | let _x = NonZero::new(5u32).unwrap(); + | ^^^^^^^ use of undeclared type `NonZero` | 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 diff --git a/tests/ui/traits/next-solver/specialization-transmute.rs b/tests/ui/traits/next-solver/specialization-transmute.rs index 41c9032201138..17c55fb4d49df 100644 --- a/tests/ui/traits/next-solver/specialization-transmute.rs +++ b/tests/ui/traits/next-solver/specialization-transmute.rs @@ -1,6 +1,6 @@ //@ compile-flags: -Znext-solver //~^ ERROR cannot normalize `::Id: '_` - +#![feature(generic_nonzero)] #![feature(specialization)] //~^ WARN the feature `specialization` is incomplete @@ -23,8 +23,9 @@ fn transmute, U: Copy>(t: T) -> U { *t.intu() } -use std::num::NonZeroU8; +use std::num::NonZero; + fn main() { - let s = transmute::>(0); //~ ERROR cannot satisfy + let s = transmute::>>(0); //~ ERROR cannot satisfy assert_eq!(s, None); } diff --git a/tests/ui/traits/next-solver/specialization-transmute.stderr b/tests/ui/traits/next-solver/specialization-transmute.stderr index c87612d6a26ec..65e3370032522 100644 --- a/tests/ui/traits/next-solver/specialization-transmute.stderr +++ b/tests/ui/traits/next-solver/specialization-transmute.stderr @@ -23,10 +23,10 @@ LL | self | ^^^^ cannot satisfy `T <: ::Id` error[E0284]: type annotations needed: cannot satisfy `::Id == Option>` - --> $DIR/specialization-transmute.rs:28:13 + --> $DIR/specialization-transmute.rs:29:13 | -LL | let s = transmute::>(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `::Id == Option>` +LL | let s = transmute::>>(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `::Id == Option>` | note: required by a bound in `transmute` --> $DIR/specialization-transmute.rs:22:25