1
Fork 0

Miri engine validity check: simplify code with 'matches!'

and improve a comment a bit
This commit is contained in:
Ralf Jung 2020-10-21 09:26:11 +02:00
parent f965120ad3
commit 2202653893

View file

@ -775,17 +775,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
); );
} }
ty::Array(tys, ..) | ty::Slice(tys) ty::Array(tys, ..) | ty::Slice(tys)
if {
// This optimization applies for types that can hold arbitrary bytes (such as // This optimization applies for types that can hold arbitrary bytes (such as
// integer and floating point types) or for structs or tuples with no fields. // integer and floating point types) or for structs or tuples with no fields.
// FIXME(wesleywiser) This logic could be extended further to arbitrary structs // FIXME(wesleywiser) This logic could be extended further to arbitrary structs
// or tuples made up of integer/floating point types or inhabited ZSTs with no // or tuples made up of integer/floating point types or inhabited ZSTs with no
// padding. // padding.
match tys.kind() { if matches!(tys.kind(), ty::Int(..) | ty::Uint(..) | ty::Float(..))
ty::Int(..) | ty::Uint(..) | ty::Float(..) => true, =>
_ => false,
}
} =>
{ {
// Optimized handling for arrays of integer/float type. // Optimized handling for arrays of integer/float type.
@ -853,7 +849,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
// of an array and not all of them, because there's only a single value of a specific // of an array and not all of them, because there's only a single value of a specific
// ZST type, so either validation fails for all elements or none. // ZST type, so either validation fails for all elements or none.
ty::Array(tys, ..) | ty::Slice(tys) if self.ecx.layout_of(tys)?.is_zst() => { ty::Array(tys, ..) | ty::Slice(tys) if self.ecx.layout_of(tys)?.is_zst() => {
// Validate just the first element // Validate just the first element (if any).
self.walk_aggregate(op, fields.take(1))? self.walk_aggregate(op, fields.take(1))?
} }
_ => { _ => {