diff --git a/tests/fail/branchless-select-i128-pointer.rs b/tests/fail/branchless-select-i128-pointer.rs index 20fbcd1de7..7e1b969e02 100644 --- a/tests/fail/branchless-select-i128-pointer.rs +++ b/tests/fail/branchless-select-i128-pointer.rs @@ -11,8 +11,10 @@ fn main() { // This is branchless code to select one or the other pointer. // However, it drops provenance when transmuting to TwoPtrs, so this is UB. let val = unsafe { - transmute::<_, &str>( //~ERROR type validation failed: encountered a dangling reference - !mask & transmute::<_, TwoPtrs>("false !") | mask & transmute::<_, TwoPtrs>("true !"), + transmute::<_, &str>( + //~^ ERROR type validation failed: encountered a dangling reference + !mask & transmute::<_, TwoPtrs>("false !") + | mask & transmute::<_, TwoPtrs>("true !"), ) }; println!("{}", val); diff --git a/tests/fail/branchless-select-i128-pointer.stderr b/tests/fail/branchless-select-i128-pointer.stderr index f37dcf955e..374d6ab068 100644 --- a/tests/fail/branchless-select-i128-pointer.stderr +++ b/tests/fail/branchless-select-i128-pointer.stderr @@ -2,7 +2,9 @@ error: Undefined Behavior: type validation failed: encountered a dangling refere --> $DIR/branchless-select-i128-pointer.rs:LL:CC | LL | / transmute::<_, &str>( -LL | | !mask & transmute::<_, TwoPtrs>("false !") | mask & transmute::<_, TwoPtrs>("true !"), +LL | | +LL | | !mask & transmute::<_, TwoPtrs>("false !") +LL | | | mask & transmute::<_, TwoPtrs>("true !"), LL | | ) | |_____________^ type validation failed: encountered a dangling reference (address $HEX is unallocated) | diff --git a/tests/fail/data_race/dealloc_read_race1.rs b/tests/fail/data_race/dealloc_read_race1.rs index 14b02e95cc..555700a75d 100644 --- a/tests/fail/data_race/dealloc_read_race1.rs +++ b/tests/fail/data_race/dealloc_read_race1.rs @@ -19,11 +19,16 @@ pub fn main() { unsafe { let j1 = spawn(move || { - *ptr.0 + let _val = *ptr.0; }); let j2 = spawn(move || { - __rust_dealloc(ptr.0 as *mut _, std::mem::size_of::(), std::mem::align_of::()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) + __rust_dealloc( + //~^ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) + ptr.0 as *mut _, + std::mem::size_of::(), + std::mem::align_of::(), + ); }); j1.join().unwrap(); diff --git a/tests/fail/data_race/dealloc_read_race1.stderr b/tests/fail/data_race/dealloc_read_race1.stderr index 6b5cf5fc02..91a681e744 100644 --- a/tests/fail/data_race/dealloc_read_race1.stderr +++ b/tests/fail/data_race/dealloc_read_race1.stderr @@ -1,8 +1,13 @@ error: Undefined Behavior: Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock) --> $DIR/dealloc_read_race1.rs:LL:CC | -LL | __rust_dealloc(ptr.0 as *mut _, std::mem::size_of::(), std::mem::align_of::()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock) +LL | / __rust_dealloc( +LL | | +LL | | ptr.0 as *mut _, +LL | | std::mem::size_of::(), +LL | | std::mem::align_of::(), +LL | | ); + | |_____________^ Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock) | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/data_race/dealloc_write_race1.rs b/tests/fail/data_race/dealloc_write_race1.rs index edcdfffdb5..44078a044a 100644 --- a/tests/fail/data_race/dealloc_write_race1.rs +++ b/tests/fail/data_race/dealloc_write_race1.rs @@ -22,7 +22,12 @@ pub fn main() { }); let j2 = spawn(move || { - __rust_dealloc(ptr.0 as *mut _, std::mem::size_of::(), std::mem::align_of::()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) + __rust_dealloc( + //~^ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) + ptr.0 as *mut _, + std::mem::size_of::(), + std::mem::align_of::(), + ); }); j1.join().unwrap(); diff --git a/tests/fail/data_race/dealloc_write_race1.stderr b/tests/fail/data_race/dealloc_write_race1.stderr index ac9701d49f..dc1a6ed267 100644 --- a/tests/fail/data_race/dealloc_write_race1.stderr +++ b/tests/fail/data_race/dealloc_write_race1.stderr @@ -1,8 +1,13 @@ error: Undefined Behavior: Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock) --> $DIR/dealloc_write_race1.rs:LL:CC | -LL | __rust_dealloc(ptr.0 as *mut _, std::mem::size_of::(), std::mem::align_of::()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock) +LL | / __rust_dealloc( +LL | | +LL | | ptr.0 as *mut _, +LL | | std::mem::size_of::(), +LL | | std::mem::align_of::(), +LL | | ); + | |_____________^ Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock) | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/function_calls/check_callback_abi.rs b/tests/fail/function_calls/check_callback_abi.rs index e36bfe1c57..0a5a2d48d2 100644 --- a/tests/fail/function_calls/check_callback_abi.rs +++ b/tests/fail/function_calls/check_callback_abi.rs @@ -8,7 +8,8 @@ fn main() { unsafe { // Make sure we check the ABI when Miri itself invokes a function // as part of a shim implementation. - std::intrinsics::r#try( //~ ERROR calling a function with ABI C using caller ABI Rust + std::intrinsics::r#try( + //~^ ERROR calling a function with ABI C using caller ABI Rust std::mem::transmute::(try_fn), std::ptr::null_mut(), |_, _| unreachable!(), diff --git a/tests/fail/function_calls/check_callback_abi.stderr b/tests/fail/function_calls/check_callback_abi.stderr index ea7c2bb6b4..56314e6d28 100644 --- a/tests/fail/function_calls/check_callback_abi.stderr +++ b/tests/fail/function_calls/check_callback_abi.stderr @@ -2,6 +2,7 @@ error: Undefined Behavior: calling a function with ABI C using caller ABI Rust --> $DIR/check_callback_abi.rs:LL:CC | LL | / std::intrinsics::r#try( +LL | | LL | | std::mem::transmute::(try_fn), LL | | std::ptr::null_mut(), LL | | |_, _| unreachable!(), diff --git a/tests/fail/function_calls/exported_symbol_abi_mismatch.cache.stderr b/tests/fail/function_calls/exported_symbol_abi_mismatch.cache.stderr index bf0d27d915..dee7f66e0a 100644 --- a/tests/fail/function_calls/exported_symbol_abi_mismatch.cache.stderr +++ b/tests/fail/function_calls/exported_symbol_abi_mismatch.cache.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: calling a function with calling convention Rust using calling convention C --> $DIR/exported_symbol_abi_mismatch.rs:LL:CC | -LL | unsafe { foo() } - | ^^^^^ calling a function with calling convention Rust using calling convention C +LL | foo(); + | ^^^^^ calling a function with calling convention Rust using calling convention C | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/function_calls/exported_symbol_abi_mismatch.fn_ptr.stderr b/tests/fail/function_calls/exported_symbol_abi_mismatch.fn_ptr.stderr index ee810af315..ebe1979660 100644 --- a/tests/fail/function_calls/exported_symbol_abi_mismatch.fn_ptr.stderr +++ b/tests/fail/function_calls/exported_symbol_abi_mismatch.fn_ptr.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: calling a function with calling convention Rust using calling convention C --> $DIR/exported_symbol_abi_mismatch.rs:LL:CC | -LL | unsafe { std::mem::transmute::(foo)() } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention Rust using calling convention C +LL | std::mem::transmute::(foo)(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention Rust using calling convention C | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/function_calls/exported_symbol_abi_mismatch.no_cache.stderr b/tests/fail/function_calls/exported_symbol_abi_mismatch.no_cache.stderr index bf0d27d915..dee7f66e0a 100644 --- a/tests/fail/function_calls/exported_symbol_abi_mismatch.no_cache.stderr +++ b/tests/fail/function_calls/exported_symbol_abi_mismatch.no_cache.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: calling a function with calling convention Rust using calling convention C --> $DIR/exported_symbol_abi_mismatch.rs:LL:CC | -LL | unsafe { foo() } - | ^^^^^ calling a function with calling convention Rust using calling convention C +LL | foo(); + | ^^^^^ calling a function with calling convention Rust using calling convention C | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/function_calls/exported_symbol_abi_mismatch.rs b/tests/fail/function_calls/exported_symbol_abi_mismatch.rs index 7dbda584e8..c337e1f29f 100644 --- a/tests/fail/function_calls/exported_symbol_abi_mismatch.rs +++ b/tests/fail/function_calls/exported_symbol_abi_mismatch.rs @@ -10,20 +10,26 @@ fn main() { } #[cfg(fn_ptr)] - unsafe { std::mem::transmute::(foo)() } - //[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C + unsafe { + std::mem::transmute::(foo)(); + //[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C + } // `Instance` caching should not suppress ABI check. #[cfg(cache)] - unsafe { foo() } + unsafe { + foo(); + } { #[cfg_attr(any(cache, fn_ptr), allow(clashing_extern_declarations))] extern "C" { fn foo(); } - unsafe { foo() } - //[no_cache]~^ ERROR calling a function with calling convention Rust using calling convention C - //[cache]~^^ ERROR calling a function with calling convention Rust using calling convention C + unsafe { + foo(); + //[no_cache]~^ ERROR calling a function with calling convention Rust using calling convention C + //[cache]~| ERROR calling a function with calling convention Rust using calling convention C + } } } diff --git a/tests/fail/type-too-large.rs b/tests/fail/type-too-large.rs index 2c4ff7013a..08f7a49b02 100644 --- a/tests/fail/type-too-large.rs +++ b/tests/fail/type-too-large.rs @@ -1,6 +1,6 @@ // ignore-32bit fn main() { - let _fat: [u8; (1<<61)+(1<<31)] = - [0; (1u64<<61) as usize +(1u64<<31) as usize]; //~ ERROR post-monomorphization error + let _fat: [u8; (1 << 61) + (1 << 31)]; + _fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize]; //~ ERROR post-monomorphization error } diff --git a/tests/fail/type-too-large.stderr b/tests/fail/type-too-large.stderr index 3d555da40c..cb1d725ec8 100644 --- a/tests/fail/type-too-large.stderr +++ b/tests/fail/type-too-large.stderr @@ -1,8 +1,8 @@ error: post-monomorphization error: values of the type `[u8; 2305843011361177600]` are too big for the current architecture --> $DIR/type-too-large.rs:LL:CC | -LL | [0; (1u64<<61) as usize +(1u64<<31) as usize]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843011361177600]` are too big for the current architecture +LL | _fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843011361177600]` are too big for the current architecture | = note: inside `main` at $DIR/type-too-large.rs:LL:CC diff --git a/tests/fail/validity/invalid_char.rs b/tests/fail/validity/invalid_char.rs index 079823f894..80749fd7c7 100644 --- a/tests/fail/validity/invalid_char.rs +++ b/tests/fail/validity/invalid_char.rs @@ -1,8 +1,9 @@ fn main() { assert!(std::char::from_u32(-1_i32 as u32).is_none()); - let _val = match unsafe { std::mem::transmute::(-1) } { //~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value - 'a' => {true}, - 'b' => {false}, - _ => {true}, + let _val = match unsafe { std::mem::transmute::(-1) } { + //~^ ERROR encountered 0xffffffff, but expected a valid unicode scalar value + 'a' => true, + 'b' => false, + _ => true, }; } diff --git a/tests/pass/0weak_memory_consistency.rs b/tests/pass/0weak_memory_consistency.rs index fc9dce0c98..0f798d2b57 100644 --- a/tests/pass/0weak_memory_consistency.rs +++ b/tests/pass/0weak_memory_consistency.rs @@ -54,12 +54,13 @@ fn test_corr() { x.store(2, Relaxed); }); + #[rustfmt::skip] let j2 = spawn(move || { let r2 = x.load(Relaxed); // -------------------------------------+ y.store(1, Release); // ---------------------+ | r2 // | | }); // | | - // |synchronizes-with |happens-before + #[rustfmt::skip] // |synchronizes-with |happens-before let j3 = spawn(move || { // | | acquires_value(&y, 1); // <------------------+ | x.load(Relaxed) // <----------------------------------------------+ @@ -80,15 +81,16 @@ fn test_wrc() { let x = static_atomic(0); let y = static_atomic(0); + #[rustfmt::skip] let j1 = spawn(move || { x.store(1, Release); // ---------------------+---------------------+ }); // | | - // |synchronizes-with | + #[rustfmt::skip] // |synchronizes-with | let j2 = spawn(move || { // | | acquires_value(&x, 1); // <------------------+ | y.store(1, Release); // ---------------------+ |happens-before }); // | | - // |synchronizes-with | + #[rustfmt::skip] // |synchronizes-with | let j3 = spawn(move || { // | | acquires_value(&y, 1); // <------------------+ | x.load(Relaxed) // <-----------------------------------------------+ @@ -107,11 +109,12 @@ fn test_message_passing() { let x = EvilSend(ptr); let y = static_atomic(0); + #[rustfmt::skip] let j1 = spawn(move || { unsafe { *x.0 = 1 }; // -----------------------------------------+ y.store(1, Release); // ---------------------+ | }); // | | - // |synchronizes-with | happens-before + #[rustfmt::skip] // |synchronizes-with | happens-before let j2 = spawn(move || { // | | acquires_value(&y, 1); // <------------------+ | unsafe { *x.0 } // <---------------------------------------------+ diff --git a/tests/pass/concurrency/linux-futex.rs b/tests/pass/concurrency/linux-futex.rs index 0d30ddff48..2c60df1ee1 100644 --- a/tests/pass/concurrency/linux-futex.rs +++ b/tests/pass/concurrency/linux-futex.rs @@ -16,25 +16,23 @@ fn wake_nobody() { // Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting. unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &futex as *const i32, - libc::FUTEX_WAKE, - 1, - ), 0); + assert_eq!(libc::syscall(libc::SYS_futex, &futex as *const i32, libc::FUTEX_WAKE, 1), 0); } // Same, but without omitting the unused arguments. unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &futex as *const i32, - libc::FUTEX_WAKE, - 1, - ptr::null::(), - 0usize, + assert_eq!( + libc::syscall( + libc::SYS_futex, + &futex as *const i32, + libc::FUTEX_WAKE, + 1, + ptr::null::(), + 0usize, + 0, + ), 0, - ), 0); + ); } } @@ -45,12 +43,7 @@ fn wake_dangling() { // Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting. unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - ptr, - libc::FUTEX_WAKE, - 1, - ), 0); + assert_eq!(libc::syscall(libc::SYS_futex, ptr, libc::FUTEX_WAKE, 1), 0); } } @@ -59,13 +52,16 @@ fn wait_wrong_val() { // Only wait if the futex value is 456. unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &futex as *const i32, - libc::FUTEX_WAIT, - 456, - ptr::null::(), - ), -1); + assert_eq!( + libc::syscall( + libc::SYS_futex, + &futex as *const i32, + libc::FUTEX_WAIT, + 456, + ptr::null::(), + ), + -1, + ); assert_eq!(*libc::__errno_location(), libc::EAGAIN); } } @@ -77,16 +73,16 @@ fn wait_timeout() { // Wait for 200ms, with nobody waking us up early. unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &futex as *const i32, - libc::FUTEX_WAIT, - 123, - &libc::timespec { - tv_sec: 0, - tv_nsec: 200_000_000, - }, - ), -1); + assert_eq!( + libc::syscall( + libc::SYS_futex, + &futex as *const i32, + libc::FUTEX_WAIT, + 123, + &libc::timespec { tv_sec: 0, tv_nsec: 200_000_000 }, + ), + -1, + ); assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT); } @@ -114,15 +110,18 @@ fn wait_absolute_timeout() { // Wait for 200ms from now, with nobody waking us up early. unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &futex as *const i32, - libc::FUTEX_WAIT_BITSET, - 123, - &timeout, - 0usize, - u32::MAX, - ), -1); + assert_eq!( + libc::syscall( + libc::SYS_futex, + &futex as *const i32, + libc::FUTEX_WAIT_BITSET, + 123, + &timeout, + 0usize, + u32::MAX, + ), + -1, + ); assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT); } @@ -137,23 +136,29 @@ fn wait_wake() { let t = thread::spawn(move || { thread::sleep(Duration::from_millis(200)); unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &FUTEX as *const i32, - libc::FUTEX_WAKE, - 10, // Wake up at most 10 threads. - ), 1); // Woken up one thread. + assert_eq!( + libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAKE, + 10, // Wake up at most 10 threads. + ), + 1, // Woken up one thread. + ); } }); unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &FUTEX as *const i32, - libc::FUTEX_WAIT, + assert_eq!( + libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAIT, + 0, + ptr::null::(), + ), 0, - ptr::null::(), - ), 0); + ); } assert!((200..1000).contains(&start.elapsed().as_millis())); @@ -168,40 +173,49 @@ fn wait_wake_bitset() { let t = thread::spawn(move || { thread::sleep(Duration::from_millis(200)); unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &FUTEX as *const i32, - libc::FUTEX_WAKE_BITSET, - 10, // Wake up at most 10 threads. - ptr::null::(), - 0usize, - 0b1001, // bitset - ), 0); // Didn't match any thread. + assert_eq!( + libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAKE_BITSET, + 10, // Wake up at most 10 threads. + ptr::null::(), + 0usize, + 0b1001, // bitset + ), + 0, // Didn't match any thread. + ); } thread::sleep(Duration::from_millis(200)); unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &FUTEX as *const i32, - libc::FUTEX_WAKE_BITSET, - 10, // Wake up at most 10 threads. - ptr::null::(), - 0usize, - 0b0110, // bitset - ), 1); // Woken up one thread. + assert_eq!( + libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAKE_BITSET, + 10, // Wake up at most 10 threads. + ptr::null::(), + 0usize, + 0b0110, // bitset + ), + 1, // Woken up one thread. + ); } }); unsafe { - assert_eq!(libc::syscall( - libc::SYS_futex, - &FUTEX as *const i32, - libc::FUTEX_WAIT_BITSET, + assert_eq!( + libc::syscall( + libc::SYS_futex, + &FUTEX as *const i32, + libc::FUTEX_WAIT_BITSET, + 0, + ptr::null::(), + 0usize, + 0b0100, // bitset + ), 0, - ptr::null::(), - 0usize, - 0b0100, // bitset - ), 0); + ); } assert!((400..1000).contains(&start.elapsed().as_millis())); @@ -237,12 +251,7 @@ fn concurrent_wait_wake() { FUTEX.store(FREE, Ordering::Relaxed); unsafe { - libc::syscall( - libc::SYS_futex, - &FUTEX as *const AtomicI32, - libc::FUTEX_WAKE, - 1, - ); + libc::syscall(libc::SYS_futex, &FUTEX as *const AtomicI32, libc::FUTEX_WAKE, 1); } t.join().unwrap(); diff --git a/tests/pass/deriving-associated-types.rs b/tests/pass/deriving-associated-types.rs index 52104d8486..4803792a97 100644 --- a/tests/pass/deriving-associated-types.rs +++ b/tests/pass/deriving-associated-types.rs @@ -40,10 +40,15 @@ struct TupleStruct( ::Type, Option<::Type>, ::Type, -) where C: WhereTrait; +) +where + C: WhereTrait; #[derive(PartialEq, Debug)] -pub struct Struct where C: WhereTrait { +pub struct Struct +where + C: WhereTrait, +{ m1: module::Type, m2: Option, a1: A, @@ -62,7 +67,10 @@ pub struct Struct where C: WhereTrait { } #[derive(PartialEq, Debug)] -enum Enum where C: WhereTrait { +enum Enum +where + C: WhereTrait, +{ Unit, Seq( module::Type, @@ -101,35 +109,11 @@ enum Enum where C: WhereTrait { } fn main() { - - let e: Enum< - i32, - i32, - i32, - > = Enum::Seq( - 0, - None, - 0, - PrivateStruct(0), - 0, - 0, - None, - 0, - None, - 0, - 0, - None, - 0, - None, - 0, - ); + let e: Enum = + Enum::Seq(0, None, 0, PrivateStruct(0), 0, 0, None, 0, None, 0, 0, None, 0, None, 0); assert_eq!(e, e); - let e: Enum< - i32, - i32, - i32, - > = Enum::Map { + let e: Enum = Enum::Map { m1: 0, m2: None, a1: 0, @@ -147,52 +131,29 @@ fn main() { d: 0, }; assert_eq!(e, e); - let e: TupleStruct< - i32, - i32, - i32, - > = TupleStruct( - 0, - None, - 0, - PrivateStruct(0), - 0, - 0, - None, - 0, - None, - 0, - 0, - None, - 0, - None, - 0, - ); - assert_eq!(e, e); + let e: TupleStruct = + TupleStruct(0, None, 0, PrivateStruct(0), 0, 0, None, 0, None, 0, 0, None, 0, None, 0); + assert_eq!(e, e); - let e: Struct< - i32, - i32, - i32, - > = Struct { - m1: 0, - m2: None, - a1: 0, - a2: PrivateStruct(0), - b: 0, - b1: 0, - b2: None, - b3: 0, - b4: None, - c: 0, - c1: 0, - c2: None, - c3: 0, - c4: None, - d: 0, - }; - assert_eq!(e, e); + let e: Struct = Struct { + m1: 0, + m2: None, + a1: 0, + a2: PrivateStruct(0), + b: 0, + b1: 0, + b2: None, + b3: 0, + b4: None, + c: 0, + c1: 0, + c2: None, + c3: 0, + c4: None, + d: 0, + }; + assert_eq!(e, e); - let e = Enum::Unit::; - assert_eq!(e, e); + let e = Enum::Unit::; + assert_eq!(e, e); } diff --git a/tests/pass/heap_allocator.rs b/tests/pass/heap_allocator.rs index e428868af7..2c38dcb49f 100644 --- a/tests/pass/heap_allocator.rs +++ b/tests/pass/heap_allocator.rs @@ -1,58 +1,89 @@ #![feature(allocator_api, slice_ptr_get)] +use std::alloc::{Allocator, Global, Layout, System}; use std::ptr::NonNull; -use std::alloc::{Global, Allocator, Layout, System}; use std::slice; -fn check_alloc(allocator: T) { unsafe { - for &align in &[4, 8, 16, 32] { - let layout_20 = Layout::from_size_align(20, align).unwrap(); - let layout_40 = Layout::from_size_align(40, 4*align).unwrap(); - let layout_10 = Layout::from_size_align(10, align/2).unwrap(); +fn check_alloc(allocator: T) { + unsafe { + for &align in &[4, 8, 16, 32] { + let layout_20 = Layout::from_size_align(20, align).unwrap(); + let layout_40 = Layout::from_size_align(40, 4 * align).unwrap(); + let layout_10 = Layout::from_size_align(10, align / 2).unwrap(); - for _ in 0..32 { - let a = allocator.allocate(layout_20).unwrap().as_non_null_ptr(); - assert_eq!(a.as_ptr() as usize % layout_20.align(), 0, "pointer is incorrectly aligned"); - allocator.deallocate(a, layout_20); - } + for _ in 0..32 { + let a = allocator.allocate(layout_20).unwrap().as_non_null_ptr(); + assert_eq!( + a.as_ptr() as usize % layout_20.align(), + 0, + "pointer is incorrectly aligned", + ); + allocator.deallocate(a, layout_20); + } - let p1 = allocator.allocate_zeroed(layout_20).unwrap().as_non_null_ptr(); - assert_eq!(p1.as_ptr() as usize % layout_20.align(), 0, "pointer is incorrectly aligned"); - assert_eq!(*p1.as_ptr(), 0); + let p1 = allocator.allocate_zeroed(layout_20).unwrap().as_non_null_ptr(); + assert_eq!( + p1.as_ptr() as usize % layout_20.align(), + 0, + "pointer is incorrectly aligned", + ); + assert_eq!(*p1.as_ptr(), 0); - // old size < new size - let p2 = allocator.grow(p1, layout_20, layout_40).unwrap().as_non_null_ptr(); - assert_eq!(p2.as_ptr() as usize % layout_40.align(), 0, "pointer is incorrectly aligned"); - let slice = slice::from_raw_parts(p2.as_ptr(), 20); - assert_eq!(&slice, &[0_u8; 20]); + // old size < new size + let p2 = allocator.grow(p1, layout_20, layout_40).unwrap().as_non_null_ptr(); + assert_eq!( + p2.as_ptr() as usize % layout_40.align(), + 0, + "pointer is incorrectly aligned", + ); + let slice = slice::from_raw_parts(p2.as_ptr(), 20); + assert_eq!(&slice, &[0_u8; 20]); - // old size == new size - let p3 = allocator.grow(p2, layout_40, layout_40).unwrap().as_non_null_ptr(); - assert_eq!(p3.as_ptr() as usize % layout_40.align(), 0, "pointer is incorrectly aligned"); - let slice = slice::from_raw_parts(p3.as_ptr(), 20); - assert_eq!(&slice, &[0_u8; 20]); + // old size == new size + let p3 = allocator.grow(p2, layout_40, layout_40).unwrap().as_non_null_ptr(); + assert_eq!( + p3.as_ptr() as usize % layout_40.align(), + 0, + "pointer is incorrectly aligned", + ); + let slice = slice::from_raw_parts(p3.as_ptr(), 20); + assert_eq!(&slice, &[0_u8; 20]); - // old size > new size - let p4 = allocator.shrink(p3, layout_40, layout_10).unwrap().as_non_null_ptr(); - assert_eq!(p4.as_ptr() as usize % layout_10.align(), 0, "pointer is incorrectly aligned"); - let slice = slice::from_raw_parts(p4.as_ptr(), 10); - assert_eq!(&slice, &[0_u8; 10]); + // old size > new size + let p4 = allocator.shrink(p3, layout_40, layout_10).unwrap().as_non_null_ptr(); + assert_eq!( + p4.as_ptr() as usize % layout_10.align(), + 0, + "pointer is incorrectly aligned", + ); + let slice = slice::from_raw_parts(p4.as_ptr(), 10); + assert_eq!(&slice, &[0_u8; 10]); - allocator.deallocate(p4, layout_10); + allocator.deallocate(p4, layout_10); + } } -} } +} fn check_align_requests(allocator: T) { + #[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/3255 for &size in &[2, 8, 64] { // size less than and bigger than alignment for &align in &[4, 8, 16, 32] { // Be sure to cover less than and bigger than `MIN_ALIGN` for all architectures let iterations = 32; unsafe { - let pointers: Vec<_> = (0..iterations).map(|_| { - allocator.allocate(Layout::from_size_align(size, align).unwrap()).unwrap().as_non_null_ptr() - }).collect(); + let pointers: Vec<_> = (0..iterations) + .map(|_| { + allocator + .allocate(Layout::from_size_align(size, align).unwrap()) + .unwrap() + .as_non_null_ptr() + }) + .collect(); for &ptr in &pointers { - assert_eq!((ptr.as_ptr() as usize) % align, 0, - "Got a pointer less aligned than requested") + assert_eq!( + (ptr.as_ptr() as usize) % align, + 0, + "Got a pointer less aligned than requested", + ) } // Clean up. @@ -61,7 +92,7 @@ fn check_align_requests(allocator: T) { } } } - } + }; } fn global_to_box() { diff --git a/tests/pass/iter.rs b/tests/pass/iter.rs index 6192dd0d37..31d0d7442d 100644 --- a/tests/pass/iter.rs +++ b/tests/pass/iter.rs @@ -1,5 +1,6 @@ fn iter_empty_and_zst() { - for _ in Vec::::new().iter() { // this iterates over a Unique::empty() + // Iterate over a Unique::empty() + for _ in Vec::::new().iter() { panic!("We should never be here."); } @@ -21,13 +22,13 @@ fn test_iterator_step_by_nth() { } fn iter_any() { - let f = |x: &u8| { 10u8 == *x }; + let f = |x: &u8| 10u8 == *x; f(&1u8); - let g = |(), x: &u8| { 10u8 == *x }; + let g = |(), x: &u8| 10u8 == *x; g((), &1u8); - let h = |(), (), x: &u8| { 10u8 == *x }; + let h = |(), (), x: &u8| 10u8 == *x; h((), (), &1u8); [1, 2, 3u8].iter().any(|elt| 10 == *elt);