Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ba23d37

Browse files
committed
Format tests with rustfmt (288-299 of 299)
1 parent 7a1b08e commit ba23d37

12 files changed

+273
-159
lines changed

tests/fail/unaligned_pointers/dyn_alignment.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
struct MuchAlign;
77

88
fn main() {
9-
for _ in 0..10 { // Try many times as this might work by chance.
9+
for _ in 0..10 {
10+
// Try many times as this might work by chance.
1011
let buf = [0u32; 256];
1112
// `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
1213
// for the actual alignment required by `MuchAlign`.
1314
// We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
1415
// as the reference is not aligned to its dynamic alignment requirements.
1516
let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
1617
// Overwrite the data part of `ptr` so it points to `buf`.
17-
unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
18+
unsafe {
19+
(&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8);
20+
}
1821
// Re-borrow that. This should be UB.
1922
let _ptr = &*ptr; //~ERROR alignment 256 is required
2023
}

tests/fail/unaligned_pointers/reference_to_packed.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ struct Foo {
1010
}
1111

1212
fn main() {
13-
for _ in 0..10 { // Try many times as this might work by chance.
14-
let foo = Foo {
15-
x: 42,
16-
y: 99,
17-
};
13+
for _ in 0..10 {
14+
// Try many times as this might work by chance.
15+
let foo = Foo { x: 42, y: 99 };
1816
let p = &foo.x;
1917
let i = *p; //~ERROR alignment 4 is required
2018
}

tests/fail/unaligned_pointers/unaligned_ptr1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
33

44
fn main() {
5-
for _ in 0..10 { // Try many times as this might work by chance.
5+
for _ in 0..10 {
6+
// Try many times as this might work by chance.
67
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
78
let x = &x[0] as *const _ as *const u32;
89
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.

tests/fail/unaligned_pointers/unaligned_ptr3.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
33

44
fn main() {
5-
for _ in 0..10 { // Try many times as this might work by chance.
5+
for _ in 0..10 {
6+
// Try many times as this might work by chance.
67
let x = [2u16, 3, 4, 5]; // Make it big enough so we don't get an out-of-bounds error.
78
let x = &x[0] as *const _ as *const *const u8; // cast to ptr-to-ptr, so that we load a ptr
89
// This must fail because alignment is violated. Test specifically for loading pointers,

tests/fail/unaligned_pointers/unaligned_ptr4.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
fn main() {
55
// Make sure we notice when a u16 is loaded at offset 1 into a u8 allocation.
66
// (This would be missed if u8 allocations are *always* at odd addresses.)
7-
for _ in 0..10 { // Try many times as this might work by chance.
7+
for _ in 0..10 {
8+
// Try many times as this might work by chance.
89
let x = [0u8; 4];
910
let ptr = x.as_ptr().wrapping_offset(1).cast::<u16>();
1011
let _val = unsafe { *ptr }; //~ERROR but alignment

tests/fail/unaligned_pointers/unaligned_ptr_addr_of.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use std::ptr;
44

55
fn main() {
6-
for _ in 0..10 { // Try many times as this might work by chance.
6+
for _ in 0..10 {
7+
// Try many times as this might work by chance.
78
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
89
let x = &x[0] as *const _ as *const u32;
910
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.

tests/fail/unaligned_pointers/unaligned_ptr_zst.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// compile-flags: -Zmir-opt-level=0 -Zmiri-disable-validation
44

55
fn main() {
6-
for i in 0..10 { // Try many times as this might work by chance.
6+
for i in 0..10 {
7+
// Try many times as this might work by chance.
78
let x = i as u8;
89
let x = &x as *const _ as *const [u32; 0];
910
// This must fail because alignment is violated. Test specifically for loading ZST.

0 commit comments

Comments
 (0)