Skip to content

Commit

Permalink
Auto merge of rust-lang#2251 - dtolnay-contrib:rustfmt4, r=RalfJung
Browse files Browse the repository at this point in the history
Format tests with rustfmt (201-224 of 300)

Extracted from rust-lang#2097. Last of the easy cases which do not involve moving around a comment.
  • Loading branch information
bors committed Jun 22, 2022
2 parents db0d4b6 + 7d40530 commit 7a1b08e
Show file tree
Hide file tree
Showing 40 changed files with 210 additions and 172 deletions.
10 changes: 6 additions & 4 deletions tests/fail/concurrency/thread_local_static_dealloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#[thread_local]
static mut TLS: u8 = 0;

fn main() { unsafe {
let dangling_ptr = std::thread::spawn(|| &TLS as *const u8 as usize).join().unwrap();
let _val = *(dangling_ptr as *const u8); //~ ERROR dereferenced after this allocation got freed
} }
fn main() {
unsafe {
let dangling_ptr = std::thread::spawn(|| &TLS as *const u8 as usize).join().unwrap();
let _val = *(dangling_ptr as *const u8); //~ ERROR dereferenced after this allocation got freed
}
}
4 changes: 2 additions & 2 deletions tests/fail/concurrency/thread_local_static_dealloc.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: pointer to ALLOC was dereferenced after this allocation got freed
--> $DIR/thread_local_static_dealloc.rs:LL:CC
|
LL | let _val = *(dangling_ptr as *const u8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pointer to ALLOC was dereferenced after this allocation got freed
LL | let _val = *(dangling_ptr as *const u8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pointer to ALLOC was dereferenced after this allocation got freed
|
= 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
32 changes: 17 additions & 15 deletions tests/fail/stacked_borrows/interior_mut2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ unsafe fn unsafe_cell_get<T>(x: &UnsafeCell<T>) -> &'static mut T {
mem::transmute(x)
}

fn main() { unsafe {
let c = &UnsafeCell::new(UnsafeCell::new(0));
let inner_uniq = &mut *c.get();
let inner_shr = &*inner_uniq;
// stack: [c: SharedReadWrite, inner_uniq: Unique, inner_shr: SharedReadWrite]
fn main() {
unsafe {
let c = &UnsafeCell::new(UnsafeCell::new(0));
let inner_uniq = &mut *c.get();
let inner_shr = &*inner_uniq;
// stack: [c: SharedReadWrite, inner_uniq: Unique, inner_shr: SharedReadWrite]

let _val = c.get().read(); // invalidates inner_uniq
// stack: [c: SharedReadWrite, inner_uniq: Disabled, inner_shr: SharedReadWrite]
let _val = c.get().read(); // invalidates inner_uniq
// stack: [c: SharedReadWrite, inner_uniq: Disabled, inner_shr: SharedReadWrite]

// We have to be careful not to add any raw pointers above inner_uniq in
// the stack, hence the use of unsafe_cell_get.
let _val = *unsafe_cell_get(inner_shr); // this still works
// We have to be careful not to add any raw pointers above inner_uniq in
// the stack, hence the use of unsafe_cell_get.
let _val = *unsafe_cell_get(inner_shr); // this still works

*c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
// stack: [c: SharedReadWrite]
*c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
// stack: [c: SharedReadWrite]

// now this does not work any more
let _val = *inner_shr.get(); //~ ERROR borrow stack
} }
// now this does not work any more
let _val = *inner_shr.get(); //~ ERROR borrow stack
}
}
18 changes: 9 additions & 9 deletions tests/fail/stacked_borrows/interior_mut2.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
error: Undefined Behavior: trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
--> $DIR/interior_mut2.rs:LL:CC
|
LL | let _val = *inner_shr.get();
| ^^^^^^^^^^^^^^^
| |
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
LL | let _val = *inner_shr.get();
| ^^^^^^^^^^^^^^^
| |
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <TAG> was created by a retag at offsets [0x0..0x4]
--> $DIR/interior_mut2.rs:LL:CC
|
LL | let inner_shr = &*inner_uniq;
| ^^^^^^^^^^^^
LL | let inner_shr = &*inner_uniq;
| ^^^^^^^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4]
--> $DIR/interior_mut2.rs:LL:CC
|
LL | *c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | *c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/interior_mut2.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
10 changes: 6 additions & 4 deletions tests/fail/stacked_borrows/issue-miri-1050-1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// error-pattern: pointer to 4 bytes starting at offset 0 is out-of-bounds

fn main() { unsafe {
let ptr = Box::into_raw(Box::new(0u16));
Box::from_raw(ptr as *mut u32);
} }
fn main() {
unsafe {
let ptr = Box::into_raw(Box::new(0u16));
Box::from_raw(ptr as *mut u32);
}
}
4 changes: 2 additions & 2 deletions tests/fail/stacked_borrows/issue-miri-1050-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
note: inside `main` at $DIR/issue-miri-1050-1.rs:LL:CC
--> $DIR/issue-miri-1050-1.rs:LL:CC
|
LL | Box::from_raw(ptr as *mut u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | Box::from_raw(ptr as *mut u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Expand Down
10 changes: 6 additions & 4 deletions tests/fail/stacked_borrows/issue-miri-1050-2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// error-pattern: is not a valid pointer
use std::ptr::NonNull;

fn main() { unsafe {
let ptr = NonNull::<i32>::dangling();
Box::from_raw(ptr.as_ptr());
} }
fn main() {
unsafe {
let ptr = NonNull::<i32>::dangling();
Box::from_raw(ptr.as_ptr());
}
}
4 changes: 2 additions & 2 deletions tests/fail/stacked_borrows/issue-miri-1050-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
note: inside `main` at $DIR/issue-miri-1050-2.rs:LL:CC
--> $DIR/issue-miri-1050-2.rs:LL:CC
|
LL | Box::from_raw(ptr.as_ptr());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | Box::from_raw(ptr.as_ptr());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Expand Down
30 changes: 17 additions & 13 deletions tests/fail/stacked_borrows/mut_exclusive_violation1.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
fn demo_mut_advanced_unique(our: &mut i32) -> i32 {
unknown_code_1(&*our);
unknown_code_1(&*our);

// This "re-asserts" uniqueness of the reference: After writing, we know
// our tag is at the top of the stack.
*our = 5;
// This "re-asserts" uniqueness of the reference: After writing, we know
// our tag is at the top of the stack.
*our = 5;

unknown_code_2();
unknown_code_2();

// We know this will return 5
*our
// We know this will return 5
*our
}

// Now comes the evil context
use std::ptr;

static mut LEAK: *mut i32 = ptr::null_mut();

fn unknown_code_1(x: &i32) { unsafe {
LEAK = x as *const _ as *mut _;
} }
fn unknown_code_1(x: &i32) {
unsafe {
LEAK = x as *const _ as *mut _;
}
}

fn unknown_code_2() { unsafe {
*LEAK = 7; //~ ERROR borrow stack
} }
fn unknown_code_2() {
unsafe {
*LEAK = 7; //~ ERROR borrow stack
}
}

fn main() {
demo_mut_advanced_unique(&mut 0);
Expand Down
22 changes: 11 additions & 11 deletions tests/fail/stacked_borrows/mut_exclusive_violation1.stderr
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
error: Undefined Behavior: attempting a write access using <untagged> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
--> $DIR/mut_exclusive_violation1.rs:LL:CC
|
LL | *LEAK = 7;
| ^^^^^^^^^
| |
| attempting a write access using <untagged> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at ALLOC[0x0..0x4]
LL | *LEAK = 7;
| ^^^^^^^^^
| |
| attempting a write access using <untagged> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at ALLOC[0x0..0x4]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: tag was most recently created at offsets [0x0..0x4]
--> $DIR/mut_exclusive_violation1.rs:LL:CC
|
LL | LEAK = x as *const _ as *mut _;
| ^
LL | LEAK = x as *const _ as *mut _;
| ^
help: tag was later invalidated at offsets [0x0..0x4]
--> $DIR/mut_exclusive_violation1.rs:LL:CC
|
LL | *our = 5;
| ^^^^^^^^
LL | *our = 5;
| ^^^^^^^^
= note: inside `unknown_code_2` at $DIR/mut_exclusive_violation1.rs:LL:CC
note: inside `demo_mut_advanced_unique` at $DIR/mut_exclusive_violation1.rs:LL:CC
--> $DIR/mut_exclusive_violation1.rs:LL:CC
|
LL | unknown_code_2();
| ^^^^^^^^^^^^^^^^
LL | unknown_code_2();
| ^^^^^^^^^^^^^^^^
note: inside `main` at $DIR/mut_exclusive_violation1.rs:LL:CC
--> $DIR/mut_exclusive_violation1.rs:LL:CC
|
Expand Down
18 changes: 10 additions & 8 deletions tests/fail/stacked_borrows/mut_exclusive_violation2.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::ptr::NonNull;

fn main() { unsafe {
let x = &mut 0;
let mut ptr1 = NonNull::from(x);
let mut ptr2 = ptr1.clone();
let raw1 = ptr1.as_mut();
let _raw2 = ptr2.as_mut();
let _val = *raw1; //~ ERROR borrow stack
} }
fn main() {
unsafe {
let x = &mut 0;
let mut ptr1 = NonNull::from(x);
let mut ptr2 = ptr1.clone();
let raw1 = ptr1.as_mut();
let _raw2 = ptr2.as_mut();
let _val = *raw1; //~ ERROR borrow stack
}
}
18 changes: 9 additions & 9 deletions tests/fail/stacked_borrows/mut_exclusive_violation2.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
error: Undefined Behavior: attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
--> $DIR/mut_exclusive_violation2.rs:LL:CC
|
LL | let _val = *raw1;
| ^^^^^
| |
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at ALLOC[0x0..0x4]
LL | let _val = *raw1;
| ^^^^^
| |
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of an access at ALLOC[0x0..0x4]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <TAG> was created by a retag at offsets [0x0..0x4]
--> $DIR/mut_exclusive_violation2.rs:LL:CC
|
LL | let raw1 = ptr1.as_mut();
| ^^^^^^^^^^^^^
LL | let raw1 = ptr1.as_mut();
| ^^^^^^^^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4]
--> $DIR/mut_exclusive_violation2.rs:LL:CC
|
LL | let _raw2 = ptr2.as_mut();
| ^^^^^^^^^^^^^
LL | let _raw2 = ptr2.as_mut();
| ^^^^^^^^^^^^^
= note: inside `main` at $DIR/mut_exclusive_violation2.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/stacked_borrows/return_invalid_mut_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn foo(x: &mut (i32, i32)) -> Option<&mut i32> {

fn main() {
match foo(&mut (1, 2)) {
Some(_x) => {}, //~ ERROR borrow stack
None => {},
Some(_x) => {} //~ ERROR borrow stack
None => {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: Undefined Behavior: trying to reborrow <TAG> for Unique permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
--> $DIR/return_invalid_mut_option.rs:LL:CC
|
LL | Some(_x) => {},
LL | Some(_x) => {}
| ^^
| |
| trying to reborrow <TAG> for Unique permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/stacked_borrows/return_invalid_shr_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn foo(x: &mut (i32, i32)) -> Option<&i32> {

fn main() {
match foo(&mut (1, 2)) {
Some(_x) => {}, //~ ERROR borrow stack
None => {},
Some(_x) => {} //~ ERROR borrow stack
None => {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: Undefined Behavior: trying to reborrow <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
--> $DIR/return_invalid_shr_option.rs:LL:CC
|
LL | Some(_x) => {},
LL | Some(_x) => {}
| ^^
| |
| trying to reborrow <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
Expand Down
18 changes: 10 additions & 8 deletions tests/fail/stacked_borrows/shared_rw_borrows_are_weak1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// *below* an already granted Unique -- so writing to
// the SharedReadWrite will invalidate the Unique.

use std::mem;
use std::cell::Cell;
use std::mem;

fn main() { unsafe {
let x = &mut Cell::new(0);
let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite
shr_rw.set(1);
y.get_mut(); //~ ERROR borrow stack
} }
fn main() {
unsafe {
let x = &mut Cell::new(0);
let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite
shr_rw.set(1);
y.get_mut(); //~ ERROR borrow stack
}
}
18 changes: 9 additions & 9 deletions tests/fail/stacked_borrows/shared_rw_borrows_are_weak1.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
error: Undefined Behavior: trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
--> $DIR/shared_rw_borrows_are_weak1.rs:LL:CC
|
LL | y.get_mut();
| ^^^^^^^^^^^
| |
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
LL | y.get_mut();
| ^^^^^^^^^^^
| |
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <TAG> was created by a retag at offsets [0x0..0x4]
--> $DIR/shared_rw_borrows_are_weak1.rs:LL:CC
|
LL | let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
| ^^^^^^^^^^^^^^^^^^^^^^^
LL | let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
| ^^^^^^^^^^^^^^^^^^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4]
--> $DIR/shared_rw_borrows_are_weak1.rs:LL:CC
|
LL | shr_rw.set(1);
| ^^^^^^^^^^^^^
LL | shr_rw.set(1);
| ^^^^^^^^^^^^^
= note: inside `main` at $DIR/shared_rw_borrows_are_weak1.rs:LL:CC

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

0 comments on commit 7a1b08e

Please sign in to comment.