Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7a1b08e

Browse files
committed
Auto merge of rust-lang#2251 - dtolnay-contrib:rustfmt4, r=RalfJung
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.
2 parents db0d4b6 + 7d40530 commit 7a1b08e

40 files changed

+210
-172
lines changed

tests/fail/concurrency/thread_local_static_dealloc.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#[thread_local]
88
static mut TLS: u8 = 0;
99

10-
fn main() { unsafe {
11-
let dangling_ptr = std::thread::spawn(|| &TLS as *const u8 as usize).join().unwrap();
12-
let _val = *(dangling_ptr as *const u8); //~ ERROR dereferenced after this allocation got freed
13-
} }
10+
fn main() {
11+
unsafe {
12+
let dangling_ptr = std::thread::spawn(|| &TLS as *const u8 as usize).join().unwrap();
13+
let _val = *(dangling_ptr as *const u8); //~ ERROR dereferenced after this allocation got freed
14+
}
15+
}

tests/fail/concurrency/thread_local_static_dealloc.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: pointer to ALLOC was dereferenced after this allocation got freed
22
--> $DIR/thread_local_static_dealloc.rs:LL:CC
33
|
4-
LL | let _val = *(dangling_ptr as *const u8);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pointer to ALLOC was dereferenced after this allocation got freed
4+
LL | let _val = *(dangling_ptr as *const u8);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pointer to ALLOC was dereferenced after this allocation got freed
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/fail/stacked_borrows/interior_mut2.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ unsafe fn unsafe_cell_get<T>(x: &UnsafeCell<T>) -> &'static mut T {
77
mem::transmute(x)
88
}
99

10-
fn main() { unsafe {
11-
let c = &UnsafeCell::new(UnsafeCell::new(0));
12-
let inner_uniq = &mut *c.get();
13-
let inner_shr = &*inner_uniq;
14-
// stack: [c: SharedReadWrite, inner_uniq: Unique, inner_shr: SharedReadWrite]
10+
fn main() {
11+
unsafe {
12+
let c = &UnsafeCell::new(UnsafeCell::new(0));
13+
let inner_uniq = &mut *c.get();
14+
let inner_shr = &*inner_uniq;
15+
// stack: [c: SharedReadWrite, inner_uniq: Unique, inner_shr: SharedReadWrite]
1516

16-
let _val = c.get().read(); // invalidates inner_uniq
17-
// stack: [c: SharedReadWrite, inner_uniq: Disabled, inner_shr: SharedReadWrite]
17+
let _val = c.get().read(); // invalidates inner_uniq
18+
// stack: [c: SharedReadWrite, inner_uniq: Disabled, inner_shr: SharedReadWrite]
1819

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

23-
*c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
24-
// stack: [c: SharedReadWrite]
24+
*c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
25+
// stack: [c: SharedReadWrite]
2526

26-
// now this does not work any more
27-
let _val = *inner_shr.get(); //~ ERROR borrow stack
28-
} }
27+
// now this does not work any more
28+
let _val = *inner_shr.get(); //~ ERROR borrow stack
29+
}
30+
}

tests/fail/stacked_borrows/interior_mut2.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
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
22
--> $DIR/interior_mut2.rs:LL:CC
33
|
4-
LL | let _val = *inner_shr.get();
5-
| ^^^^^^^^^^^^^^^
6-
| |
7-
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8-
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
4+
LL | let _val = *inner_shr.get();
5+
| ^^^^^^^^^^^^^^^
6+
| |
7+
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8+
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
99
|
1010
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/interior_mut2.rs:LL:CC
1414
|
15-
LL | let inner_shr = &*inner_uniq;
16-
| ^^^^^^^^^^^^
15+
LL | let inner_shr = &*inner_uniq;
16+
| ^^^^^^^^^^^^
1717
help: <TAG> was later invalidated at offsets [0x0..0x4]
1818
--> $DIR/interior_mut2.rs:LL:CC
1919
|
20-
LL | *c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
LL | *c.get() = UnsafeCell::new(0); // now inner_shr gets invalidated
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222
= note: inside `main` at $DIR/interior_mut2.rs:LL:CC
2323

2424
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// error-pattern: pointer to 4 bytes starting at offset 0 is out-of-bounds
22

3-
fn main() { unsafe {
4-
let ptr = Box::into_raw(Box::new(0u16));
5-
Box::from_raw(ptr as *mut u32);
6-
} }
3+
fn main() {
4+
unsafe {
5+
let ptr = Box::into_raw(Box::new(0u16));
6+
Box::from_raw(ptr as *mut u32);
7+
}
8+
}

tests/fail/stacked_borrows/issue-miri-1050-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
1212
note: inside `main` at $DIR/issue-miri-1050-1.rs:LL:CC
1313
--> $DIR/issue-miri-1050-1.rs:LL:CC
1414
|
15-
LL | Box::from_raw(ptr as *mut u32);
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
LL | Box::from_raw(ptr as *mut u32);
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// error-pattern: is not a valid pointer
22
use std::ptr::NonNull;
33

4-
fn main() { unsafe {
5-
let ptr = NonNull::<i32>::dangling();
6-
Box::from_raw(ptr.as_ptr());
7-
} }
4+
fn main() {
5+
unsafe {
6+
let ptr = NonNull::<i32>::dangling();
7+
Box::from_raw(ptr.as_ptr());
8+
}
9+
}

tests/fail/stacked_borrows/issue-miri-1050-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
1212
note: inside `main` at $DIR/issue-miri-1050-2.rs:LL:CC
1313
--> $DIR/issue-miri-1050-2.rs:LL:CC
1414
|
15-
LL | Box::from_raw(ptr.as_ptr());
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
LL | Box::from_raw(ptr.as_ptr());
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

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

tests/fail/stacked_borrows/mut_exclusive_violation1.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
fn demo_mut_advanced_unique(our: &mut i32) -> i32 {
2-
unknown_code_1(&*our);
2+
unknown_code_1(&*our);
33

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

8-
unknown_code_2();
8+
unknown_code_2();
99

10-
// We know this will return 5
11-
*our
10+
// We know this will return 5
11+
*our
1212
}
1313

1414
// Now comes the evil context
1515
use std::ptr;
1616

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

19-
fn unknown_code_1(x: &i32) { unsafe {
20-
LEAK = x as *const _ as *mut _;
21-
} }
19+
fn unknown_code_1(x: &i32) {
20+
unsafe {
21+
LEAK = x as *const _ as *mut _;
22+
}
23+
}
2224

23-
fn unknown_code_2() { unsafe {
24-
*LEAK = 7; //~ ERROR borrow stack
25-
} }
25+
fn unknown_code_2() {
26+
unsafe {
27+
*LEAK = 7; //~ ERROR borrow stack
28+
}
29+
}
2630

2731
fn main() {
2832
demo_mut_advanced_unique(&mut 0);

tests/fail/stacked_borrows/mut_exclusive_violation1.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
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
22
--> $DIR/mut_exclusive_violation1.rs:LL:CC
33
|
4-
LL | *LEAK = 7;
5-
| ^^^^^^^^^
6-
| |
7-
| attempting a write access using <untagged> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8-
| this error occurs as part of an access at ALLOC[0x0..0x4]
4+
LL | *LEAK = 7;
5+
| ^^^^^^^^^
6+
| |
7+
| attempting a write access using <untagged> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8+
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
1010
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: tag was most recently created at offsets [0x0..0x4]
1313
--> $DIR/mut_exclusive_violation1.rs:LL:CC
1414
|
15-
LL | LEAK = x as *const _ as *mut _;
16-
| ^
15+
LL | LEAK = x as *const _ as *mut _;
16+
| ^
1717
help: tag was later invalidated at offsets [0x0..0x4]
1818
--> $DIR/mut_exclusive_violation1.rs:LL:CC
1919
|
20-
LL | *our = 5;
21-
| ^^^^^^^^
20+
LL | *our = 5;
21+
| ^^^^^^^^
2222
= note: inside `unknown_code_2` at $DIR/mut_exclusive_violation1.rs:LL:CC
2323
note: inside `demo_mut_advanced_unique` at $DIR/mut_exclusive_violation1.rs:LL:CC
2424
--> $DIR/mut_exclusive_violation1.rs:LL:CC
2525
|
26-
LL | unknown_code_2();
27-
| ^^^^^^^^^^^^^^^^
26+
LL | unknown_code_2();
27+
| ^^^^^^^^^^^^^^^^
2828
note: inside `main` at $DIR/mut_exclusive_violation1.rs:LL:CC
2929
--> $DIR/mut_exclusive_violation1.rs:LL:CC
3030
|

0 commit comments

Comments
 (0)