Skip to content

Commit ae78862

Browse files
committed
raw slices do not have to comply to the size limit
1 parent 0c1cb32 commit ae78862

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/librustc_mir/interpret/validity.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::RangeInclusive;
33

44
use syntax_pos::symbol::{sym, Symbol};
55
use rustc::hir;
6-
use rustc::ty::layout::{self, Size, TyLayout, LayoutOf, VariantIdx};
6+
use rustc::ty::layout::{self, TyLayout, LayoutOf, VariantIdx};
77
use rustc::ty;
88
use rustc_data_structures::fx::FxHashSet;
99

@@ -276,20 +276,11 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
276276
// FIXME: More checks for the vtable.
277277
}
278278
ty::Slice(..) | ty::Str => {
279-
let len = try_validation!(meta.unwrap().to_usize(self.ecx),
279+
let _len = try_validation!(meta.unwrap().to_usize(self.ecx),
280280
"non-integer slice length in wide pointer", self.path);
281-
// check max slice length
282-
let elem_size = match tail.sty {
283-
ty::Str => Size::from_bytes(1),
284-
ty::Slice(ty) => self.ecx.layout_of(ty)?.size,
285-
_ => bug!("It cannot be another type"),
286-
};
287-
if elem_size.checked_mul(len, &*self.ecx.tcx).is_none() {
288-
throw_validation_failure!(
289-
"too large slice (longer than isize::MAX bytes)",
290-
self.path
291-
);
292-
}
281+
// We do not check that `len * elem_size <= isize::MAX`:
282+
// that is only required for references, and there it falls out of the
283+
// "dereferencable" check performed by Stacked Borrows.
293284
}
294285
ty::Foreign(..) => {
295286
// Unsized, but not wide.

0 commit comments

Comments
 (0)