Skip to content

Commit c878532

Browse files
committed
Auto merge of #152632 - JonathanBrouwer:rollup-hVWecYA, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - rust-lang/rust#152622 (Update GCC subtree) - rust-lang/rust#145024 (Optimize indexing slices and strs with inclusive ranges) - rust-lang/rust#151365 (UnsafePinned: implement opsem effects of UnsafeUnpin) - rust-lang/rust#152381 (Do not require `'static` for obtaining reflection information.) - rust-lang/rust#143575 (Remove named lifetimes in some `PartialOrd` & `PartialEq` `impl`s) - rust-lang/rust#152404 (tests: adapt align-offset.rs for InstCombine improvements in LLVM 23) - rust-lang/rust#152582 (rustc_query_impl: Use `ControlFlow` in `visit_waiters` instead of nested options)
2 parents 4a42d40 + b15ad72 commit c878532

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ impl NewPermission {
7171
access: None,
7272
protector: None,
7373
}
74-
} else if pointee.is_unpin(*cx.tcx, cx.typing_env()) {
74+
} else if pointee.is_unpin(*cx.tcx, cx.typing_env())
75+
&& pointee.is_unsafe_unpin(*cx.tcx, cx.typing_env())
76+
{
7577
// A regular full mutable reference. On `FnEntry` this is `noalias` and `dereferenceable`.
7678
NewPermission::Uniform {
7779
perm: Permission::Unique,
@@ -129,7 +131,9 @@ impl NewPermission {
129131
fn from_box_ty<'tcx>(ty: Ty<'tcx>, kind: RetagKind, cx: &crate::MiriInterpCx<'tcx>) -> Self {
130132
// `ty` is not the `Box` but the field of the Box with this pointer (due to allocator handling).
131133
let pointee = ty.builtin_deref(true).unwrap();
132-
if pointee.is_unpin(*cx.tcx, cx.typing_env()) {
134+
if pointee.is_unpin(*cx.tcx, cx.typing_env())
135+
&& pointee.is_unsafe_unpin(*cx.tcx, cx.typing_env())
136+
{
133137
// A regular box. On `FnEntry` this is `noalias`, but not `dereferenceable` (hence only
134138
// a weak protector).
135139
NewPermission::Uniform {

src/borrow_tracker/tree_borrows/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ impl<'tcx> NewPermission {
133133
retag_kind: RetagKind,
134134
cx: &crate::MiriInterpCx<'tcx>,
135135
) -> Option<Self> {
136-
let ty_is_unpin = pointee.is_unpin(*cx.tcx, cx.typing_env());
136+
let ty_is_unpin = pointee.is_unpin(*cx.tcx, cx.typing_env())
137+
&& pointee.is_unsafe_unpin(*cx.tcx, cx.typing_env());
137138
let ty_is_freeze = pointee.is_freeze(*cx.tcx, cx.typing_env());
138139
let is_protected = retag_kind == RetagKind::FnEntry;
139140

tests/pass/both_borrows/unsafe_pinned.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,36 @@ fn mutate(x: &UnsafePinned<i32>) {
99
unsafe { ptr.write(42) };
1010
}
1111

12+
fn mut_alias(x: &mut UnsafePinned<i32>, y: &mut UnsafePinned<i32>) {
13+
unsafe {
14+
x.get().write(0);
15+
y.get().write(0);
16+
x.get().write(0);
17+
y.get().write(0);
18+
}
19+
}
20+
21+
// Also try this with a type for which we implement `Unpin`, just to be extra mean.
22+
struct MyUnsafePinned<T>(UnsafePinned<T>);
23+
impl<T> Unpin for MyUnsafePinned<T> {}
24+
25+
fn my_mut_alias(x: &mut MyUnsafePinned<i32>, y: &mut MyUnsafePinned<i32>) {
26+
unsafe {
27+
x.0.get().write(0);
28+
y.0.get().write(0);
29+
x.0.get().write(0);
30+
y.0.get().write(0);
31+
}
32+
}
33+
1234
fn main() {
13-
let x = UnsafePinned::new(0);
35+
let mut x = UnsafePinned::new(0i32);
1436
mutate(&x);
15-
assert_eq!(x.into_inner(), 42);
37+
assert_eq!(unsafe { x.get().read() }, 42);
38+
39+
let ptr = &raw mut x;
40+
unsafe { mut_alias(&mut *ptr, &mut *ptr) };
41+
42+
let ptr = ptr.cast::<MyUnsafePinned<i32>>();
43+
unsafe { my_mut_alias(&mut *ptr, &mut *ptr) };
1644
}

0 commit comments

Comments
 (0)