Skip to content

Commit f84b95a

Browse files
committed
interpret: fix projecting into an unsized field of a local
new invariant: Place::Local never refers to something unsized
1 parent 115b4dd commit f84b95a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/pass/unsized.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//@[tree]compile-flags: -Zmiri-tree-borrows
33
#![feature(unsized_tuple_coercion)]
44
#![feature(unsized_fn_params)]
5+
#![feature(custom_mir, core_intrinsics)]
56

67
use std::mem;
78

@@ -32,7 +33,30 @@ fn unsized_params() {
3233
f3(*p);
3334
}
3435

36+
fn unsized_field_projection() {
37+
use std::intrinsics::mir::*;
38+
39+
pub struct S<T: ?Sized>(T);
40+
41+
#[custom_mir(dialect = "runtime", phase = "optimized")]
42+
fn f(x: S<[u8]>) {
43+
mir! {
44+
{
45+
let idx = 0;
46+
// Project to an unsized field of an unsized local.
47+
x.0[idx] = 0;
48+
let _val = x.0[idx];
49+
Return()
50+
}
51+
}
52+
}
53+
54+
let x: Box<S<[u8]>> = Box::new(S([0]));
55+
f(*x);
56+
}
57+
3558
fn main() {
3659
unsized_tuple();
3760
unsized_params();
61+
unsized_field_projection();
3862
}

0 commit comments

Comments
 (0)