Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9ee16e1
Require const stability attributes on intrinsics to be able to use th…
oli-obk Dec 20, 2019
032d810
Add a big notice about const intrinsics
oli-obk Dec 20, 2019
89986a3
add partialeq and eq to cursor
Luro02 Dec 11, 2019
4ce2384
Improve JS code a bit by avoid erasing all event handlers
GuillaumeGomez Dec 22, 2019
b677013
Improve code readability
GuillaumeGomez Dec 22, 2019
71ff18f
Fix invalid results showing back
GuillaumeGomez Dec 22, 2019
056dff5
Fix ICE in mir interpretation
oli-obk Dec 23, 2019
c205f6a
Remove mem::uninitalized from tests
Mark-Simulacrum Dec 22, 2019
5b8df34
Update src/librustc_mir/interpret/place.rs
oli-obk Dec 23, 2019
45acee3
Move `{hir::lowering -> hir}::is_range_literal`.
Centril Dec 22, 2019
a5991c5
Add the full issue reference to equality constraints in `where` clauses
varkor Dec 22, 2019
b7bfdbe
Improve invalid assignment error
varkor Dec 22, 2019
5fa02ec
Add note about destructuring assignments
varkor Dec 22, 2019
5ab4735
Recognise nested tuples/arrays/structs
varkor Dec 22, 2019
35979a9
Add span information to `ExprKind::Assign`
varkor Dec 22, 2019
9a60224
Add new folder for destructuring assignment tests
varkor Dec 22, 2019
dd7f493
is_range_literal: fix fallout
Centril Dec 22, 2019
4bb8346
is_range_literal: leave FIXME
Centril Dec 22, 2019
9e50813
Fix reformatting rebase issues
varkor Dec 23, 2019
a08df28
Document that calling Drop, even after it panics, is UB
Mark-Simulacrum Dec 23, 2019
63d2822
Fix typo
oli-obk Dec 23, 2019
260514d
Rollup merge of #67233 - Luro02:cursor_traits, r=sfackler
Centril Dec 23, 2019
1de2705
Rollup merge of #67466 - oli-obk:const_intrinsic, r=Centril
Centril Dec 23, 2019
67c0f4e
Rollup merge of #67507 - Mark-Simulacrum:purge-uninit, r=Centril
Centril Dec 23, 2019
6f38a15
Rollup merge of #67527 - GuillaumeGomez:results-show-too-much, r=kinn…
Centril Dec 23, 2019
3a07f3b
Rollup merge of #67536 - Centril:move-is_range_literal, r=Mark-Simula…
Centril Dec 23, 2019
4164761
Rollup merge of #67538 - varkor:lhs-assign-diagnostics, r=Centril
Centril Dec 23, 2019
7eb025f
Rollup merge of #67546 - oli-obk:slice_pattern_ice, r=varkor
Centril Dec 23, 2019
68a9a2d
Rollup merge of #67559 - Mark-Simulacrum:drop-doc, r=RalfJung
Centril Dec 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/test/run-make-fulldeps/sanitizer-memory/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
all:
$(RUSTC) -g -Z sanitizer=memory -Z print-link-args uninit.rs | $(CGREP) librustc_msan
$(TMPDIR)/uninit 2>&1 | $(CGREP) use-of-uninitialized-value
$(RUSTC) -g -Z sanitizer=memory -Z print-link-args maybeuninit.rs | $(CGREP) librustc_msan
$(TMPDIR)/maybeuninit 2>&1 | $(CGREP) use-of-uninitialized-value
8 changes: 8 additions & 0 deletions src/test/run-make-fulldeps/sanitizer-memory/maybeuninit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::mem::MaybeUninit;

fn main() {
// This is technically not sound -- but we're literally trying to test
// that the sanitizer catches this, so I guess "intentionally unsound"?
let xs: [u8; 4] = unsafe { MaybeUninit::uninit().assume_init() };
let y = xs[0] + xs[1];
}
6 changes: 3 additions & 3 deletions src/test/run-make-fulldeps/sanitizer-memory/uninit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::mem;

fn main() {
// This is technically not sound -- but we're literally trying to test
// that the sanitizer catches this, so I guess "intentionally unsound"?
#[allow(deprecated)]
let xs: [u8; 4] = unsafe { mem::uninitialized() };
let xs: [u8; 4] = unsafe { std::mem::uninitialized() };
let y = xs[0] + xs[1];
}
5 changes: 2 additions & 3 deletions src/test/rustdoc/issue-52873.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ impl<U: Unsigned, B: Bit> Add<B0> for UInt<U, B> {
impl<U: Unsigned> Add<U> for UTerm {
type Output = U;
fn add(self, _: U) -> Self::Output {
#[allow(deprecated)]
unsafe { ::std::mem::uninitialized() }
unimplemented!()
}
}

Expand Down Expand Up @@ -137,7 +136,7 @@ where
{
type Output = UInt<Prod<Ul, UInt<Ur, B>>, B0>;
fn mul(self, _: UInt<Ur, B>) -> Self::Output {
unsafe { ::std::mem::uninitialized() }
unimplemented!()
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/test/ui/abi/stack-probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/const-generics/issues/issue-61422.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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() {}
4 changes: 2 additions & 2 deletions src/test/ui/for-loop-while/for-loop-has-unit-body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-48131.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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()
}
Expand Down
9 changes: 4 additions & 5 deletions src/test/ui/issues/issue-58212.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/structs-enums/enum-non-c-like-repr-c-and-int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
7 changes: 5 additions & 2 deletions src/test/ui/structs-enums/enum-non-c-like-repr-c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/structs-enums/enum-non-c-like-repr-int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
17 changes: 10 additions & 7 deletions src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(deprecated)]

use std::mem::zeroed;
enum Void {}

fn main() {
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
|
= 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
Expand All @@ -18,39 +18,39 @@ 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 {};
| ^
|
= 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 {};
| ^
|
= 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
|
= 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
|
= 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
Expand Down
12 changes: 7 additions & 5 deletions src/test/ui/uninit-empty-types.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}