about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-08-04 21:42:35 +0200
committerRalf Jung <post@ralfj.de>2023-08-30 13:43:34 +0200
commitbdd5855b8e127f4a258b0bd90cd5d2dbade1b3cc (patch)
tree3a94ee99816cb0d12f479b257a9a88e027c2f84b /src
parent61efe9d2981b87ec7f2800d62f98c594de151713 (diff)
downloadrust-bdd5855b8e127f4a258b0bd90cd5d2dbade1b3cc.tar.gz
rust-bdd5855b8e127f4a258b0bd90cd5d2dbade1b3cc.zip
interpret: fix projecting into an unsized field of a local
new invariant: Place::Local never refers to something unsized
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/tests/pass/unsized.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/unsized.rs b/src/tools/miri/tests/pass/unsized.rs
index c9046dc3c76..5c6929882f6 100644
--- a/src/tools/miri/tests/pass/unsized.rs
+++ b/src/tools/miri/tests/pass/unsized.rs
@@ -2,6 +2,7 @@
 //@[tree]compile-flags: -Zmiri-tree-borrows
 #![feature(unsized_tuple_coercion)]
 #![feature(unsized_fn_params)]
+#![feature(custom_mir, core_intrinsics)]
 
 use std::mem;
 
@@ -32,7 +33,30 @@ fn unsized_params() {
     f3(*p);
 }
 
+fn unsized_field_projection() {
+    use std::intrinsics::mir::*;
+
+    pub struct S<T: ?Sized>(T);
+
+    #[custom_mir(dialect = "runtime", phase = "optimized")]
+    fn f(x: S<[u8]>) {
+        mir! {
+            {
+                let idx = 0;
+                // Project to an unsized field of an unsized local.
+                x.0[idx] = 0;
+                let _val = x.0[idx];
+                Return()
+            }
+        }
+    }
+
+    let x: Box<S<[u8]>> = Box::new(S([0]));
+    f(*x);
+}
+
 fn main() {
     unsized_tuple();
     unsized_params();
+    unsized_field_projection();
 }