Skip to content

Commit

Permalink
Auto merge of #2254 - dtolnay-contrib:rustfmt6, r=oli-obk
Browse files Browse the repository at this point in the history
Format tests with rustfmt (276-287 of 299)

Extracted from #2097.

This is one half of the last 24 files (left for last because they require more unique attention than the first 275 "easy" files).

I'll comment below to call attention to cases where I exercised my own judgement in how to format the test.

rust-lang/rustfmt#3255 is especially annoying: rustfmt does not like `…( //` and `…{ //`.
  • Loading branch information
bors committed Jun 22, 2022
2 parents 7a1b08e + 05893d9 commit 769c6c7
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 242 deletions.
6 changes: 4 additions & 2 deletions tests/fail/branchless-select-i128-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion tests/fail/branchless-select-i128-pointer.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
|
Expand Down
9 changes: 7 additions & 2 deletions tests/fail/data_race/dealloc_read_race1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>(), std::mem::align_of::<usize>()); //~ 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::<usize>(),
std::mem::align_of::<usize>(),
);
});

j1.join().unwrap();
Expand Down
9 changes: 7 additions & 2 deletions tests/fail/data_race/dealloc_read_race1.stderr
Original file line number Diff line number Diff line change
@@ -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::<usize>(), std::mem::align_of::<usize>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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::<usize>(),
LL | | std::mem::align_of::<usize>(),
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
Expand Down
7 changes: 6 additions & 1 deletion tests/fail/data_race/dealloc_write_race1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ pub fn main() {
});

let j2 = spawn(move || {
__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)
__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::<usize>(),
std::mem::align_of::<usize>(),
);
});

j1.join().unwrap();
Expand Down
9 changes: 7 additions & 2 deletions tests/fail/data_race/dealloc_write_race1.stderr
Original file line number Diff line number Diff line change
@@ -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::<usize>(), std::mem::align_of::<usize>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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::<usize>(),
LL | | std::mem::align_of::<usize>(),
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
Expand Down
3 changes: 2 additions & 1 deletion tests/fail/function_calls/check_callback_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<extern "C" fn(*mut u8), _>(try_fn),
std::ptr::null_mut(),
|_, _| unreachable!(),
Expand Down
1 change: 1 addition & 0 deletions tests/fail/function_calls/check_callback_abi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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::<extern "C" fn(*mut u8), _>(try_fn),
LL | | std::ptr::null_mut(),
LL | | |_, _| unreachable!(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention Rust using calling convention C
LL | std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 12 additions & 6 deletions tests/fail/function_calls/exported_symbol_abi_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ fn main() {
}

#[cfg(fn_ptr)]
unsafe { std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
//[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C
unsafe {
std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(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
}
}
}
4 changes: 2 additions & 2 deletions tests/fail/type-too-large.rs
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions tests/fail/type-too-large.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 5 additions & 4 deletions tests/fail/validity/invalid_char.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
fn main() {
assert!(std::char::from_u32(-1_i32 as u32).is_none());
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
'a' => {true},
'b' => {false},
_ => {true},
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } {
//~^ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
'a' => true,
'b' => false,
_ => true,
};
}
11 changes: 7 additions & 4 deletions tests/pass/0weak_memory_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) // <----------------------------------------------+
Expand All @@ -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) // <-----------------------------------------------+
Expand All @@ -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 } // <---------------------------------------------+
Expand Down
Loading

0 comments on commit 769c6c7

Please sign in to comment.