Skip to content

Commit

Permalink
we already have the constant's type, no need to recompute from the de…
Browse files Browse the repository at this point in the history
…f_id
  • Loading branch information
oli-obk committed Jun 9, 2016
1 parent 59d858a commit 225a6a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,13 +1184,12 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
use rustc::mir::repr::Operand::*;
match *op {
Consume(ref lvalue) => Ok(self.eval_lvalue(lvalue)?.to_ptr()),
Constant(mir::Constant { ref literal, .. }) => {
Constant(mir::Constant { ref literal, ty, .. }) => {
use rustc::mir::repr::Literal::*;
match *literal {
Value { ref value } => Ok(self.const_to_ptr(value)?),
Item { def_id, substs } => {
let item_ty = self.tcx.lookup_item_type(def_id).subst(self.tcx, substs);
if item_ty.ty.is_fn() {
if ty.is_fn() {
Err(EvalError::Unimplemented("unimplemented: mentions of function items".to_string()))
} else {
let cid = ConstantId {
Expand Down
9 changes: 5 additions & 4 deletions src/interpreter/stepper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
};
use error::EvalResult;
use rustc::mir::repr as mir;
use rustc::ty::subst::{self, Subst};
use rustc::ty::subst;
use rustc::hir::def_id::DefId;
use rustc::mir::visit::{Visitor, LvalueContext};
use syntax::codemap::Span;
Expand Down Expand Up @@ -151,9 +151,10 @@ impl<'a, 'b, 'mir, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'mir, 'tcx>
// already computed by rustc
mir::Literal::Value { .. } => {}
mir::Literal::Item { def_id, substs } => {
let item_ty = self.gecx.tcx.lookup_item_type(def_id).subst(self.gecx.tcx, substs);
if item_ty.ty.is_fn() {
// unimplemented
if constant.ty.is_fn() {
// No need to do anything here, even if function pointers are implemented,
// 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.static_item(def_id, substs, constant.span);
}
Expand Down

0 comments on commit 225a6a2

Please sign in to comment.