use hir::def::CtorKind;
use hir::def_id::DefId;
use ty::subst::{Subst, Substs};
-use ty::{self, AdtDef, ClosureSubsts, Region, Ty, GeneratorInterior};
+use ty::{self, AdtDef, ClosureSubsts, Region, Ty, TyCtxt, GeneratorInterior};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use util::ppaux;
use rustc_back::slice;
}
impl<'tcx> TerminatorKind<'tcx> {
- pub fn if_<'a, 'gcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>, cond: Operand<'tcx>,
+ pub fn if_<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, cond: Operand<'tcx>,
t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
static BOOL_SWITCH_FALSE: &'static [ConstInt] = &[ConstInt::U8(0)];
TerminatorKind::SwitchInt {
impl<'tcx> Operand<'tcx> {
pub fn function_handle<'a>(
- tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
+ tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
span: Span,
) -> Self {
+ let ty = tcx.type_of(def_id).subst(tcx, substs);
Operand::Constant(box Constant {
span,
- ty: tcx.type_of(def_id).subst(tcx, substs),
- literal: Literal::Value { value: ConstVal::Function(def_id, substs) },
+ ty,
+ literal: Literal::Value {
+ value: tcx.mk_const(ty::Const {
+ val: ConstVal::Function(def_id, substs),
+ ty
+ })
+ },
})
}
tcx.with_freevars(node_id, |freevars| {
for (freevar, lv) in freevars.iter().zip(lvs) {
- let def_id = freevar.def.def_id();
- let var_id = tcx.hir.as_local_node_id(def_id).unwrap();
- let var_name = tcx.local_var_name_str(var_id);
- struct_fmt.field(&var_name, lv);
+ let var_name = tcx.hir.name(freevar.var_id());
+ struct_fmt.field(&var_name.as_str(), lv);
}
});
tcx.with_freevars(node_id, |freevars| {
for (freevar, lv) in freevars.iter().zip(lvs) {
- let def_id = freevar.def.def_id();
- let var_id = tcx.hir.as_local_node_id(def_id).unwrap();
- let var_name = tcx.local_var_name_str(var_id);
- struct_fmt.field(&var_name, lv);
+ let var_name = tcx.hir.name(freevar.var_id());
+ struct_fmt.field(&var_name.as_str(), lv);
}
struct_fmt.field("$state", &lvs[freevars.len()]);
for i in (freevars.len() + 1)..lvs.len() {
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub enum Literal<'tcx> {
- Item {
- def_id: DefId,
- substs: &'tcx Substs<'tcx>,
- },
Value {
- value: ConstVal<'tcx>,
+ value: &'tcx ty::Const<'tcx>,
},
Promoted {
// Index into the `promoted` vector of `Mir`.
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
use self::Literal::*;
match *self {
- Item { def_id, substs } => {
- ppaux::parameterized(fmt, substs, def_id, &[])
- }
- Value { ref value } => {
+ Value { value } => {
write!(fmt, "const ")?;
- fmt_const_val(fmt, value)
+ fmt_const_val(fmt, &value.val)
}
Promoted { index } => {
write!(fmt, "{:?}", index)
match *const_val {
Float(f) => write!(fmt, "{:?}", f),
Integral(n) => write!(fmt, "{}", n),
- Str(ref s) => write!(fmt, "{:?}", s),
- ByteStr(ref bytes) => {
- let escaped: String = bytes
+ Str(s) => write!(fmt, "{:?}", s),
+ ByteStr(bytes) => {
+ let escaped: String = bytes.data
.iter()
.flat_map(|&ch| ascii::escape_default(ch).map(|c| c as char))
.collect();
Char(c) => write!(fmt, "{:?}", c),
Variant(def_id) |
Function(def_id, _) => write!(fmt, "{}", item_path_str(def_id)),
- Struct(_) | Tuple(_) | Array(_) | Repeat(..) =>
- bug!("ConstVal `{:?}` should not be in MIR", const_val),
+ Aggregate(_) => bug!("`ConstVal::{:?}` should not be in MIR", const_val),
+ Unevaluated(..) => write!(fmt, "{:?}", const_val)
}
}
impl<'tcx> TypeFoldable<'tcx> for Literal<'tcx> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
match *self {
- Literal::Item { def_id, substs } => Literal::Item {
- def_id,
- substs: substs.fold_with(folder)
+ Literal::Value { value } => Literal::Value {
+ value: value.fold_with(folder)
},
- _ => self.clone()
+ Literal::Promoted { index } => Literal::Promoted { index }
}
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
match *self {
- Literal::Item { substs, .. } => substs.visit_with(visitor),
- _ => false
+ Literal::Value { value } => value.visit_with(visitor),
+ Literal::Promoted { .. } => false
}
}
}