Skip to content

Commit 6e70bd4

Browse files
committed
fmt
1 parent c78cd65 commit 6e70bd4

11 files changed

+62
-48
lines changed

src/tools/miri/tests/fail/provenance/int_copy_looses_provenance3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum E {
1111
// Doing a copy at integer type should lose provenance.
1212
// This tests the case where provenacne is hiding in the discriminant of an enum.
1313
fn main() {
14-
assert_eq!(mem::size_of::<E>(), 2*mem::size_of::<usize>());
14+
assert_eq!(mem::size_of::<E>(), 2 * mem::size_of::<usize>());
1515

1616
// We want to store provenance in the enum discriminant, but the value still needs to
1717
// be valid atfor the type. So we split provenance and data.

src/tools/miri/tests/fail/uninit/padding-enum.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ enum E {
77
Some(&'static (), &'static (), usize),
88
}
99

10-
fn main() { unsafe {
11-
let mut p: mem::MaybeUninit<E> = mem::MaybeUninit::zeroed();
12-
// The copy when `E` is returned from `transmute` should destroy padding
13-
// (even when we use `write_unaligned`, which under the hood uses an untyped copy).
14-
p.as_mut_ptr().write_unaligned(mem::transmute((0usize, 0usize, 0usize)));
15-
// This is a `None`, so everything but the discriminant is padding.
16-
assert!(matches!(*p.as_ptr(), E::None));
10+
fn main() {
11+
unsafe {
12+
let mut p: mem::MaybeUninit<E> = mem::MaybeUninit::zeroed();
13+
// The copy when `E` is returned from `transmute` should destroy padding
14+
// (even when we use `write_unaligned`, which under the hood uses an untyped copy).
15+
p.as_mut_ptr().write_unaligned(mem::transmute((0usize, 0usize, 0usize)));
16+
// This is a `None`, so everything but the discriminant is padding.
17+
assert!(matches!(*p.as_ptr(), E::None));
1718

18-
// Turns out the discriminant is (currently) stored
19-
// in the 2nd pointer, so the first half is padding.
20-
let c = &p as *const _ as *const u8;
21-
let _val = *c.add(0); // Get a padding byte.
22-
//~^ERROR: uninitialized
23-
} }
19+
// Turns out the discriminant is (currently) stored
20+
// in the 2nd pointer, so the first half is padding.
21+
let c = &p as *const _ as *const u8;
22+
// Read a padding byte.
23+
let _val = *c.add(0);
24+
//~^ERROR: uninitialized
25+
}
26+
}

src/tools/miri/tests/fail/uninit/padding-enum.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> $DIR/padding-enum.rs:LL:CC
33
|
4-
LL | let _val = *c.add(0); // Get a padding byte.
5-
| ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4+
LL | let _val = *c.add(0);
5+
| ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/uninit/padding-struct.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ use std::mem;
33
#[repr(C)]
44
struct Pair(u8, u16);
55

6-
fn main() { unsafe {
7-
let p: Pair = mem::transmute(0u32); // The copy when `Pair` is returned from `transmute` should destroy padding.
8-
let c = &p as *const _ as *const u8;
9-
let _val = *c.add(1); // Get the padding byte.
10-
//~^ERROR: uninitialized
11-
} }
6+
fn main() {
7+
unsafe {
8+
let p: Pair = mem::transmute(0u32); // The copy when `Pair` is returned from `transmute` should destroy padding.
9+
let c = &p as *const _ as *const u8;
10+
// Read the padding byte.
11+
let _val = *c.add(1);
12+
//~^ERROR: uninitialized
13+
}
14+
}

src/tools/miri/tests/fail/uninit/padding-struct.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> $DIR/padding-struct.rs:LL:CC
33
|
4-
LL | let _val = *c.add(1); // Get the padding byte.
5-
| ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4+
LL | let _val = *c.add(1);
5+
| ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/uninit/padding-union.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ union U {
66
field: (u8, u16),
77
}
88

9-
fn main() { unsafe {
10-
let p: U = mem::transmute(0u32); // The copy when `U` is returned from `transmute` should destroy padding.
11-
let c = &p as *const _ as *const [u8; 4];
12-
let _val = *c; // Read the entire thing, definitely contains the padding byte.
13-
//~^ERROR: uninitialized
14-
} }
9+
fn main() {
10+
unsafe {
11+
let p: U = mem::transmute(0u32); // The copy when `U` is returned from `transmute` should destroy padding.
12+
let c = &p as *const _ as *const [u8; 4];
13+
// Read the entire thing, definitely contains the padding byte.
14+
let _val = *c;
15+
//~^ERROR: uninitialized
16+
}
17+
}

src/tools/miri/tests/fail/uninit/padding-union.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
22
--> $DIR/padding-union.rs:LL:CC
33
|
4-
LL | let _val = *c; // Read the entire thing, definitely contains the padding byte.
5-
| ^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
4+
LL | let _val = *c;
5+
| ^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/uninit/padding-wide-ptr.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ use std::mem;
33
// If this is `None`, the metadata becomes padding.
44
type T = Option<&'static str>;
55

6-
fn main() { unsafe {
7-
let mut p: mem::MaybeUninit<T> = mem::MaybeUninit::zeroed();
8-
// The copy when `T` is returned from `transmute` should destroy padding
9-
// (even when we use `write_unaligned`, which under the hood uses an untyped copy).
10-
p.as_mut_ptr().write_unaligned(mem::transmute((0usize, 0usize)));
11-
// Null epresents `None`.
12-
assert!(matches!(*p.as_ptr(), None));
6+
fn main() {
7+
unsafe {
8+
let mut p: mem::MaybeUninit<T> = mem::MaybeUninit::zeroed();
9+
// The copy when `T` is returned from `transmute` should destroy padding
10+
// (even when we use `write_unaligned`, which under the hood uses an untyped copy).
11+
p.as_mut_ptr().write_unaligned(mem::transmute((0usize, 0usize)));
12+
// Null epresents `None`.
13+
assert!(matches!(*p.as_ptr(), None));
1314

14-
// The second part, with the length, becomes padding.
15-
let c = &p as *const _ as *const u8;
16-
let _val = *c.add(mem::size_of::<*const u8>()); // Get a padding byte.
17-
//~^ERROR: uninitialized
18-
} }
15+
// The second part, with the length, becomes padding.
16+
let c = &p as *const _ as *const u8;
17+
// Read a padding byte.
18+
let _val = *c.add(mem::size_of::<*const u8>());
19+
//~^ERROR: uninitialized
20+
}
21+
}

src/tools/miri/tests/fail/uninit/padding-wide-ptr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> $DIR/padding-wide-ptr.rs:LL:CC
33
|
4-
LL | let _val = *c.add(mem::size_of::<*const u8>()); // Get a padding byte.
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4+
LL | let _val = *c.add(mem::size_of::<*const u8>());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/pass/arrays.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ fn debug() {
6262
}
6363

6464
fn huge_zst() {
65-
fn id<T>(x: T) -> T { x }
65+
fn id<T>(x: T) -> T {
66+
x
67+
}
6668

6769
// A "huge" zero-sized array. Make sure we don't loop over it in any part of Miri.
6870
let val = [(); usize::MAX];

src/tools/miri/tests/pass/async-niche-aliasing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
use std::{
55
future::Future,
6+
mem::MaybeUninit,
67
pin::Pin,
78
sync::Arc,
89
task::{Context, Poll, Wake},
9-
mem::MaybeUninit,
1010
};
1111

1212
struct ThingAdder<'a> {

0 commit comments

Comments
 (0)