Skip to content

Commit 4d712a3

Browse files
committed
Auto merge of rust-lang#2244 - dtolnay-contrib:rustfmt0, r=RalfJung
Format tests and benches with rustfmt (1-50 of 300) Extracted from rust-lang#2097. I filtered this PR to contain exclusively "easy" cases to start off with, i.e. where there is no compiletest_rs (or other) comment in the vicinity that might need to get manually repositioned.
2 parents b2616ce + 53580c1 commit 4d712a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+149
-138
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ jobs:
116116
rustup override set nightly
117117
- name: Formatting (miri, ui_test)
118118
run: cargo fmt --all --check
119-
- name: Formatting (cargo-miri)
120-
run: cargo fmt --manifest-path cargo-miri/Cargo.toml --all --check
119+
- name: Formatting (everything else)
120+
# TODO: Add `tests` (work in progress).
121+
# Maybe change to `find . -name '*.rs'`, superseding the previous step.
122+
run: find bench-cargo-miri benches cargo-miri test-cargo-miri -name '*.rs'
123+
| xargs rustfmt --edition=2021 --config-path ./rustfmt.toml --check
121124

122125
# These jobs doesn't actually test anything, but they're only used to tell
123126
# bors the build completed, as there is no practical way to detect when a

bench-cargo-miri/mse/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ fn mse(samples: usize, frame_buf: &[i16], buf_ref: &[u8]) -> f64 {
3030
}
3131
mse / max_samples as f64
3232
}
33-

benches/helpers/repeat_manual.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
fn main() {
22
let mut data: [u8; 1024] = unsafe { std::mem::uninitialized() };
33
for i in 0..data.len() {
4-
unsafe { std::ptr::write(&mut data[i], 0); }
4+
unsafe {
5+
std::ptr::write(&mut data[i], 0);
6+
}
57
}
68
assert_eq!(data.len(), 1024);
79
}

test-cargo-miri/cdylib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ use byteorder::{BigEndian, ByteOrder};
22

33
#[no_mangle]
44
extern "C" fn use_the_dependency() {
5-
let _n = <BigEndian as ByteOrder>::read_u64(&[1,2,3,4,5,6,7,8]);
5+
let _n = <BigEndian as ByteOrder>::read_u64(&[1, 2, 3, 4, 5, 6, 7, 8]);
66
}

test-cargo-miri/issue-1567/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use byteorder::{BigEndian, ByteOrder};
22

33
pub fn use_the_dependency() {
4-
let _n = <BigEndian as ByteOrder>::read_u32(&[1,2,3,4]);
4+
let _n = <BigEndian as ByteOrder>::read_u32(&[1, 2, 3, 4]);
55
}

test-cargo-miri/issue-1705/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use byteorder::{LittleEndian, ByteOrder};
1+
use byteorder::{ByteOrder, LittleEndian};
22

33
pub fn use_the_dependency() {
4-
let _n = <LittleEndian as ByteOrder>::read_u32(&[1,2,3,4]);
4+
let _n = <LittleEndian as ByteOrder>::read_u32(&[1, 2, 3, 4]);
55
}

test-cargo-miri/issue-rust-86261/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Regression test for https://github.com/rust-lang/rust/issues/86261:
44
// `#[no_mangle]` on a `use` item.
55
#[no_mangle]
6-
use std::{thread,panic, io, boxed, any, string};
6+
use std::{any, boxed, io, panic, string, thread};
77

88
// `#[no_mangle]` on a struct has a similar problem.
99
#[no_mangle]

test-cargo-miri/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
assert_eq!(env!("MIRITESTVAR"), "testval");
99

1010
// Exercise external crate, printing to stdout.
11-
let buf = &[1,2,3,4];
11+
let buf = &[1, 2, 3, 4];
1212
let n = <BigEndian as ByteOrder>::read_u32(buf);
1313
assert_eq!(n, 0x01020304);
1414
println!("{:#010x}", n);
@@ -32,7 +32,7 @@ fn main() {
3232
#[cfg(unix)]
3333
for line in io::stdin().lock().lines() {
3434
let num: i32 = line.unwrap().parse().unwrap();
35-
println!("{}", 2*num);
35+
println!("{}", 2 * num);
3636
}
3737
// On non-Unix, reading from stdin is not supported. So we hard-code the right answer.
3838
#[cfg(not(unix))]

test-cargo-miri/tests/test.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,5 @@ fn page_size() {
6767
let page_size = page_size::get();
6868

6969
// In particular, this checks that it is not 0.
70-
assert!(
71-
page_size.is_power_of_two(),
72-
"page size not a power of two: {}",
73-
page_size
74-
);
70+
assert!(page_size.is_power_of_two(), "page size not a power of two: {}", page_size);
7571
}

tests/fail/abort-terminator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// error-pattern: the program aborted
22
#![feature(c_unwind)]
33

4-
extern "C" fn panic_abort() { panic!() }
4+
extern "C" fn panic_abort() {
5+
panic!()
6+
}
57

68
fn main() {
79
panic_abort();

tests/fail/abort-terminator.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
33
error: abnormal termination: the program aborted execution
44
--> $DIR/abort-terminator.rs:LL:CC
55
|
6-
LL | extern "C" fn panic_abort() { panic!() }
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the program aborted execution
6+
LL | / extern "C" fn panic_abort() {
7+
LL | | panic!()
8+
LL | | }
9+
| |_^ the program aborted execution
810
|
911
= note: inside `panic_abort` at $DIR/abort-terminator.rs:LL:CC
1012
note: inside `main` at $DIR/abort-terminator.rs:LL:CC

tests/fail/alloc/global_system_mixup.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
#![feature(allocator_api, slice_ptr_get)]
1010

11-
use std::alloc::{Allocator, Global, System, Layout};
11+
use std::alloc::{Allocator, Global, Layout, System};
1212

1313
fn main() {
1414
let l = Layout::from_size_align(1, 1).unwrap();
1515
let ptr = Global.allocate(l).unwrap().as_non_null_ptr();
16-
unsafe { System.deallocate(ptr, l); }
16+
unsafe {
17+
System.deallocate(ptr, l);
18+
}
1719
}

tests/fail/alloc/global_system_mixup.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | FREE();
1212
note: inside `main` at $DIR/global_system_mixup.rs:LL:CC
1313
--> $DIR/global_system_mixup.rs:LL:CC
1414
|
15-
LL | unsafe { System.deallocate(ptr, l); }
15+
LL | System.deallocate(ptr, l);
1616
| ^
1717

1818
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

tests/fail/concurrency/too_few_args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ fn main() {
1919
let attr: libc::pthread_attr_t = mem::zeroed();
2020
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
2121
let thread_start: extern "C" fn() -> *mut libc::c_void = thread_start;
22-
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
22+
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void =
23+
mem::transmute(thread_start);
2324
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
2425
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
2526
}

tests/fail/concurrency/too_many_args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ fn main() {
1919
let attr: libc::pthread_attr_t = mem::zeroed();
2020
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
2121
let thread_start: extern "C" fn(*mut libc::c_void, i32) -> *mut libc::c_void = thread_start;
22-
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
22+
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void =
23+
mem::transmute(thread_start);
2324
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
2425
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
2526
}

tests/fail/concurrency/unwind_top_of_stack.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ fn main() {
2020
let attr: libc::pthread_attr_t = mem::zeroed();
2121
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
2222
// Cast to avoid inserting abort-on-unwind.
23-
let thread_start: extern "C-unwind" fn(*mut libc::c_void) -> *mut libc::c_void = thread_start;
24-
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
23+
let thread_start: extern "C-unwind" fn(*mut libc::c_void) -> *mut libc::c_void =
24+
thread_start;
25+
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void =
26+
mem::transmute(thread_start);
2527
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
2628
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
2729
}

tests/fail/dangling_pointers/storage_dead_dangling.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
static mut LEAK: usize = 0;
55

66
fn fill(v: &mut i32) {
7-
unsafe { LEAK = v as *mut _ as usize; }
7+
unsafe {
8+
LEAK = v as *mut _ as usize;
9+
}
810
}
911

1012
fn evil() {

tests/fail/data_race/alloc_read_race.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
33
#![feature(new_uninit)]
44

5-
use std::thread::spawn;
6-
use std::ptr::null_mut;
7-
use std::sync::atomic::{Ordering, AtomicPtr};
85
use std::mem::MaybeUninit;
6+
use std::ptr::null_mut;
7+
use std::sync::atomic::{AtomicPtr, Ordering};
8+
use std::thread::spawn;
99

1010
#[derive(Copy, Clone)]
1111
struct EvilSend<T>(pub T);

tests/fail/data_race/alloc_write_race.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
33
#![feature(new_uninit)]
44

5-
use std::thread::spawn;
65
use std::ptr::null_mut;
7-
use std::sync::atomic::{Ordering, AtomicPtr};
6+
use std::sync::atomic::{AtomicPtr, Ordering};
7+
use std::thread::spawn;
88

99
#[derive(Copy, Clone)]
1010
struct EvilSend<T>(pub T);
@@ -30,7 +30,8 @@ pub fn main() {
3030
// Uses relaxed semantics to not generate
3131
// a release sequence.
3232
let pointer = &*ptr.0;
33-
pointer.store(Box::into_raw(Box::<usize>::new_uninit()) as *mut usize, Ordering::Relaxed);
33+
pointer
34+
.store(Box::into_raw(Box::<usize>::new_uninit()) as *mut usize, Ordering::Relaxed);
3435
});
3536

3637
let j2 = spawn(move || {

tests/fail/data_race/atomic_read_na_write_race1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
#![feature(core_intrinsics)]
33

4-
use std::thread::spawn;
5-
use std::sync::atomic::AtomicUsize;
64
use std::intrinsics::atomic_load;
5+
use std::sync::atomic::AtomicUsize;
6+
use std::thread::spawn;
77

88
#[derive(Copy, Clone)]
99
struct EvilSend<T>(pub T);

tests/fail/data_race/atomic_read_na_write_race2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22

3-
use std::thread::spawn;
43
use std::sync::atomic::AtomicUsize;
54
use std::sync::atomic::Ordering;
5+
use std::thread::spawn;
66

77
#[derive(Copy, Clone)]
88
struct EvilSend<T>(pub T);

tests/fail/data_race/atomic_write_na_read_race1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22

3-
use std::thread::spawn;
43
use std::sync::atomic::AtomicUsize;
54
use std::sync::atomic::Ordering;
5+
use std::thread::spawn;
66

77
#[derive(Copy, Clone)]
88
struct EvilSend<T>(pub T);

tests/fail/data_race/atomic_write_na_read_race2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
#![feature(core_intrinsics)]
33

4-
use std::thread::spawn;
5-
use std::sync::atomic::AtomicUsize;
64
use std::intrinsics::atomic_store;
5+
use std::sync::atomic::AtomicUsize;
6+
use std::thread::spawn;
77

88
#[derive(Copy, Clone)]
99
struct EvilSend<T>(pub T);
@@ -17,7 +17,7 @@ pub fn main() {
1717
let c = EvilSend(b);
1818
unsafe {
1919
let j1 = spawn(move || {
20-
*(c.0 as *mut usize)
20+
let _val = *(c.0 as *mut usize);
2121
});
2222

2323
let j2 = spawn(move || {

tests/fail/data_race/atomic_write_na_write_race1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
#![feature(core_intrinsics)]
33

4-
use std::thread::spawn;
5-
use std::sync::atomic::AtomicUsize;
64
use std::intrinsics::atomic_store;
5+
use std::sync::atomic::AtomicUsize;
6+
use std::thread::spawn;
77

88
#[derive(Copy, Clone)]
99
struct EvilSend<T>(pub T);

tests/fail/data_race/atomic_write_na_write_race2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22

3-
use std::thread::spawn;
43
use std::sync::atomic::AtomicUsize;
54
use std::sync::atomic::Ordering;
5+
use std::thread::spawn;
66

77
#[derive(Copy, Clone)]
88
struct EvilSend<T>(pub T);

tests/fail/data_race/dangling_thread_async_race.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
// compile-flags: -Zmiri-disable-isolation
33

4-
use std::thread::{spawn, sleep};
5-
use std::time::Duration;
64
use std::mem;
7-
5+
use std::thread::{sleep, spawn};
6+
use std::time::Duration;
87

98
#[derive(Copy, Clone)]
109
struct EvilSend<T>(pub T);
1110

1211
unsafe impl<T> Send for EvilSend<T> {}
1312
unsafe impl<T> Sync for EvilSend<T> {}
1413

15-
1614
fn main() {
1715
let mut a = 0u32;
1816
let b = &mut a as *mut u32;

tests/fail/data_race/dangling_thread_race.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
// compile-flags: -Zmiri-disable-isolation
33

4-
use std::thread::{spawn, sleep};
5-
use std::time::Duration;
64
use std::mem;
7-
5+
use std::thread::{sleep, spawn};
6+
use std::time::Duration;
87

98
#[derive(Copy, Clone)]
109
struct EvilSend<T>(pub T);
1110

1211
unsafe impl<T> Send for EvilSend<T> {}
1312
unsafe impl<T> Sync for EvilSend<T> {}
1413

15-
1614
fn main() {
1715
let mut a = 0u32;
1816
let b = &mut a as *mut u32;
@@ -34,7 +32,6 @@ fn main() {
3432
// remains enabled nevertheless.
3533
spawn(|| ()).join().unwrap();
3634

37-
3835
unsafe {
3936
*c.0 = 64; //~ ERROR Data race detected between Write on Thread(id = 0, name = "main") and Write on Thread(id = 1)
4037
}

tests/fail/data_race/dealloc_read_race2.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ pub fn main() {
1919

2020
unsafe {
2121
let j1 = spawn(move || {
22-
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>())
22+
__rust_dealloc(
23+
ptr.0 as *mut _,
24+
std::mem::size_of::<usize>(),
25+
std::mem::align_of::<usize>(),
26+
)
2327
});
2428

2529
let j2 = spawn(move || {

tests/fail/data_race/dealloc_read_race_stack.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
// compile-flags: -Zmiri-disable-isolation -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
33

4-
use std::thread::{spawn, sleep};
54
use std::ptr::null_mut;
6-
use std::sync::atomic::{Ordering, AtomicPtr};
5+
use std::sync::atomic::{AtomicPtr, Ordering};
6+
use std::thread::{sleep, spawn};
77
use std::time::Duration;
88

99
#[derive(Copy, Clone)]
@@ -36,7 +36,6 @@ pub fn main() {
3636
sleep(Duration::from_millis(200));
3737

3838
// Now `stack_var` gets deallocated.
39-
4039
} //~ ERROR Data race detected between Deallocate on Thread(id = 1) and Read on Thread(id = 2)
4140
});
4241

tests/fail/data_race/dealloc_write_race2.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ pub fn main() {
1818

1919
unsafe {
2020
let j1 = spawn(move || {
21-
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>());
21+
__rust_dealloc(
22+
ptr.0 as *mut _,
23+
std::mem::size_of::<usize>(),
24+
std::mem::align_of::<usize>(),
25+
);
2226
});
2327

2428
let j2 = spawn(move || {

0 commit comments

Comments
 (0)