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

Commit 7d09004

Browse files
committed
Format tests with rustfmt (276-287 of 299)
1 parent 7a1b08e commit 7d09004

12 files changed

+251
-231
lines changed

tests/fail/branchless-select-i128-pointer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ fn main() {
1111
// This is branchless code to select one or the other pointer.
1212
// However, it drops provenance when transmuting to TwoPtrs, so this is UB.
1313
let val = unsafe {
14-
transmute::<_, &str>( //~ERROR type validation failed: encountered a dangling reference
15-
!mask & transmute::<_, TwoPtrs>("false !") | mask & transmute::<_, TwoPtrs>("true !"),
14+
transmute::<_, &str>(
15+
//~ERROR type validation failed: encountered a dangling reference
16+
!mask & transmute::<_, TwoPtrs>("false !")
17+
| mask & transmute::<_, TwoPtrs>("true !"),
1618
)
1719
};
1820
println!("{}", val);

tests/fail/data_race/dealloc_read_race1.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ pub fn main() {
1818
let ptr = EvilSend(pointer);
1919

2020
unsafe {
21-
let j1 = spawn(move || {
22-
*ptr.0
23-
});
21+
let j1 = spawn(move || *ptr.0);
2422

2523
let j2 = spawn(move || {
26-
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1)
24+
__rust_dealloc(
25+
ptr.0 as *mut _,
26+
std::mem::size_of::<usize>(),
27+
std::mem::align_of::<usize>(),
28+
); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1)
2729
});
2830

2931
j1.join().unwrap();

tests/fail/data_race/dealloc_write_race1.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ pub fn main() {
2222
});
2323

2424
let j2 = spawn(move || {
25-
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1)
25+
__rust_dealloc(
26+
ptr.0 as *mut _,
27+
std::mem::size_of::<usize>(),
28+
std::mem::align_of::<usize>(),
29+
); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1)
2630
});
2731

2832
j1.join().unwrap();

tests/fail/function_calls/check_callback_abi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ fn main() {
88
unsafe {
99
// Make sure we check the ABI when Miri itself invokes a function
1010
// as part of a shim implementation.
11-
std::intrinsics::r#try( //~ ERROR calling a function with ABI C using caller ABI Rust
11+
std::intrinsics::r#try(
12+
//~ ERROR calling a function with ABI C using caller ABI Rust
1213
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
1314
std::ptr::null_mut(),
1415
|_, _| unreachable!(),

tests/fail/function_calls/exported_symbol_abi_mismatch.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ fn main() {
1010
}
1111

1212
#[cfg(fn_ptr)]
13-
unsafe { std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
13+
unsafe {
14+
std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)()
15+
}
1416
//[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C
1517

1618
// `Instance` caching should not suppress ABI check.
1719
#[cfg(cache)]
18-
unsafe { foo() }
20+
unsafe {
21+
foo()
22+
}
1923

2024
{
2125
#[cfg_attr(any(cache, fn_ptr), allow(clashing_extern_declarations))]

tests/fail/type-too-large.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// ignore-32bit
22

33
fn main() {
4-
let _fat: [u8; (1<<61)+(1<<31)] =
5-
[0; (1u64<<61) as usize +(1u64<<31) as usize]; //~ ERROR post-monomorphization error
4+
let _fat: [u8; (1 << 61) + (1 << 31)] = [0; (1u64 << 61) as usize + (1u64 << 31) as usize]; //~ ERROR post-monomorphization error
65
}

tests/fail/validity/invalid_char.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
fn main() {
22
assert!(std::char::from_u32(-1_i32 as u32).is_none());
3-
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
4-
'a' => {true},
5-
'b' => {false},
6-
_ => {true},
3+
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } {
4+
//~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
5+
'a' => true,
6+
'b' => false,
7+
_ => true,
78
};
89
}

tests/pass/0weak_memory_consistency.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ fn test_corr() {
6060
r2 // | |
6161
}); // | |
6262
// |synchronizes-with |happens-before
63-
let j3 = spawn(move || { // | |
63+
let j3 = spawn(move || {
64+
// | |
6465
acquires_value(&y, 1); // <------------------+ |
6566
x.load(Relaxed) // <----------------------------------------------+
6667
// The two reads on x are ordered by hb, so they cannot observe values
@@ -84,12 +85,14 @@ fn test_wrc() {
8485
x.store(1, Release); // ---------------------+---------------------+
8586
}); // | |
8687
// |synchronizes-with |
87-
let j2 = spawn(move || { // | |
88+
let j2 = spawn(move || {
89+
// | |
8890
acquires_value(&x, 1); // <------------------+ |
8991
y.store(1, Release); // ---------------------+ |happens-before
9092
}); // | |
9193
// |synchronizes-with |
92-
let j3 = spawn(move || { // | |
94+
let j3 = spawn(move || {
95+
// | |
9396
acquires_value(&y, 1); // <------------------+ |
9497
x.load(Relaxed) // <-----------------------------------------------+
9598
});
@@ -112,7 +115,8 @@ fn test_message_passing() {
112115
y.store(1, Release); // ---------------------+ |
113116
}); // | |
114117
// |synchronizes-with | happens-before
115-
let j2 = spawn(move || { // | |
118+
let j2 = spawn(move || {
119+
// | |
116120
acquires_value(&y, 1); // <------------------+ |
117121
unsafe { *x.0 } // <---------------------------------------------+
118122
});

tests/pass/concurrency/linux-futex.rs

Lines changed: 102 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@ fn wake_nobody() {
1616

1717
// Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting.
1818
unsafe {
19-
assert_eq!(libc::syscall(
20-
libc::SYS_futex,
21-
&futex as *const i32,
22-
libc::FUTEX_WAKE,
23-
1,
24-
), 0);
19+
assert_eq!(libc::syscall(libc::SYS_futex, &futex as *const i32, libc::FUTEX_WAKE, 1,), 0);
2520
}
2621

2722
// Same, but without omitting the unused arguments.
2823
unsafe {
29-
assert_eq!(libc::syscall(
30-
libc::SYS_futex,
31-
&futex as *const i32,
32-
libc::FUTEX_WAKE,
33-
1,
34-
ptr::null::<libc::timespec>(),
35-
0usize,
36-
0,
37-
), 0);
24+
assert_eq!(
25+
libc::syscall(
26+
libc::SYS_futex,
27+
&futex as *const i32,
28+
libc::FUTEX_WAKE,
29+
1,
30+
ptr::null::<libc::timespec>(),
31+
0usize,
32+
0,
33+
),
34+
0
35+
);
3836
}
3937
}
4038

@@ -45,12 +43,7 @@ fn wake_dangling() {
4543

4644
// Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting.
4745
unsafe {
48-
assert_eq!(libc::syscall(
49-
libc::SYS_futex,
50-
ptr,
51-
libc::FUTEX_WAKE,
52-
1,
53-
), 0);
46+
assert_eq!(libc::syscall(libc::SYS_futex, ptr, libc::FUTEX_WAKE, 1,), 0);
5447
}
5548
}
5649

@@ -59,13 +52,16 @@ fn wait_wrong_val() {
5952

6053
// Only wait if the futex value is 456.
6154
unsafe {
62-
assert_eq!(libc::syscall(
63-
libc::SYS_futex,
64-
&futex as *const i32,
65-
libc::FUTEX_WAIT,
66-
456,
67-
ptr::null::<libc::timespec>(),
68-
), -1);
55+
assert_eq!(
56+
libc::syscall(
57+
libc::SYS_futex,
58+
&futex as *const i32,
59+
libc::FUTEX_WAIT,
60+
456,
61+
ptr::null::<libc::timespec>(),
62+
),
63+
-1
64+
);
6965
assert_eq!(*libc::__errno_location(), libc::EAGAIN);
7066
}
7167
}
@@ -77,16 +73,16 @@ fn wait_timeout() {
7773

7874
// Wait for 200ms, with nobody waking us up early.
7975
unsafe {
80-
assert_eq!(libc::syscall(
81-
libc::SYS_futex,
82-
&futex as *const i32,
83-
libc::FUTEX_WAIT,
84-
123,
85-
&libc::timespec {
86-
tv_sec: 0,
87-
tv_nsec: 200_000_000,
88-
},
89-
), -1);
76+
assert_eq!(
77+
libc::syscall(
78+
libc::SYS_futex,
79+
&futex as *const i32,
80+
libc::FUTEX_WAIT,
81+
123,
82+
&libc::timespec { tv_sec: 0, tv_nsec: 200_000_000 },
83+
),
84+
-1
85+
);
9086
assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT);
9187
}
9288

@@ -114,15 +110,18 @@ fn wait_absolute_timeout() {
114110

115111
// Wait for 200ms from now, with nobody waking us up early.
116112
unsafe {
117-
assert_eq!(libc::syscall(
118-
libc::SYS_futex,
119-
&futex as *const i32,
120-
libc::FUTEX_WAIT_BITSET,
121-
123,
122-
&timeout,
123-
0usize,
124-
u32::MAX,
125-
), -1);
113+
assert_eq!(
114+
libc::syscall(
115+
libc::SYS_futex,
116+
&futex as *const i32,
117+
libc::FUTEX_WAIT_BITSET,
118+
123,
119+
&timeout,
120+
0usize,
121+
u32::MAX,
122+
),
123+
-1
124+
);
126125
assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT);
127126
}
128127

@@ -137,23 +136,29 @@ fn wait_wake() {
137136
let t = thread::spawn(move || {
138137
thread::sleep(Duration::from_millis(200));
139138
unsafe {
140-
assert_eq!(libc::syscall(
141-
libc::SYS_futex,
142-
&FUTEX as *const i32,
143-
libc::FUTEX_WAKE,
144-
10, // Wake up at most 10 threads.
145-
), 1); // Woken up one thread.
139+
assert_eq!(
140+
libc::syscall(
141+
libc::SYS_futex,
142+
&FUTEX as *const i32,
143+
libc::FUTEX_WAKE,
144+
10, // Wake up at most 10 threads.
145+
),
146+
1
147+
); // Woken up one thread.
146148
}
147149
});
148150

149151
unsafe {
150-
assert_eq!(libc::syscall(
151-
libc::SYS_futex,
152-
&FUTEX as *const i32,
153-
libc::FUTEX_WAIT,
154-
0,
155-
ptr::null::<libc::timespec>(),
156-
), 0);
152+
assert_eq!(
153+
libc::syscall(
154+
libc::SYS_futex,
155+
&FUTEX as *const i32,
156+
libc::FUTEX_WAIT,
157+
0,
158+
ptr::null::<libc::timespec>(),
159+
),
160+
0
161+
);
157162
}
158163

159164
assert!((200..1000).contains(&start.elapsed().as_millis()));
@@ -168,40 +173,49 @@ fn wait_wake_bitset() {
168173
let t = thread::spawn(move || {
169174
thread::sleep(Duration::from_millis(200));
170175
unsafe {
171-
assert_eq!(libc::syscall(
172-
libc::SYS_futex,
173-
&FUTEX as *const i32,
174-
libc::FUTEX_WAKE_BITSET,
175-
10, // Wake up at most 10 threads.
176-
ptr::null::<libc::timespec>(),
177-
0usize,
178-
0b1001, // bitset
179-
), 0); // Didn't match any thread.
176+
assert_eq!(
177+
libc::syscall(
178+
libc::SYS_futex,
179+
&FUTEX as *const i32,
180+
libc::FUTEX_WAKE_BITSET,
181+
10, // Wake up at most 10 threads.
182+
ptr::null::<libc::timespec>(),
183+
0usize,
184+
0b1001, // bitset
185+
),
186+
0
187+
); // Didn't match any thread.
180188
}
181189
thread::sleep(Duration::from_millis(200));
182190
unsafe {
183-
assert_eq!(libc::syscall(
184-
libc::SYS_futex,
185-
&FUTEX as *const i32,
186-
libc::FUTEX_WAKE_BITSET,
187-
10, // Wake up at most 10 threads.
188-
ptr::null::<libc::timespec>(),
189-
0usize,
190-
0b0110, // bitset
191-
), 1); // Woken up one thread.
191+
assert_eq!(
192+
libc::syscall(
193+
libc::SYS_futex,
194+
&FUTEX as *const i32,
195+
libc::FUTEX_WAKE_BITSET,
196+
10, // Wake up at most 10 threads.
197+
ptr::null::<libc::timespec>(),
198+
0usize,
199+
0b0110, // bitset
200+
),
201+
1
202+
); // Woken up one thread.
192203
}
193204
});
194205

195206
unsafe {
196-
assert_eq!(libc::syscall(
197-
libc::SYS_futex,
198-
&FUTEX as *const i32,
199-
libc::FUTEX_WAIT_BITSET,
200-
0,
201-
ptr::null::<libc::timespec>(),
202-
0usize,
203-
0b0100, // bitset
204-
), 0);
207+
assert_eq!(
208+
libc::syscall(
209+
libc::SYS_futex,
210+
&FUTEX as *const i32,
211+
libc::FUTEX_WAIT_BITSET,
212+
0,
213+
ptr::null::<libc::timespec>(),
214+
0usize,
215+
0b0100, // bitset
216+
),
217+
0
218+
);
205219
}
206220

207221
assert!((400..1000).contains(&start.elapsed().as_millis()));
@@ -237,12 +251,7 @@ fn concurrent_wait_wake() {
237251

238252
FUTEX.store(FREE, Ordering::Relaxed);
239253
unsafe {
240-
libc::syscall(
241-
libc::SYS_futex,
242-
&FUTEX as *const AtomicI32,
243-
libc::FUTEX_WAKE,
244-
1,
245-
);
254+
libc::syscall(libc::SYS_futex, &FUTEX as *const AtomicI32, libc::FUTEX_WAKE, 1);
246255
}
247256

248257
t.join().unwrap();

0 commit comments

Comments
 (0)