diff options
| author | bors <bors@rust-lang.org> | 2019-12-23 18:28:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-23 18:28:33 +0000 |
| commit | 9ae6cedb8d1e37469be1434642a3e403fce50a03 (patch) | |
| tree | 94ea2d34cd99239633126bd50f0f0a5663e233b3 /src/test/ui | |
| parent | a916ac22b9f7f1f0f7aba0a41a789b3ecd765018 (diff) | |
| parent | 68a9a2d64888be73fda2d00ea1f5c121bc08164b (diff) | |
| download | rust-9ae6cedb8d1e37469be1434642a3e403fce50a03.tar.gz rust-9ae6cedb8d1e37469be1434642a3e403fce50a03.zip | |
Auto merge of #67560 - Centril:rollup-fzdpu9c, r=Centril
Rollup of 8 pull requests
Successful merges:
- #67233 (Add PartialEq and Eq to Cursor)
- #67466 (Require const stability attributes on intrinsics to be able to use them in constant contexts)
- #67507 (Remove mem::uninitalized from tests)
- #67527 (Results show too much)
- #67536 (Move `{hir::lowering -> hir}::is_range_literal`)
- #67538 (Improve diagnostics for invalid assignment)
- #67546 (Fix ICE in mir interpretation)
- #67559 (Document that calling Drop, even after it panics, is UB)
Failed merges:
r? @ghost
Diffstat (limited to 'src/test/ui')
31 files changed, 332 insertions, 98 deletions
diff --git a/src/test/ui/abi/stack-probes.rs b/src/test/ui/abi/stack-probes.rs index 1ab1d6df66d..1d5b362e29d 100644 --- a/src/test/ui/abi/stack-probes.rs +++ b/src/test/ui/abi/stack-probes.rs @@ -13,7 +13,7 @@ // ignore-sgx no processes // ignore-musl FIXME #31506 -use std::mem; +use std::mem::MaybeUninit; use std::process::Command; use std::thread; use std::env; @@ -28,8 +28,8 @@ fn main() { let args = env::args().skip(1).collect::<Vec<_>>(); if args.len() > 0 { match &args[0][..] { - "main-thread" => recurse(&[]), - "child-thread" => thread::spawn(|| recurse(&[])).join().unwrap(), + "main-thread" => recurse(&MaybeUninit::uninit()), + "child-thread" => thread::spawn(|| recurse(&MaybeUninit::uninit())).join().unwrap(), _ => panic!(), } return @@ -48,10 +48,11 @@ fn main() { } #[allow(unconditional_recursion)] -fn recurse(array: &[u64]) { - unsafe { black_box(array.as_ptr() as u64); } - #[allow(deprecated)] - let local: [_; 1024] = unsafe { mem::uninitialized() }; +fn recurse(array: &MaybeUninit<[u64; 1024]>) { + unsafe { + black_box(array.as_ptr() as u64); + } + let local: MaybeUninit<[u64; 1024]> = MaybeUninit::uninit(); recurse(&local); } diff --git a/src/test/ui/bad/bad-expr-lhs.rs b/src/test/ui/bad/bad-expr-lhs.rs index 2cd8bc9d473..d7cf1b77005 100644 --- a/src/test/ui/bad/bad-expr-lhs.rs +++ b/src/test/ui/bad/bad-expr-lhs.rs @@ -1,10 +1,10 @@ fn main() { - 1 = 2; //~ ERROR invalid left-hand side expression - 1 += 2; //~ ERROR invalid left-hand side expression - (1, 2) = (3, 4); //~ ERROR invalid left-hand side expression + 1 = 2; //~ ERROR invalid left-hand side of assignment + 1 += 2; //~ ERROR invalid left-hand side of assignment + (1, 2) = (3, 4); //~ ERROR invalid left-hand side of assignment let (a, b) = (1, 2); - (a, b) = (3, 4); //~ ERROR invalid left-hand side expression + (a, b) = (3, 4); //~ ERROR invalid left-hand side of assignment - None = Some(3); //~ ERROR invalid left-hand side expression + None = Some(3); //~ ERROR invalid left-hand side of assignment } diff --git a/src/test/ui/bad/bad-expr-lhs.stderr b/src/test/ui/bad/bad-expr-lhs.stderr index a0de6a73797..a195e1054d0 100644 --- a/src/test/ui/bad/bad-expr-lhs.stderr +++ b/src/test/ui/bad/bad-expr-lhs.stderr @@ -1,32 +1,45 @@ -error[E0070]: invalid left-hand side expression - --> $DIR/bad-expr-lhs.rs:2:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/bad-expr-lhs.rs:2:7 | LL | 1 = 2; - | ^^^^^ left-hand of expression not valid + | - ^ + | | + | cannot assign to this expression -error[E0067]: invalid left-hand side expression - --> $DIR/bad-expr-lhs.rs:3:5 +error[E0067]: invalid left-hand side of assignment + --> $DIR/bad-expr-lhs.rs:3:7 | LL | 1 += 2; - | ^ invalid expression for left-hand side + | - ^^ + | | + | cannot assign to this expression -error[E0070]: invalid left-hand side expression - --> $DIR/bad-expr-lhs.rs:4:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/bad-expr-lhs.rs:4:12 | LL | (1, 2) = (3, 4); - | ^^^^^^^^^^^^^^^ left-hand of expression not valid + | ------ ^ + | | + | cannot assign to this expression -error[E0070]: invalid left-hand side expression - --> $DIR/bad-expr-lhs.rs:7:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/bad-expr-lhs.rs:7:12 | LL | (a, b) = (3, 4); - | ^^^^^^^^^^^^^^^ left-hand of expression not valid + | ------ ^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 -error[E0070]: invalid left-hand side expression - --> $DIR/bad-expr-lhs.rs:9:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/bad-expr-lhs.rs:9:10 | LL | None = Some(3); - | ^^^^^^^^^^^^^^ left-hand of expression not valid + | ---- ^ + | | + | cannot assign to this expression error: aborting due to 5 previous errors diff --git a/src/test/ui/const-generics/issues/issue-61422.rs b/src/test/ui/const-generics/issues/issue-61422.rs index 45d37b6a2f3..4fa150ffef0 100644 --- a/src/test/ui/const-generics/issues/issue-61422.rs +++ b/src/test/ui/const-generics/issues/issue-61422.rs @@ -5,6 +5,10 @@ use std::mem; +// Neither of the uninits below are currently accepted as not UB, however, +// this code does not run and is merely checking that we do not ICE on this pattern, +// so this is fine. + fn foo<const SIZE: usize>() { let arr: [u8; SIZE] = unsafe { #[allow(deprecated)] @@ -13,4 +17,12 @@ fn foo<const SIZE: usize>() { }; } +fn bar<const SIZE: usize>() { + let arr: [u8; SIZE] = unsafe { + let array: [u8; SIZE] = mem::MaybeUninit::uninit().assume_init(); + array + }; +} + + fn main() {} diff --git a/src/test/ui/consts/const-eval/simd/insert_extract.rs b/src/test/ui/consts/const-eval/simd/insert_extract.rs index d3462d802ea..92231d4ced3 100644 --- a/src/test/ui/consts/const-eval/simd/insert_extract.rs +++ b/src/test/ui/consts/const-eval/simd/insert_extract.rs @@ -2,6 +2,8 @@ #![feature(const_fn)] #![feature(repr_simd)] #![feature(platform_intrinsics)] +#![feature(staged_api)] +#![stable(feature = "foo", since = "1.33.7")] #![allow(non_camel_case_types)] #[repr(simd)] struct i8x1(i8); @@ -9,7 +11,9 @@ #[repr(simd)] struct f32x3(f32, f32, f32); extern "platform-intrinsic" { + #[rustc_const_stable(feature = "foo", since = "1.3.37")] fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T; + #[rustc_const_stable(feature = "foo", since = "1.3.37")] fn simd_extract<T, U>(x: T, idx: u32) -> U; } diff --git a/src/test/ui/consts/const-fn-type-name.rs b/src/test/ui/consts/const-fn-type-name.rs index 2bb1aeecf37..72fac19c191 100644 --- a/src/test/ui/consts/const-fn-type-name.rs +++ b/src/test/ui/consts/const-fn-type-name.rs @@ -2,6 +2,7 @@ #![feature(core_intrinsics)] #![feature(const_fn)] +#![feature(const_type_name)] #![allow(dead_code)] const fn type_name_wrapper<T>(_: &T) -> &'static str { diff --git a/src/test/ui/consts/const_prop_slice_pat_ice.rs b/src/test/ui/consts/const_prop_slice_pat_ice.rs new file mode 100644 index 00000000000..5fec36e44bd --- /dev/null +++ b/src/test/ui/consts/const_prop_slice_pat_ice.rs @@ -0,0 +1,9 @@ +// check-pass +#![feature(slice_patterns)] + +fn main() { + match &[0, 1] as &[i32] { + [a @ .., x] => {} + &[] => {} + } +} diff --git a/src/test/ui/destructuring-assignment/note-unsupported.rs b/src/test/ui/destructuring-assignment/note-unsupported.rs new file mode 100644 index 00000000000..876c9efea26 --- /dev/null +++ b/src/test/ui/destructuring-assignment/note-unsupported.rs @@ -0,0 +1,25 @@ +struct S { x: u8, y: u8 } + +fn main() { + let (a, b) = (1, 2); + + (a, b) = (3, 4); //~ ERROR invalid left-hand side of assignment + (a, b) += (3, 4); //~ ERROR invalid left-hand side of assignment + //~^ ERROR binary assignment operation `+=` cannot be applied + + [a, b] = [3, 4]; //~ ERROR invalid left-hand side of assignment + [a, b] += [3, 4]; //~ ERROR invalid left-hand side of assignment + //~^ ERROR binary assignment operation `+=` cannot be applied + + let s = S { x: 3, y: 4 }; + + S { x: a, y: b } = s; //~ ERROR invalid left-hand side of assignment + S { x: a, y: b } += s; //~ ERROR invalid left-hand side of assignment + //~^ ERROR binary assignment operation `+=` cannot be applied + + S { x: a, ..s } = S { x: 3, y: 4 }; //~ ERROR invalid left-hand side of assignment + + let c = 3; + + ((a, b), c) = ((3, 4), 5); //~ ERROR invalid left-hand side of assignment +} diff --git a/src/test/ui/destructuring-assignment/note-unsupported.stderr b/src/test/ui/destructuring-assignment/note-unsupported.stderr new file mode 100644 index 00000000000..a6805c32a6e --- /dev/null +++ b/src/test/ui/destructuring-assignment/note-unsupported.stderr @@ -0,0 +1,122 @@ +error[E0070]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:6:12 + | +LL | (a, b) = (3, 4); + | ------ ^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0368]: binary assignment operation `+=` cannot be applied to type `({integer}, {integer})` + --> $DIR/note-unsupported.rs:7:5 + | +LL | (a, b) += (3, 4); + | ------^^^^^^^^^^ + | | + | cannot use `+=` on type `({integer}, {integer})` + | + = note: an implementation of `std::ops::AddAssign` might be missing for `({integer}, {integer})` + +error[E0067]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:7:12 + | +LL | (a, b) += (3, 4); + | ------ ^^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0070]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:10:12 + | +LL | [a, b] = [3, 4]; + | ------ ^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0368]: binary assignment operation `+=` cannot be applied to type `[{integer}; 2]` + --> $DIR/note-unsupported.rs:11:5 + | +LL | [a, b] += [3, 4]; + | ------^^^^^^^^^^ + | | + | cannot use `+=` on type `[{integer}; 2]` + | + = note: an implementation of `std::ops::AddAssign` might be missing for `[{integer}; 2]` + +error[E0067]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:11:12 + | +LL | [a, b] += [3, 4]; + | ------ ^^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0070]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:16:22 + | +LL | S { x: a, y: b } = s; + | ---------------- ^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0368]: binary assignment operation `+=` cannot be applied to type `S` + --> $DIR/note-unsupported.rs:17:5 + | +LL | S { x: a, y: b } += s; + | ----------------^^^^^ + | | + | cannot use `+=` on type `S` + | + = note: an implementation of `std::ops::AddAssign` might be missing for `S` + +error[E0067]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:17:22 + | +LL | S { x: a, y: b } += s; + | ---------------- ^^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0070]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:20:21 + | +LL | S { x: a, ..s } = S { x: 3, y: 4 }; + | --------------- ^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error[E0070]: invalid left-hand side of assignment + --> $DIR/note-unsupported.rs:24:17 + | +LL | ((a, b), c) = ((3, 4), 5); + | ----------- ^ + | | + | cannot assign to this expression + | + = note: destructuring assignments are not currently supported + = note: for more information, see https://github.com/rust-lang/rfcs/issues/372 + +error: aborting due to 11 previous errors + +Some errors have detailed explanations: E0067, E0070, E0368. +For more information about an error, try `rustc --explain E0067`. diff --git a/src/test/ui/error-codes/E0067.stderr b/src/test/ui/error-codes/E0067.stderr index 0334565840f..526503798b3 100644 --- a/src/test/ui/error-codes/E0067.stderr +++ b/src/test/ui/error-codes/E0067.stderr @@ -8,11 +8,13 @@ LL | LinkedList::new() += 1; | = note: an implementation of `std::ops::AddAssign` might be missing for `std::collections::LinkedList<_>` -error[E0067]: invalid left-hand side expression - --> $DIR/E0067.rs:4:5 +error[E0067]: invalid left-hand side of assignment + --> $DIR/E0067.rs:4:23 | LL | LinkedList::new() += 1; - | ^^^^^^^^^^^^^^^^^ invalid expression for left-hand side + | ----------------- ^^ + | | + | cannot assign to this expression error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0070.stderr b/src/test/ui/error-codes/E0070.stderr index 845833bc82f..d809bb18dee 100644 --- a/src/test/ui/error-codes/E0070.stderr +++ b/src/test/ui/error-codes/E0070.stderr @@ -1,14 +1,18 @@ -error[E0070]: invalid left-hand side expression - --> $DIR/E0070.rs:6:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/E0070.rs:6:16 | LL | SOME_CONST = 14; - | ^^^^^^^^^^^^^^^ left-hand of expression not valid + | ---------- ^ + | | + | cannot assign to this expression -error[E0070]: invalid left-hand side expression - --> $DIR/E0070.rs:7:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/E0070.rs:7:7 | LL | 1 = 3; - | ^^^^^ left-hand of expression not valid + | - ^ + | | + | cannot assign to this expression error[E0308]: mismatched types --> $DIR/E0070.rs:8:25 @@ -16,11 +20,13 @@ error[E0308]: mismatched types LL | some_other_func() = 4; | ^ expected `()`, found integer -error[E0070]: invalid left-hand side expression - --> $DIR/E0070.rs:8:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/E0070.rs:8:23 | LL | some_other_func() = 4; - | ^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid + | ----------------- ^ + | | + | cannot assign to this expression error: aborting due to 4 previous errors diff --git a/src/test/ui/for-loop-while/for-loop-has-unit-body.rs b/src/test/ui/for-loop-while/for-loop-has-unit-body.rs index 38c34d2dc2e..eba385461b9 100644 --- a/src/test/ui/for-loop-while/for-loop-has-unit-body.rs +++ b/src/test/ui/for-loop-while/for-loop-has-unit-body.rs @@ -2,8 +2,8 @@ fn main() { // Check that the tail statement in the body unifies with something for _ in 0..3 { - #[allow(deprecated)] - unsafe { std::mem::uninitialized() } + // `()` is fine to zero-initialize as it is zero sized and inhabited. + unsafe { std::mem::zeroed() } } // Check that the tail statement in the body can be unit diff --git a/src/test/ui/issues/issue-13407.rs b/src/test/ui/issues/issue-13407.rs index 322e67cc131..fa53d55f5b3 100644 --- a/src/test/ui/issues/issue-13407.rs +++ b/src/test/ui/issues/issue-13407.rs @@ -4,7 +4,7 @@ mod A { fn main() { A::C = 1; - //~^ ERROR: invalid left-hand side expression + //~^ ERROR: invalid left-hand side of assignment //~| ERROR: mismatched types //~| ERROR: struct `C` is private } diff --git a/src/test/ui/issues/issue-13407.stderr b/src/test/ui/issues/issue-13407.stderr index 5a465cc533b..b280de3158f 100644 --- a/src/test/ui/issues/issue-13407.stderr +++ b/src/test/ui/issues/issue-13407.stderr @@ -10,11 +10,13 @@ error[E0308]: mismatched types LL | A::C = 1; | ^ expected struct `A::C`, found integer -error[E0070]: invalid left-hand side expression - --> $DIR/issue-13407.rs:6:5 +error[E0070]: invalid left-hand side of assignment + --> $DIR/issue-13407.rs:6:10 | LL | A::C = 1; - | ^^^^^^^^ left-hand of expression not valid + | ---- ^ + | | + | cannot assign to this expression error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-26093.rs b/src/test/ui/issues/issue-26093.rs index 7895c90068f..c838515caf9 100644 --- a/src/test/ui/issues/issue-26093.rs +++ b/src/test/ui/issues/issue-26093.rs @@ -1,7 +1,9 @@ macro_rules! not_a_place { ($thing:expr) => { $thing = 42; - //~^ ERROR invalid left-hand side expression + //~^ ERROR invalid left-hand side of assignment + $thing += 42; + //~^ ERROR invalid left-hand side of assignment } } diff --git a/src/test/ui/issues/issue-26093.stderr b/src/test/ui/issues/issue-26093.stderr index 947c52f08d2..c96228b518a 100644 --- a/src/test/ui/issues/issue-26093.stderr +++ b/src/test/ui/issues/issue-26093.stderr @@ -1,12 +1,28 @@ -error[E0070]: invalid left-hand side expression - --> $DIR/issue-26093.rs:3:9 +error[E0070]: invalid left-hand side of assignment + --> $DIR/issue-26093.rs:3:16 | LL | $thing = 42; - | ^^^^^^^^^^^ left-hand of expression not valid + | ^ ... LL | not_a_place!(99); - | ----------------- in this macro invocation + | ----------------- + | | | + | | cannot assign to this expression + | in this macro invocation -error: aborting due to previous error +error[E0067]: invalid left-hand side of assignment + --> $DIR/issue-26093.rs:5:16 + | +LL | $thing += 42; + | ^^ +... +LL | not_a_place!(99); + | ----------------- + | | | + | | cannot assign to this expression + | in this macro invocation + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0070`. +Some errors have detailed explanations: E0067, E0070. +For more information about an error, try `rustc --explain E0067`. diff --git a/src/test/ui/issues/issue-34334.rs b/src/test/ui/issues/issue-34334.rs index 4457d71cbb4..e34b5c9a0f4 100644 --- a/src/test/ui/issues/issue-34334.rs +++ b/src/test/ui/issues/issue-34334.rs @@ -3,7 +3,7 @@ fn main () { //~^ ERROR expected one of `,` or `>`, found `=` //~| ERROR expected value, found struct `Vec` //~| ERROR mismatched types - //~| ERROR invalid left-hand side expression + //~| ERROR invalid left-hand side of assignment //~| ERROR expected expression, found reserved identifier `_` //~| ERROR expected expression, found reserved identifier `_` let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index fc90e0674cf..3055e316a08 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -35,11 +35,13 @@ LL | let sr: Vec<(u32, _, _) = vec![]; found struct `std::vec::Vec<_>` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error[E0070]: invalid left-hand side expression - --> $DIR/issue-34334.rs:2:13 +error[E0070]: invalid left-hand side of assignment + --> $DIR/issue-34334.rs:2:29 | LL | let sr: Vec<(u32, _, _) = vec![]; - | ^^^^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid + | --------------- ^ + | | + | cannot assign to this expression error[E0599]: no method named `iter` found for type `()` in the current scope --> $DIR/issue-34334.rs:9:36 diff --git a/src/test/ui/issues/issue-48131.rs b/src/test/ui/issues/issue-48131.rs index c8540729352..85664e62ead 100644 --- a/src/test/ui/issues/issue-48131.rs +++ b/src/test/ui/issues/issue-48131.rs @@ -1,7 +1,7 @@ // This note is annotated because the purpose of the test // is to ensure that certain other notes are not generated. #![deny(unused_unsafe)] //~ NOTE -#![allow(deprecated)] + // (test that no note is generated on this unsafe fn) pub unsafe fn a() { @@ -20,8 +20,8 @@ pub fn b() { unsafe { /* unnecessary */ } //~ ERROR unnecessary `unsafe` //~^ NOTE } - - let () = ::std::mem::uninitialized(); + // `()` is fine to zero-initialize as it is zero sized and inhabited. + let () = ::std::mem::zeroed(); inner() } diff --git a/src/test/ui/issues/issue-58212.rs b/src/test/ui/issues/issue-58212.rs index 21dcdd56bf6..4695497c3a1 100644 --- a/src/test/ui/issues/issue-58212.rs +++ b/src/test/ui/issues/issue-58212.rs @@ -1,13 +1,12 @@ -// run-pass +// check-pass trait FromUnchecked { - unsafe fn from_unchecked(); + fn from_unchecked(); } impl FromUnchecked for [u8; 1] { - unsafe fn from_unchecked() { - #[allow(deprecated)] - let mut array: Self = std::mem::uninitialized(); + fn from_unchecked() { + let mut array: Self = [0; 1]; let _ptr = &mut array as *mut [u8] as *mut u8; } } diff --git a/src/test/ui/structs-enums/enum-non-c-like-repr-c-and-int.rs b/src/test/ui/structs-enums/enum-non-c-like-repr-c-and-int.rs index 78d8e5e3a5d..7d15d607dd6 100644 --- a/src/test/ui/structs-enums/enum-non-c-like-repr-c-and-int.rs +++ b/src/test/ui/structs-enums/enum-non-c-like-repr-c-and-int.rs @@ -69,8 +69,10 @@ fn main() { unsafe { // This should be safe, because we don't match on it unless it's fully formed, // and it doesn't have a destructor. - #[allow(deprecated)] - let mut dest: MyEnum = mem::uninitialized(); + // + // MyEnum is repr(C, u8) so it is guaranteed to have a separate discriminant and each + // variant can be zero initialized. + let mut dest: MyEnum = mem::zeroed(); while buf.len() > 0 { match parse_my_enum(&mut dest, &mut buf) { Ok(()) => output.push(Ok(dest)), diff --git a/src/test/ui/structs-enums/enum-non-c-like-repr-c.rs b/src/test/ui/structs-enums/enum-non-c-like-repr-c.rs index 1209533efda..fc9efdeca7d 100644 --- a/src/test/ui/structs-enums/enum-non-c-like-repr-c.rs +++ b/src/test/ui/structs-enums/enum-non-c-like-repr-c.rs @@ -69,8 +69,11 @@ fn main() { unsafe { // This should be safe, because we don't match on it unless it's fully formed, // and it doesn't have a destructor. - #[allow(deprecated)] - let mut dest: MyEnum = mem::uninitialized(); + // + // Furthermore, there are no types within MyEnum which cannot be initialized with zero, + // specifically, though padding and such are present, there are no references or similar + // types. + let mut dest: MyEnum = mem::zeroed(); while buf.len() > 0 { match parse_my_enum(&mut dest, &mut buf) { Ok(()) => output.push(Ok(dest)), diff --git a/src/test/ui/structs-enums/enum-non-c-like-repr-int.rs b/src/test/ui/structs-enums/enum-non-c-like-repr-int.rs index 5dd9c1863d6..f9e96c1a0f4 100644 --- a/src/test/ui/structs-enums/enum-non-c-like-repr-int.rs +++ b/src/test/ui/structs-enums/enum-non-c-like-repr-int.rs @@ -65,8 +65,10 @@ fn main() { unsafe { // This should be safe, because we don't match on it unless it's fully formed, // and it doesn't have a destructor. - #[allow(deprecated)] - let mut dest: MyEnum = mem::uninitialized(); + // + // MyEnum is repr(u8) so it is guaranteed to have a separate discriminant and each variant + // can be zero initialized. + let mut dest: MyEnum = mem::zeroed(); while buf.len() > 0 { match parse_my_enum(&mut dest, &mut buf) { Ok(()) => output.push(Ok(dest)), diff --git a/src/test/ui/type/type-check/assignment-expected-bool.rs b/src/test/ui/type/type-check/assignment-expected-bool.rs index 03830fea062..191939bdb70 100644 --- a/src/test/ui/type/type-check/assignment-expected-bool.rs +++ b/src/test/ui/type/type-check/assignment-expected-bool.rs @@ -30,5 +30,5 @@ fn main() { // A test to check that not expecting `bool` behaves well: let _: usize = 0 = 0; //~^ ERROR mismatched types [E0308] - //~| ERROR invalid left-hand side expression [E0070] + //~| ERROR invalid left-hand side of assignment [E0070] } diff --git a/src/test/ui/type/type-check/assignment-expected-bool.stderr b/src/test/ui/type/type-check/assignment-expected-bool.stderr index 9a1cf5b2562..3f1caddf728 100644 --- a/src/test/ui/type/type-check/assignment-expected-bool.stderr +++ b/src/test/ui/type/type-check/assignment-expected-bool.stderr @@ -97,11 +97,13 @@ LL | || (0 = 0); | expected `bool`, found `()` | help: try comparing for equality: `0 == 0` -error[E0070]: invalid left-hand side expression - --> $DIR/assignment-expected-bool.rs:31:20 +error[E0070]: invalid left-hand side of assignment + --> $DIR/assignment-expected-bool.rs:31:22 | LL | let _: usize = 0 = 0; - | ^^^^^ left-hand of expression not valid + | - ^ + | | + | cannot assign to this expression error[E0308]: mismatched types --> $DIR/assignment-expected-bool.rs:31:20 diff --git a/src/test/ui/type/type-check/assignment-in-if.rs b/src/test/ui/type/type-check/assignment-in-if.rs index 77b122b0a79..8da7b32b47b 100644 --- a/src/test/ui/type/type-check/assignment-in-if.rs +++ b/src/test/ui/type/type-check/assignment-in-if.rs @@ -26,7 +26,7 @@ fn main() { //~^ ERROR mismatched types println!("{}", x); } - // "invalid left-hand side expression" error is suppresed + // "invalid left-hand side of assignment" error is suppresed if 3 = x { //~^ ERROR mismatched types println!("{}", x); diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs index a5360fa13c4..e804afcf9ed 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs @@ -1,5 +1,4 @@ -#![allow(deprecated)] - +use std::mem::zeroed; enum Void {} fn main() { @@ -8,21 +7,25 @@ fn main() { Ok(n) => n, }; - let x: &Void = unsafe { std::mem::uninitialized() }; + // This is pretty much instant UB. However, we have no choice -- we need to + // test matching on a reference to `&Void`; we cannot do anything other than + // just accept the fact that this is UB if `main` did run, but it doesn't; + // this test only checks that these are feature-gated. + let x: &Void = unsafe { zeroed() }; let _ = match x {}; //~ ERROR non-exhaustive - let x: (Void,) = unsafe { std::mem::uninitialized() }; + let x: (Void,) = unsafe { zeroed() }; let _ = match x {}; //~ ERROR non-exhaustive - let x: [Void; 1] = unsafe { std::mem::uninitialized() }; + let x: [Void; 1] = unsafe { zeroed() }; let _ = match x {}; //~ ERROR non-exhaustive - let x: &[Void] = unsafe { std::mem::uninitialized() }; + let x: &[Void] = unsafe { zeroed() }; let _ = match x { //~ ERROR non-exhaustive &[] => (), }; - let x: Void = unsafe { std::mem::uninitialized() }; + let x: Void = unsafe { zeroed() }; let _ = match x {}; // okay let x: Result<u32, Void> = Ok(23); diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr index 18ffdccb9b2..a667e1fe2da 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:7:19 + --> $DIR/uninhabited-matches-feature-gated.rs:6:19 | LL | let _ = match x { | ^ pattern `Err(_)` not covered @@ -7,7 +7,7 @@ LL | let _ = match x { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: type `&Void` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:12:19 + --> $DIR/uninhabited-matches-feature-gated.rs:15:19 | LL | enum Void {} | ------------ `Void` defined here @@ -18,7 +18,7 @@ LL | let _ = match x {}; = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: type `(Void,)` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:15:19 + --> $DIR/uninhabited-matches-feature-gated.rs:18:19 | LL | let _ = match x {}; | ^ @@ -26,7 +26,7 @@ LL | let _ = match x {}; = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: type `[Void; 1]` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:18:19 + --> $DIR/uninhabited-matches-feature-gated.rs:21:19 | LL | let _ = match x {}; | ^ @@ -34,7 +34,7 @@ LL | let _ = match x {}; = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:21:19 + --> $DIR/uninhabited-matches-feature-gated.rs:24:19 | LL | let _ = match x { | ^ pattern `&[_, ..]` not covered @@ -42,7 +42,7 @@ LL | let _ = match x { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:29:19 + --> $DIR/uninhabited-matches-feature-gated.rs:32:19 | LL | let _ = match x { | ^ pattern `Err(_)` not covered @@ -50,7 +50,7 @@ LL | let _ = match x { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0005]: refutable pattern in local binding: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:34:9 + --> $DIR/uninhabited-matches-feature-gated.rs:37:9 | LL | let Ok(x) = x; | ^^^^^ pattern `Err(_)` not covered diff --git a/src/test/ui/uninit-empty-types.rs b/src/test/ui/uninit-empty-types.rs index 0d1235776a6..b21de882b2c 100644 --- a/src/test/ui/uninit-empty-types.rs +++ b/src/test/ui/uninit-empty-types.rs @@ -1,17 +1,19 @@ -// run-pass +// build-pass // Test the uninit() construct returning various empty types. // pretty-expanded FIXME #23616 -use std::mem; +use std::mem::MaybeUninit; -#[derive(Clone)] struct Foo; #[allow(deprecated)] pub fn main() { unsafe { - let _x: Foo = mem::uninitialized(); - let _x: [Foo; 2] = mem::uninitialized(); + // `Foo` and `[Foo; 2]` are both zero sized and inhabited, so this is safe. + let _x: Foo = MaybeUninit::uninit().assume_init(); + let _x: [Foo; 2] = MaybeUninit::uninit().assume_init(); + let _x: Foo = std::mem::uninitialized(); + let _x: [Foo; 2] = std::mem::uninitialized(); } } diff --git a/src/test/ui/where-clauses/where-equality-constraints.rs b/src/test/ui/where-clauses/where-equality-constraints.rs index f2349144b88..8828f09d92d 100644 --- a/src/test/ui/where-clauses/where-equality-constraints.rs +++ b/src/test/ui/where-clauses/where-equality-constraints.rs @@ -1,6 +1,6 @@ fn f() where u8 = u16 {} -//~^ ERROR equality constraints are not yet supported in where clauses +//~^ ERROR equality constraints are not yet supported in `where` clauses fn g() where for<'a> &'static (u8,) == u16, {} -//~^ ERROR equality constraints are not yet supported in where clauses +//~^ ERROR equality constraints are not yet supported in `where` clauses fn main() {} diff --git a/src/test/ui/where-clauses/where-equality-constraints.stderr b/src/test/ui/where-clauses/where-equality-constraints.stderr index 220447079c6..c0241fe708f 100644 --- a/src/test/ui/where-clauses/where-equality-constraints.stderr +++ b/src/test/ui/where-clauses/where-equality-constraints.stderr @@ -1,14 +1,18 @@ -error: equality constraints are not yet supported in where clauses (see #20041) +error: equality constraints are not yet supported in `where` clauses --> $DIR/where-equality-constraints.rs:1:14 | LL | fn f() where u8 = u16 {} | ^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/20041 -error: equality constraints are not yet supported in where clauses (see #20041) +error: equality constraints are not yet supported in `where` clauses --> $DIR/where-equality-constraints.rs:3:14 | LL | fn g() where for<'a> &'static (u8,) == u16, {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/20041 error: aborting due to 2 previous errors |
