From ae788620588029bef52d27d01ce66010a3c9a4b2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 26 Aug 2019 19:48:56 +0200 Subject: [PATCH] raw slices do not have to comply to the size limit --- src/librustc_mir/interpret/validity.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 7af55a2a3a376..c2505547c5b4f 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -3,7 +3,7 @@ use std::ops::RangeInclusive; use syntax_pos::symbol::{sym, Symbol}; use rustc::hir; -use rustc::ty::layout::{self, Size, TyLayout, LayoutOf, VariantIdx}; +use rustc::ty::layout::{self, TyLayout, LayoutOf, VariantIdx}; use rustc::ty; use rustc_data_structures::fx::FxHashSet; @@ -276,20 +276,11 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M // FIXME: More checks for the vtable. } ty::Slice(..) | ty::Str => { - let len = try_validation!(meta.unwrap().to_usize(self.ecx), + let _len = try_validation!(meta.unwrap().to_usize(self.ecx), "non-integer slice length in wide pointer", self.path); - // check max slice length - let elem_size = match tail.sty { - ty::Str => Size::from_bytes(1), - ty::Slice(ty) => self.ecx.layout_of(ty)?.size, - _ => bug!("It cannot be another type"), - }; - if elem_size.checked_mul(len, &*self.ecx.tcx).is_none() { - throw_validation_failure!( - "too large slice (longer than isize::MAX bytes)", - self.path - ); - } + // We do not check that `len * elem_size <= isize::MAX`: + // that is only required for references, and there it falls out of the + // "dereferencable" check performed by Stacked Borrows. } ty::Foreign(..) => { // Unsized, but not wide.