Skip to content

Commit 140dd98

Browse files
committed
Auto merge of #2794 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 6bd7151 + 086867b commit 140dd98

File tree

8 files changed

+131
-6
lines changed

8 files changed

+131
-6
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7e253a7fb2e2e050021fed32da6fa2ec7bcea0fb
1+
f715e430aac0de131e2ad21804013ea405722a66

src/helpers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
478478
} else if matches!(v.layout.fields, FieldsShape::Union(..)) {
479479
// A (non-frozen) union. We fall back to whatever the type says.
480480
(self.unsafe_cell_action)(v)
481+
} else if matches!(v.layout.ty.kind(), ty::Dynamic(_, _, ty::DynStar)) {
482+
// This needs to read the vtable pointer to proceed type-driven, but we don't
483+
// want to reentrantly read from memory here.
484+
(self.unsafe_cell_action)(v)
481485
} else {
482486
// We want to not actually read from memory for this visit. So, before
483487
// walking this value, we have to make sure it is not a

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![allow(
1414
clippy::collapsible_else_if,
1515
clippy::collapsible_if,
16+
clippy::if_same_then_else,
1617
clippy::comparison_chain,
1718
clippy::enum_variant_names,
1819
clippy::field_reassign_with_default,

tests/fail/branchless-select-i128-pointer.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: Undefined Behavior: constructing invalid value: encountered a dangling reference (address $HEX is unallocated)
1+
error: Undefined Behavior: constructing invalid value: encountered a dangling reference ($HEX[noalloc] has no provenance)
22
--> $DIR/branchless-select-i128-pointer.rs:LL:CC
33
|
44
LL | / transmute::<_, &str>(
55
LL | |
66
LL | | !mask & transmute::<_, TwoPtrs>("false !")
77
LL | | | mask & transmute::<_, TwoPtrs>("true !"),
88
LL | | )
9-
| |_____________^ constructing invalid value: encountered a dangling reference (address $HEX is unallocated)
9+
| |_____________^ constructing invalid value: encountered a dangling reference ($HEX[noalloc] has no provenance)
1010
|
1111
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1212
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/fail/validity/dangling_ref1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
use std::mem;
44

55
fn main() {
6-
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
6+
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference
77
}

tests/fail/validity/dangling_ref1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: constructing invalid value: encountered a dangling reference (address 0x10 is unallocated)
1+
error: Undefined Behavior: constructing invalid value: encountered a dangling reference (0x10[noalloc] has no provenance)
22
--> $DIR/dangling_ref1.rs:LL:CC
33
|
44
LL | let _x: &i32 = unsafe { mem::transmute(16usize) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x10 is unallocated)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x10[noalloc] has no provenance)
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/dyn-star.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#![feature(dyn_star)]
2+
#![allow(incomplete_features)]
3+
#![feature(custom_inner_attributes)]
4+
// rustfmt destroys `dyn* Trait` syntax
5+
#![rustfmt::skip]
6+
7+
use std::fmt::{Debug, Display};
8+
9+
fn main() {
10+
make_dyn_star();
11+
method();
12+
box_();
13+
dispatch_on_pin_mut();
14+
dyn_star_to_dyn();
15+
dyn_to_dyn_star();
16+
}
17+
18+
fn dyn_star_to_dyn() {
19+
let x: dyn* Debug = &42;
20+
let x = Box::new(x) as Box<dyn Debug>;
21+
assert_eq!("42", format!("{x:?}"));
22+
}
23+
24+
fn dyn_to_dyn_star() {
25+
let x: Box<dyn Debug> = Box::new(42);
26+
let x = &x as dyn* Debug;
27+
assert_eq!("42", format!("{x:?}"));
28+
}
29+
30+
fn make_dyn_star() {
31+
fn make_dyn_star_coercion(i: usize) {
32+
let _dyn_i: dyn* Debug = i;
33+
}
34+
35+
fn make_dyn_star_explicit(i: usize) {
36+
let _dyn_i: dyn* Debug = i as dyn* Debug;
37+
}
38+
39+
make_dyn_star_coercion(42);
40+
make_dyn_star_explicit(42);
41+
}
42+
43+
fn method() {
44+
trait Foo {
45+
fn get(&self) -> usize;
46+
}
47+
48+
impl Foo for usize {
49+
fn get(&self) -> usize {
50+
*self
51+
}
52+
}
53+
54+
fn invoke_dyn_star(i: dyn* Foo) -> usize {
55+
i.get()
56+
}
57+
58+
fn make_and_invoke_dyn_star(i: usize) -> usize {
59+
let dyn_i: dyn* Foo = i;
60+
invoke_dyn_star(dyn_i)
61+
}
62+
63+
assert_eq!(make_and_invoke_dyn_star(42), 42);
64+
}
65+
66+
fn box_() {
67+
fn make_dyn_star() -> dyn* Display {
68+
Box::new(42) as dyn* Display
69+
}
70+
71+
let x = make_dyn_star();
72+
assert_eq!(format!("{x}"), "42");
73+
}
74+
75+
fn dispatch_on_pin_mut() {
76+
use std::future::Future;
77+
78+
async fn foo(f: dyn* Future<Output = i32>) {
79+
println!("dispatch_on_pin_mut: value: {}", f.await);
80+
}
81+
82+
async fn async_main() {
83+
foo(Box::pin(async { 1 })).await
84+
}
85+
86+
// ------------------------------------------------------------------------- //
87+
// Implementation Details Below...
88+
89+
use std::pin::Pin;
90+
use std::task::*;
91+
92+
pub fn noop_waker() -> Waker {
93+
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
94+
95+
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
96+
unsafe { Waker::from_raw(raw) }
97+
}
98+
99+
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
100+
101+
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
102+
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
103+
}
104+
105+
unsafe fn noop(_p: *const ()) {}
106+
107+
let mut fut = async_main();
108+
109+
// Poll loop, just to test the future...
110+
let waker = noop_waker();
111+
let ctx = &mut Context::from_waker(&waker);
112+
113+
loop {
114+
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
115+
Poll::Pending => {}
116+
Poll::Ready(()) => break,
117+
}
118+
}
119+
}

tests/pass/dyn-star.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dispatch_on_pin_mut: value: 1

0 commit comments

Comments
 (0)