Skip to content

Commit 16320f2

Browse files
committed
Auto merge of #3210 - rust-lang:rustup-2023-12-05, r=RalfJung
Automatic Rustup
2 parents 2a761de + dfb8b0e commit 16320f2

8 files changed

+94
-22
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c9808f87028e16d134438787cab3d4cc16d05fe2
1+
317d14a56cb8c748bf0e2f2afff89c2249ab4423
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//@compile-flags: -Zmiri-strict-provenance
2-
//@error-in-other-file: /retag .* tag does not exist in the borrow stack/
32

43
fn main() {
54
unsafe {
65
let a = [1, 2, 3];
76
let s = &a[0..0];
87
assert_eq!(s.len(), 0);
9-
assert_eq!(*s.get_unchecked(1), 2);
8+
assert_eq!(*s.as_ptr().add(1), 2); //~ ERROR: /retag .* tag does not exist in the borrow stack/
109
}
1110
}

tests/fail/stacked_borrows/zst_slice.stderr

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
error: Undefined Behavior: trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
2-
--> RUSTLIB/core/src/slice/mod.rs:LL:CC
2+
--> $DIR/zst_slice.rs:LL:CC
33
|
4-
LL | unsafe { &*index.get_unchecked(self) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
8-
| this error occurs as part of retag at ALLOC[0x4..0x8]
4+
LL | assert_eq!(*s.as_ptr().add(1), 2);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
8+
| this error occurs as part of retag at ALLOC[0x4..0x8]
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> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
1313
--> $DIR/zst_slice.rs:LL:CC
1414
|
15-
LL | assert_eq!(*s.get_unchecked(1), 2);
16-
| ^^^^^^^^^^^^^^^^^^
15+
LL | assert_eq!(*s.as_ptr().add(1), 2);
16+
| ^^^^^^^^^^
1717
= note: BACKTRACE (of the first span):
18-
= note: inside `core::slice::<impl [i32]>::get_unchecked::<usize>` at RUSTLIB/core/src/slice/mod.rs:LL:CC
19-
note: inside `main`
20-
--> $DIR/zst_slice.rs:LL:CC
21-
|
22-
LL | assert_eq!(*s.get_unchecked(1), 2);
23-
| ^^^^^^^^^^^^^^^^^^
18+
= note: inside `main` at RUSTLIB/core/src/macros/mod.rs:LL:CC
19+
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2420

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

tests/fail/uninit/uninit_byte_read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@compile-flags: -Zmiri-disable-stacked-borrows
22
fn main() {
33
let v: Vec<u8> = Vec::with_capacity(10);
4-
let undef = unsafe { *v.get_unchecked(5) }; //~ ERROR: uninitialized
4+
let undef = unsafe { *v.as_ptr().add(5) }; //~ ERROR: uninitialized
55
let x = undef + 1;
66
panic!("this should never print: {}", x);
77
}

tests/fail/uninit/uninit_byte_read.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> $DIR/uninit_byte_read.rs:LL:CC
33
|
4-
LL | let undef = unsafe { *v.get_unchecked(5) };
5-
| ^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4+
LL | let undef = unsafe { *v.as_ptr().add(5) };
5+
| ^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
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/pass/float_nan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use NaNKind::*;
2020
#[track_caller]
2121
fn check_all_outcomes<T: Eq + Hash + fmt::Display>(expected: HashSet<T>, generate: impl Fn() -> T) {
2222
let mut seen = HashSet::new();
23-
// Let's give it 8x as many tries as we are expecting values.
24-
let tries = expected.len() * 8;
23+
// Let's give it sixteen times as many tries as we are expecting values.
24+
let tries = expected.len() * 16;
2525
for _ in 0..tries {
2626
let val = generate();
2727
assert!(expected.contains(&val), "got an unexpected value: {val}");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![feature(layout_for_ptr)]
2+
use std::mem;
3+
4+
#[repr(packed, C)]
5+
struct PackedSized {
6+
f: u8,
7+
d: [u32; 4],
8+
}
9+
10+
#[repr(packed, C)]
11+
struct PackedUnsized {
12+
f: u8,
13+
d: [u32],
14+
}
15+
16+
impl PackedSized {
17+
fn unsize(&self) -> &PackedUnsized {
18+
// We can't unsize via a generic type since then we get the error
19+
// that packed structs with unsized tail don't work if the tail
20+
// might need dropping.
21+
let len = 4usize;
22+
unsafe { mem::transmute((self, len)) }
23+
}
24+
}
25+
26+
fn main() {
27+
unsafe {
28+
let p = PackedSized { f: 0, d: [1, 2, 3, 4] };
29+
let p = p.unsize() as *const PackedUnsized;
30+
// Make sure the size computation does *not* think there is
31+
// any padding in front of the `d` field.
32+
assert_eq!(mem::size_of_val_raw(p), 1 + 4 * 4);
33+
// And likewise for the offset computation.
34+
let d = std::ptr::addr_of!((*p).d);
35+
assert_eq!(d.cast::<u32>().read_unaligned(), 1);
36+
}
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![feature(layout_for_ptr)]
2+
use std::mem;
3+
4+
#[repr(packed(4))]
5+
struct Slice([u32]);
6+
7+
#[repr(packed(2), C)]
8+
struct PackedSized {
9+
f: u8,
10+
d: [u32; 4],
11+
}
12+
13+
#[repr(packed(2), C)]
14+
struct PackedUnsized {
15+
f: u8,
16+
d: Slice,
17+
}
18+
19+
impl PackedSized {
20+
fn unsize(&self) -> &PackedUnsized {
21+
// We can't unsize via a generic type since then we get the error
22+
// that packed structs with unsized tail don't work if the tail
23+
// might need dropping.
24+
let len = 4usize;
25+
unsafe { mem::transmute((self, len)) }
26+
}
27+
}
28+
29+
fn main() {
30+
unsafe {
31+
let p = PackedSized { f: 0, d: [1, 2, 3, 4] };
32+
let p = p.unsize() as *const PackedUnsized;
33+
// Make sure the size computation correctly adds exact 1 byte of padding
34+
// in front of the `d` field.
35+
assert_eq!(mem::size_of_val_raw(p), 1 + 1 + 4 * 4);
36+
// And likewise for the offset computation.
37+
let d = std::ptr::addr_of!((*p).d);
38+
assert_eq!(d.cast::<u32>().read_unaligned(), 1);
39+
}
40+
}

0 commit comments

Comments
 (0)