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

This commit is contained in:
David Tolnay 2022-06-19 20:33:59 -07:00
parent fe04faf0ce
commit 66e8751afc
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
50 changed files with 129 additions and 127 deletions

View File

@ -30,4 +30,3 @@ fn mse(samples: usize, frame_buf: &[i16], buf_ref: &[u8]) -> f64 {
}
mse / max_samples as f64
}

View File

@ -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);
}

View File

@ -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]);
}

View File

@ -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]);
}

View File

@ -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]);
}

View File

@ -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]

View File

@ -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);
@ -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))]

View File

@ -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);
}

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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() {

View File

@ -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);

View File

@ -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);
@ -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 || {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
@ -16,9 +16,7 @@ pub fn main() {
let b = &mut a as *mut AtomicUsize;
let c = EvilSend(b);
unsafe {
let j1 = spawn(move || {
*(c.0 as *mut usize)
});
let j1 = spawn(move || *(c.0 as *mut usize));
let j2 = spawn(move || {
//Equivalent to: (&*c.0).store(32, Ordering::SeqCst)

View File

@ -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);

View File

@ -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);

View File

@ -1,10 +1,9 @@
// 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);
@ -12,7 +11,6 @@ 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;

View File

@ -1,10 +1,9 @@
// 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);
@ -12,7 +11,6 @@ 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;
@ -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)
}

View File

@ -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 || {

View File

@ -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)]
@ -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)
});

View File

@ -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 || {

View File

@ -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)]
@ -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 Write on Thread(id = 2)
});

View File

@ -1,10 +1,10 @@
// We want to control preemption here.
// compile-flags: -Zmiri-disable-isolation -Zmiri-preemption-rate=0
// ignore-windows: Concurrency on Windows is not supported yet.
use std::sync::atomic::{fence, AtomicUsize, Ordering};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering, fence};
use std::time::Duration;
use std::thread;
use std::time::Duration;
fn main() {
static mut V: u32 = 0;

View File

@ -13,9 +13,7 @@ pub fn main() {
let b = &mut a as *mut u32;
let c = EvilSend(b);
unsafe {
let j1 = spawn(move || {
*c.0
});
let j1 = spawn(move || *c.0);
let j2 = spawn(move || {
*c.0 = 64; //~ ERROR Data race detected between Write on Thread(id = 2) and Read on Thread(id = 1)

View File

@ -4,9 +4,9 @@
// Note: mir-opt-level set to 0 to prevent the read of stack_var in thread 1
// from being optimized away and preventing the detection of the data-race.
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)]

View File

@ -1,8 +1,8 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
use std::thread::spawn;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread::spawn;
#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);

View File

@ -1,8 +1,8 @@
// 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::sync::atomic::{AtomicUsize, Ordering};
use std::thread::{sleep, spawn};
use std::time::Duration;
#[derive(Copy, Clone)]

View File

@ -1,8 +1,8 @@
// 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;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread::spawn;
#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);

View File

@ -1,8 +1,8 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
use std::thread::spawn;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread::spawn;
#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);

View File

@ -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)]

View File

@ -1,14 +1,14 @@
// ignore-windows: Windows does not have a global environ list that the program can access directly
#[cfg(target_os="linux")]
#[cfg(target_os = "linux")]
fn get_environ() -> *const *const u8 {
extern "C" {
static mut environ: *const *const u8;
}
unsafe { environ }
extern "C" {
static mut environ: *const *const u8;
}
unsafe { environ }
}
#[cfg(target_os="macos")]
#[cfg(target_os = "macos")]
fn get_environ() -> *const *const u8 {
extern "C" {
fn _NSGetEnviron() -> *mut *const *const u8;

View File

@ -3,9 +3,7 @@
fn main() {
let b = Box::new(42);
let g = unsafe {
std::mem::transmute::<&Box<usize>, &fn(i32)>(&b)
};
let g = unsafe { std::mem::transmute::<&Box<usize>, &fn(i32)>(&b) };
(*g)(42) //~ ERROR it does not point to a function
}

View File

@ -1,9 +1,7 @@
fn main() {
fn f() {}
let g = unsafe {
std::mem::transmute::<fn(), fn(i32)>(f)
};
let g = unsafe { std::mem::transmute::<fn(), fn(i32)>(f) };
g(42) //~ ERROR calling a function with more arguments than it expected
}

View File

@ -1,9 +1,7 @@
fn main() {
fn f(_ : (i32,i32)) {}
fn f(_: (i32, i32)) {}
let g = unsafe {
std::mem::transmute::<fn((i32,i32)), fn(i32)>(f)
};
let g = unsafe { std::mem::transmute::<fn((i32, i32)), fn(i32)>(f) };
g(42) //~ ERROR calling a function with argument of type (i32, i32) passing data of type i32
}

View File

@ -1,10 +1,7 @@
fn main() {
fn f(_ : (i32,i32)) {}
fn f(_: (i32, i32)) {}
let g = unsafe {
std::mem::transmute::<fn((i32,i32)), fn()>(f)
};
let g = unsafe { std::mem::transmute::<fn((i32, i32)), fn()>(f) };
g() //~ ERROR calling a function with fewer arguments than it requires
}

View File

@ -1,9 +1,7 @@
fn main() {
fn f(_ : *const [i32]) {}
fn f(_: *const [i32]) {}
let g = unsafe {
std::mem::transmute::<fn(*const [i32]), fn(*const i32)>(f)
};
let g = unsafe { std::mem::transmute::<fn(*const [i32]), fn(*const i32)>(f) };
g(&42 as *const i32) //~ ERROR calling a function with argument of type *const [i32] passing data of type *const i32
}

View File

@ -1,9 +1,9 @@
fn main() {
fn f() -> u32 { 42 }
fn f() -> u32 {
42
}
let g = unsafe {
std::mem::transmute::<fn() -> u32, fn()>(f)
};
let g = unsafe { std::mem::transmute::<fn() -> u32, fn()>(f) };
g() //~ ERROR calling a function with return type u32 passing return place of type ()
}

View File

@ -2,9 +2,7 @@
// compile-flags: -Zmiri-disable-validation
fn main() {
let g = unsafe {
std::mem::transmute::<usize, fn(i32)>(42)
};
let g = unsafe { std::mem::transmute::<usize, fn(i32)>(42) };
g(42) //~ ERROR not a valid pointer
}

View File

@ -6,9 +6,9 @@ use std::mem;
fn f() {}
fn main() {
let x : fn() = f;
let y : *mut u8 = unsafe { mem::transmute(x) };
let x: fn() = f;
let y: *mut u8 = unsafe { mem::transmute(x) };
let y = y.wrapping_offset(1);
let x : fn() = unsafe { mem::transmute(y) };
let x: fn() = unsafe { mem::transmute(y) };
x(); //~ ERROR function pointer but it does not point to a function
}

View File

@ -8,8 +8,10 @@ extern "platform-intrinsic" {
#[allow(non_camel_case_types)]
struct i32x2(i32, i32);
fn main() { unsafe {
let x = i32x2(1, 1);
let y = i32x2(1, 0);
simd_div(x, y); //~ERROR Undefined Behavior: dividing by zero
} }
fn main() {
unsafe {
let x = i32x2(1, 1);
let y = i32x2(1, 0);
simd_div(x, y); //~ERROR Undefined Behavior: dividing by zero
}
}

View File

@ -8,8 +8,10 @@ extern "platform-intrinsic" {
#[allow(non_camel_case_types)]
struct i32x2(i32, i32);
fn main() { unsafe {
let x = i32x2(1, i32::MIN);
let y = i32x2(1, -1);
simd_div(x, y); //~ERROR Undefined Behavior: overflow in signed division
} }
fn main() {
unsafe {
let x = i32x2(1, i32::MIN);
let y = i32x2(1, -1);
simd_div(x, y); //~ERROR Undefined Behavior: overflow in signed division
}
}

View File

@ -2,6 +2,8 @@
#![feature(portable_simd)]
use std::simd::*;
fn main() { unsafe {
let _x : i32x2 = f32x2::from_array([f32::MAX, f32::MIN]).to_int_unchecked();
} }
fn main() {
unsafe {
let _x: i32x2 = f32x2::from_array([f32::MAX, f32::MIN]).to_int_unchecked();
}
}

View File

@ -2,8 +2,10 @@
#![feature(portable_simd)]
use std::simd::*;
fn main() { unsafe {
let vec: &[i8] = &[10, 11, 12, 13, 14, 15, 16, 17, 18];
let idxs = Simd::from_array([9, 3, 0, 17]);
let _result = Simd::gather_select_unchecked(&vec, Mask::splat(true), idxs, Simd::splat(0));
} }
fn main() {
unsafe {
let vec: &[i8] = &[10, 11, 12, 13, 14, 15, 16, 17, 18];
let idxs = Simd::from_array([9, 3, 0, 17]);
let _result = Simd::gather_select_unchecked(&vec, Mask::splat(true), idxs, Simd::splat(0));
}
}

View File

@ -8,7 +8,9 @@ extern "platform-intrinsic" {
#[allow(non_camel_case_types)]
struct i32x2(i32, i32);
fn main() { unsafe {
let x = i32x2(0, 1);
simd_reduce_any(x); //~ERROR must be all-0-bits or all-1-bits
} }
fn main() {
unsafe {
let x = i32x2(0, 1);
simd_reduce_any(x); //~ERROR must be all-0-bits or all-1-bits
}
}