diff --git a/src/eval_context.rs b/src/eval_context.rs index 5cd790797b4..bbee49bae84 100644 --- a/src/eval_context.rs +++ b/src/eval_context.rs @@ -342,7 +342,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { Ok(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::from_u128(s.len() as u128))) } - pub(super) fn const_to_value(&mut self, const_val: &ConstVal) -> EvalResult<'tcx, Value> { + pub(super) fn const_to_value(&mut self, const_val: &ConstVal<'tcx>) -> EvalResult<'tcx, Value> { use rustc::middle::const_val::ConstVal::*; use rustc_const_math::ConstFloat; @@ -364,7 +364,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { Struct(_) => unimplemented!(), Tuple(_) => unimplemented!(), - Function(_, _) => unimplemented!(), + // function items are zero sized and thus have no readable value + Function(..) => PrimVal::Undef, Array(_) => unimplemented!(), Repeat(_, _) => unimplemented!(), }; @@ -995,20 +996,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { match *op { Consume(ref lvalue) => self.eval_and_read_lvalue(lvalue), - Constant(mir::Constant { ref literal, ty, .. }) => { + Constant(mir::Constant { ref literal, .. }) => { use rustc::mir::Literal; let value = match *literal { Literal::Value { ref value } => self.const_to_value(value)?, Literal::Item { def_id, substs } => { - if let ty::TyFnDef(..) = ty.sty { - // function items are zero sized - Value::ByRef(self.memory.allocate(0, 0)?) - } else { - let instance = self.resolve_associated_const(def_id, substs); - let cid = GlobalId { instance, promoted: None }; - self.globals.get(&cid).expect("static/const not cached").value - } + let instance = self.resolve_associated_const(def_id, substs); + let cid = GlobalId { instance, promoted: None }; + self.globals.get(&cid).expect("static/const not cached").value } Literal::Promoted { index } => { diff --git a/src/step.rs b/src/step.rs index 8a0cbc4a8f1..79e940bee53 100644 --- a/src/step.rs +++ b/src/step.rs @@ -195,13 +195,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'tcx> { // already computed by rustc mir::Literal::Value { .. } => {} mir::Literal::Item { def_id, substs } => { - if let ty::TyFnDef(..) = constant.ty.sty { - // No need to do anything here, - // because the type is the actual function, not the signature of the function. - // Thus we can simply create a zero sized allocation in `evaluate_operand` - } else { - self.global_item(def_id, substs, constant.span, true); - } + self.global_item(def_id, substs, constant.span, true); }, mir::Literal::Promoted { index } => { let cid = GlobalId {