From: Ralf Jung Date: Fri, 14 Jul 2017 03:28:00 +0000 (-0700) Subject: fn ptrs and never were accidentally disabled (55) X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=66e55b0d6e00706fb9bbfd6a062852c9dbd09cec;p=rust.git fn ptrs and never were accidentally disabled (55) --- diff --git a/src/librustc_mir/interpret/lvalue.rs b/src/librustc_mir/interpret/lvalue.rs index 1c7070e77b1..60ce28f8232 100644 --- a/src/librustc_mir/interpret/lvalue.rs +++ b/src/librustc_mir/interpret/lvalue.rs @@ -529,7 +529,7 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx: let is_owning = match ty.sty { TyInt(_) | TyUint(_) | TyRawPtr(_) | TyBool | TyFloat(_) | TyChar | TyStr | - TyRef(..) => true, + TyRef(..) | TyFnPtr(..) | TyNever => true, TyAdt(adt, _) if adt.is_box() => true, TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) => false, TyParam(_) | TyInfer(_) => bug!("I got an incomplete type for validation"), @@ -611,6 +611,15 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx: let val = self.read_lvalue(lvalue)?; self.validate_ptr(val, ty.boxed_ty(), vctx) } + TyFnPtr(_sig) => { + // TODO: The function names here could need some improvement. + let ptr = self.read_lvalue(lvalue)?.into_ptr(&mut self.memory)?.to_ptr()?; + self.memory.get_fn(ptr)?; + // TODO: Check if the signature matches (should be the same check as what terminator/mod.rs already does on call?). + Ok(()) + } + + // Compound types TySlice(elem_ty) => { let len = match lvalue { Lvalue::Ptr { extra: LvalueExtra::Length(len), .. } => len, @@ -629,13 +638,6 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx: } Ok(()) } - TyFnPtr(_sig) => { - // TODO: The function names here could need some improvement. - let ptr = self.read_lvalue(lvalue)?.into_ptr(&mut self.memory)?.to_ptr()?; - self.memory.get_fn(ptr)?; - // TODO: Check if the signature matches (should be the same check as what terminator/mod.rs already does on call?). - Ok(()) - } TyAdt(adt, subst) => { match adt.adt_kind() { AdtKind::Enum => { @@ -682,6 +684,8 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx: let field_lvalue = self.lvalue_field(lvalue, idx, ty, field_ty)?; self.validate(field_lvalue, field_ty, vctx)?; } + // TODO: Check if the signature matches (should be the same check as what terminator/mod.rs already does on call?). + // Is there other things we can/should check? Like vtable pointers? Ok(()) } _ => bug!("We already establishd that this is a type we support.")