about summary refs log tree commit diff
path: root/src/librustc_mir
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-05-12 11:41:15 +0200
committerGitHub <noreply@github.com>2020-05-12 11:41:15 +0200
commitceeb9bdee6de1883012be5894c360b34b644fa44 (patch)
treeaa59db539531cfd59fe1af12db6363baaff96632 /src/librustc_mir
parent31e5be027e717eaedb51992a4c938f8aa9e7fdd1 (diff)
parent6f9810c981f43cab6f4598d2d3b3e6e9b82d56ee (diff)
downloadrust-ceeb9bdee6de1883012be5894c360b34b644fa44.tar.gz
rust-ceeb9bdee6de1883012be5894c360b34b644fa44.zip
Rollup merge of #72128 - RalfJung:str-validity, r=oli-obk
strings do not have to be valid UTF-8 any more

Cc https://github.com/rust-lang/reference/pull/792
r? @oli-obk
Diffstat (limited to 'src/librustc_mir')
-rw-r--r--src/librustc_mir/interpret/validity.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs
index 4f90f83b735..7eb05ba2d2c 100644
--- a/src/librustc_mir/interpret/validity.rs
+++ b/src/librustc_mir/interpret/validity.rs
@@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{InterpError, InterpErrorInfo};
 use rustc_middle::ty;
 use rustc_middle::ty::layout::TyAndLayout;
 use rustc_span::symbol::{sym, Symbol};
-use rustc_target::abi::{Abi, LayoutOf, Scalar, VariantIdx, Variants};
+use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx, Variants};
 
 use std::hash::Hash;
 
@@ -744,10 +744,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
         match op.layout.ty.kind {
             ty::Str => {
                 let mplace = op.assert_mem_place(self.ecx); // strings are never immediate
+                let len = mplace.len(self.ecx)?;
                 try_validation!(
-                    self.ecx.read_str(mplace),
+                    self.ecx.memory.read_bytes(mplace.ptr, Size::from_bytes(len)),
                     self.path,
-                    err_ub!(InvalidStr(..)) => { "uninitialized or non-UTF-8 data in str" },
+                    err_ub!(InvalidUninitBytes(..)) => { "uninitialized data in `str`" },
                 );
             }
             ty::Array(tys, ..) | ty::Slice(tys)