Skip to content

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

+6-4
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

+2-2
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

+17-15
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

+9-9
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
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

+2-2
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

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

+2-2
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

+17-13
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

+11-11
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
|
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::ptr::NonNull;
22

3-
fn main() { unsafe {
4-
let x = &mut 0;
5-
let mut ptr1 = NonNull::from(x);
6-
let mut ptr2 = ptr1.clone();
7-
let raw1 = ptr1.as_mut();
8-
let _raw2 = ptr2.as_mut();
9-
let _val = *raw1; //~ ERROR borrow stack
10-
} }
3+
fn main() {
4+
unsafe {
5+
let x = &mut 0;
6+
let mut ptr1 = NonNull::from(x);
7+
let mut ptr2 = ptr1.clone();
8+
let raw1 = ptr1.as_mut();
9+
let _raw2 = ptr2.as_mut();
10+
let _val = *raw1; //~ ERROR borrow stack
11+
}
12+
}

tests/fail/stacked_borrows/mut_exclusive_violation2.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
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
22
--> $DIR/mut_exclusive_violation2.rs:LL:CC
33
|
4-
LL | let _val = *raw1;
5-
| ^^^^^
6-
| |
7-
| attempting a read access using <TAG> 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 | let _val = *raw1;
5+
| ^^^^^
6+
| |
7+
| attempting a read access using <TAG> 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 created by a retag at offsets [0x0..0x4]
1313
--> $DIR/mut_exclusive_violation2.rs:LL:CC
1414
|
15-
LL | let raw1 = ptr1.as_mut();
16-
| ^^^^^^^^^^^^^
15+
LL | let raw1 = ptr1.as_mut();
16+
| ^^^^^^^^^^^^^
1717
help: <TAG> was later invalidated at offsets [0x0..0x4]
1818
--> $DIR/mut_exclusive_violation2.rs:LL:CC
1919
|
20-
LL | let _raw2 = ptr2.as_mut();
21-
| ^^^^^^^^^^^^^
20+
LL | let _raw2 = ptr2.as_mut();
21+
| ^^^^^^^^^^^^^
2222
= note: inside `main` at $DIR/mut_exclusive_violation2.rs:LL:CC
2323

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

tests/fail/stacked_borrows/return_invalid_mut_option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn foo(x: &mut (i32, i32)) -> Option<&mut i32> {
1010

1111
fn main() {
1212
match foo(&mut (1, 2)) {
13-
Some(_x) => {}, //~ ERROR borrow stack
14-
None => {},
13+
Some(_x) => {} //~ ERROR borrow stack
14+
None => {}
1515
}
1616
}

tests/fail/stacked_borrows/return_invalid_mut_option.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
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
22
--> $DIR/return_invalid_mut_option.rs:LL:CC
33
|
4-
LL | Some(_x) => {},
4+
LL | Some(_x) => {}
55
| ^^
66
| |
77
| trying to reborrow <TAG> for Unique permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location

tests/fail/stacked_borrows/return_invalid_shr_option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn foo(x: &mut (i32, i32)) -> Option<&i32> {
99

1010
fn main() {
1111
match foo(&mut (1, 2)) {
12-
Some(_x) => {}, //~ ERROR borrow stack
13-
None => {},
12+
Some(_x) => {} //~ ERROR borrow stack
13+
None => {}
1414
}
1515
}

tests/fail/stacked_borrows/return_invalid_shr_option.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
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
22
--> $DIR/return_invalid_shr_option.rs:LL:CC
33
|
4-
LL | Some(_x) => {},
4+
LL | Some(_x) => {}
55
| ^^
66
| |
77
| trying to reborrow <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location

tests/fail/stacked_borrows/shared_rw_borrows_are_weak1.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// *below* an already granted Unique -- so writing to
33
// the SharedReadWrite will invalidate the Unique.
44

5-
use std::mem;
65
use std::cell::Cell;
6+
use std::mem;
77

8-
fn main() { unsafe {
9-
let x = &mut Cell::new(0);
10-
let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
11-
let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite
12-
shr_rw.set(1);
13-
y.get_mut(); //~ ERROR borrow stack
14-
} }
8+
fn main() {
9+
unsafe {
10+
let x = &mut Cell::new(0);
11+
let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
12+
let shr_rw = &*x; // thanks to interior mutability this will be a SharedReadWrite
13+
shr_rw.set(1);
14+
y.get_mut(); //~ ERROR borrow stack
15+
}
16+
}

tests/fail/stacked_borrows/shared_rw_borrows_are_weak1.stderr

+9-9
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/shared_rw_borrows_are_weak1.rs:LL:CC
33
|
4-
LL | y.get_mut();
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 | y.get_mut();
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/shared_rw_borrows_are_weak1.rs:LL:CC
1414
|
15-
LL | let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
16-
| ^^^^^^^^^^^^^^^^^^^^^^^
15+
LL | let y: &mut Cell<i32> = mem::transmute(&mut *x); // launder lifetime
16+
| ^^^^^^^^^^^^^^^^^^^^^^^
1717
help: <TAG> was later invalidated at offsets [0x0..0x4]
1818
--> $DIR/shared_rw_borrows_are_weak1.rs:LL:CC
1919
|
20-
LL | shr_rw.set(1);
21-
| ^^^^^^^^^^^^^
20+
LL | shr_rw.set(1);
21+
| ^^^^^^^^^^^^^
2222
= note: inside `main` at $DIR/shared_rw_borrows_are_weak1.rs:LL:CC
2323

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

0 commit comments

Comments
 (0)