Skip to content

Format tests and benches with rustfmt (1-50 of 300) #2244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ jobs:
rustup override set nightly
- name: Formatting (miri, ui_test)
run: cargo fmt --all --check
- name: Formatting (cargo-miri)
run: cargo fmt --manifest-path cargo-miri/Cargo.toml --all --check
- name: Formatting (everything else)
# TODO: Add `tests` (work in progress).
# Maybe change to `find . -name '*.rs'`, superseding the previous step.
run: find bench-cargo-miri benches cargo-miri test-cargo-miri -name '*.rs'
| xargs rustfmt --edition=2021 --config-path ./rustfmt.toml --check

# These jobs doesn't actually test anything, but they're only used to tell
# bors the build completed, as there is no practical way to detect when a
Expand Down
1 change: 0 additions & 1 deletion bench-cargo-miri/mse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ fn mse(samples: usize, frame_buf: &[i16], buf_ref: &[u8]) -> f64 {
}
mse / max_samples as f64
}

4 changes: 3 additions & 1 deletion benches/helpers/repeat_manual.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
fn main() {
let mut data: [u8; 1024] = unsafe { std::mem::uninitialized() };
for i in 0..data.len() {
unsafe { std::ptr::write(&mut data[i], 0); }
unsafe {
std::ptr::write(&mut data[i], 0);
}
}
assert_eq!(data.len(), 1024);
}
2 changes: 1 addition & 1 deletion test-cargo-miri/cdylib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use byteorder::{BigEndian, ByteOrder};

#[no_mangle]
extern "C" fn use_the_dependency() {
let _n = <BigEndian as ByteOrder>::read_u64(&[1,2,3,4,5,6,7,8]);
let _n = <BigEndian as ByteOrder>::read_u64(&[1, 2, 3, 4, 5, 6, 7, 8]);
}
2 changes: 1 addition & 1 deletion test-cargo-miri/issue-1567/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use byteorder::{BigEndian, ByteOrder};

pub fn use_the_dependency() {
let _n = <BigEndian as ByteOrder>::read_u32(&[1,2,3,4]);
let _n = <BigEndian as ByteOrder>::read_u32(&[1, 2, 3, 4]);
}
4 changes: 2 additions & 2 deletions test-cargo-miri/issue-1705/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use byteorder::{LittleEndian, ByteOrder};
use byteorder::{ByteOrder, LittleEndian};

pub fn use_the_dependency() {
let _n = <LittleEndian as ByteOrder>::read_u32(&[1,2,3,4]);
let _n = <LittleEndian as ByteOrder>::read_u32(&[1, 2, 3, 4]);
}
2 changes: 1 addition & 1 deletion test-cargo-miri/issue-rust-86261/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Regression test for https://github.com/rust-lang/rust/issues/86261:
// `#[no_mangle]` on a `use` item.
#[no_mangle]
use std::{thread,panic, io, boxed, any, string};
use std::{any, boxed, io, panic, string, thread};

// `#[no_mangle]` on a struct has a similar problem.
#[no_mangle]
Expand Down
4 changes: 2 additions & 2 deletions test-cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
assert_eq!(env!("MIRITESTVAR"), "testval");

// Exercise external crate, printing to stdout.
let buf = &[1,2,3,4];
let buf = &[1, 2, 3, 4];
let n = <BigEndian as ByteOrder>::read_u32(buf);
assert_eq!(n, 0x01020304);
println!("{:#010x}", n);
Expand All @@ -32,7 +32,7 @@ fn main() {
#[cfg(unix)]
for line in io::stdin().lock().lines() {
let num: i32 = line.unwrap().parse().unwrap();
println!("{}", 2*num);
println!("{}", 2 * num);
}
// On non-Unix, reading from stdin is not supported. So we hard-code the right answer.
#[cfg(not(unix))]
Expand Down
6 changes: 1 addition & 5 deletions test-cargo-miri/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,5 @@ fn page_size() {
let page_size = page_size::get();

// In particular, this checks that it is not 0.
assert!(
page_size.is_power_of_two(),
"page size not a power of two: {}",
page_size
);
assert!(page_size.is_power_of_two(), "page size not a power of two: {}", page_size);
}
4 changes: 3 additions & 1 deletion tests/fail/abort-terminator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// error-pattern: the program aborted
#![feature(c_unwind)]

extern "C" fn panic_abort() { panic!() }
extern "C" fn panic_abort() {
panic!()
}

fn main() {
panic_abort();
Expand Down
6 changes: 4 additions & 2 deletions tests/fail/abort-terminator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: abnormal termination: the program aborted execution
--> $DIR/abort-terminator.rs:LL:CC
|
LL | extern "C" fn panic_abort() { panic!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the program aborted execution
LL | / extern "C" fn panic_abort() {
LL | | panic!()
LL | | }
| |_^ the program aborted execution
|
= note: inside `panic_abort` at $DIR/abort-terminator.rs:LL:CC
note: inside `main` at $DIR/abort-terminator.rs:LL:CC
Expand Down
6 changes: 4 additions & 2 deletions tests/fail/alloc/global_system_mixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#![feature(allocator_api, slice_ptr_get)]

use std::alloc::{Allocator, Global, System, Layout};
use std::alloc::{Allocator, Global, Layout, System};

fn main() {
let l = Layout::from_size_align(1, 1).unwrap();
let ptr = Global.allocate(l).unwrap().as_non_null_ptr();
unsafe { System.deallocate(ptr, l); }
unsafe {
System.deallocate(ptr, l);
}
}
2 changes: 1 addition & 1 deletion tests/fail/alloc/global_system_mixup.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LL | FREE();
note: inside `main` at $DIR/global_system_mixup.rs:LL:CC
--> $DIR/global_system_mixup.rs:LL:CC
|
LL | unsafe { System.deallocate(ptr, l); }
LL | System.deallocate(ptr, l);
| ^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
3 changes: 2 additions & 1 deletion tests/fail/concurrency/too_few_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ fn main() {
let attr: libc::pthread_attr_t = mem::zeroed();
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
let thread_start: extern "C" fn() -> *mut libc::c_void = thread_start;
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void =
mem::transmute(thread_start);
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/fail/concurrency/too_many_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ fn main() {
let attr: libc::pthread_attr_t = mem::zeroed();
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
let thread_start: extern "C" fn(*mut libc::c_void, i32) -> *mut libc::c_void = thread_start;
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void =
mem::transmute(thread_start);
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/fail/concurrency/unwind_top_of_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ fn main() {
let attr: libc::pthread_attr_t = mem::zeroed();
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
// Cast to avoid inserting abort-on-unwind.
let thread_start: extern "C-unwind" fn(*mut libc::c_void) -> *mut libc::c_void = thread_start;
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
let thread_start: extern "C-unwind" fn(*mut libc::c_void) -> *mut libc::c_void =
thread_start;
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void =
mem::transmute(thread_start);
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/fail/dangling_pointers/storage_dead_dangling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
static mut LEAK: usize = 0;

fn fill(v: &mut i32) {
unsafe { LEAK = v as *mut _ as usize; }
unsafe {
LEAK = v as *mut _ as usize;
}
}

fn evil() {
Expand Down
6 changes: 3 additions & 3 deletions tests/fail/data_race/alloc_read_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
#![feature(new_uninit)]

use std::thread::spawn;
use std::ptr::null_mut;
use std::sync::atomic::{Ordering, AtomicPtr};
use std::mem::MaybeUninit;
use std::ptr::null_mut;
use std::sync::atomic::{AtomicPtr, Ordering};
use std::thread::spawn;

#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);
Expand Down
7 changes: 4 additions & 3 deletions tests/fail/data_race/alloc_write_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
#![feature(new_uninit)]

use std::thread::spawn;
use std::ptr::null_mut;
use std::sync::atomic::{Ordering, AtomicPtr};
use std::sync::atomic::{AtomicPtr, Ordering};
use std::thread::spawn;

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

let j2 = spawn(move || {
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/data_race/atomic_read_na_write_race1.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(core_intrinsics)]

use std::thread::spawn;
use std::sync::atomic::AtomicUsize;
use std::intrinsics::atomic_load;
use std::sync::atomic::AtomicUsize;
use std::thread::spawn;

#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/data_race/atomic_read_na_write_race2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore-windows: Concurrency on Windows is not supported yet.

use std::thread::spawn;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::thread::spawn;

#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/data_race/atomic_write_na_read_race1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore-windows: Concurrency on Windows is not supported yet.

use std::thread::spawn;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::thread::spawn;

#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);
Expand Down
6 changes: 3 additions & 3 deletions tests/fail/data_race/atomic_write_na_read_race2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(core_intrinsics)]

use std::thread::spawn;
use std::sync::atomic::AtomicUsize;
use std::intrinsics::atomic_store;
use std::sync::atomic::AtomicUsize;
use std::thread::spawn;

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

let j2 = spawn(move || {
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/data_race/atomic_write_na_write_race1.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(core_intrinsics)]

use std::thread::spawn;
use std::sync::atomic::AtomicUsize;
use std::intrinsics::atomic_store;
use std::sync::atomic::AtomicUsize;
use std::thread::spawn;

#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/data_race/atomic_write_na_write_race2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore-windows: Concurrency on Windows is not supported yet.

use std::thread::spawn;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::thread::spawn;

#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);
Expand Down
6 changes: 2 additions & 4 deletions tests/fail/data_race/dangling_thread_async_race.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// compile-flags: -Zmiri-disable-isolation

use std::thread::{spawn, sleep};
use std::time::Duration;
use std::mem;

use std::thread::{sleep, spawn};
use std::time::Duration;

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

unsafe impl<T> Send for EvilSend<T> {}
unsafe impl<T> Sync for EvilSend<T> {}


fn main() {
let mut a = 0u32;
let b = &mut a as *mut u32;
Expand Down
7 changes: 2 additions & 5 deletions tests/fail/data_race/dangling_thread_race.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// compile-flags: -Zmiri-disable-isolation

use std::thread::{spawn, sleep};
use std::time::Duration;
use std::mem;

use std::thread::{sleep, spawn};
use std::time::Duration;

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

unsafe impl<T> Send for EvilSend<T> {}
unsafe impl<T> Sync for EvilSend<T> {}


fn main() {
let mut a = 0u32;
let b = &mut a as *mut u32;
Expand All @@ -34,7 +32,6 @@ fn main() {
// remains enabled nevertheless.
spawn(|| ()).join().unwrap();


unsafe {
*c.0 = 64; //~ ERROR Data race detected between Write on Thread(id = 0, name = "main") and Write on Thread(id = 1)
}
Expand Down
6 changes: 5 additions & 1 deletion tests/fail/data_race/dealloc_read_race2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub fn main() {

unsafe {
let j1 = spawn(move || {
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>())
__rust_dealloc(
ptr.0 as *mut _,
std::mem::size_of::<usize>(),
std::mem::align_of::<usize>(),
)
});

let j2 = spawn(move || {
Expand Down
5 changes: 2 additions & 3 deletions tests/fail/data_race/dealloc_read_race_stack.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// compile-flags: -Zmiri-disable-isolation -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0

use std::thread::{spawn, sleep};
use std::ptr::null_mut;
use std::sync::atomic::{Ordering, AtomicPtr};
use std::sync::atomic::{AtomicPtr, Ordering};
use std::thread::{sleep, spawn};
use std::time::Duration;

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

// Now `stack_var` gets deallocated.

} //~ ERROR Data race detected between Deallocate on Thread(id = 1) and Read on Thread(id = 2)
});

Expand Down
6 changes: 5 additions & 1 deletion tests/fail/data_race/dealloc_write_race2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ pub fn main() {

unsafe {
let j1 = spawn(move || {
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>());
__rust_dealloc(
ptr.0 as *mut _,
std::mem::size_of::<usize>(),
std::mem::align_of::<usize>(),
);
});

let j2 = spawn(move || {
Expand Down
Loading