]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/mir/mod.rs
Rollup merge of #44562 - eddyb:ugh-rustdoc, r=nikomatsakis
[rust.git] / src / librustc / mir / mod.rs
index cf3d7c3642a5feadafca0ed5ccda504c759158a3..d43504b77ba0c40c9ef182b5f40cd398df9be471 100644 (file)
@@ -21,7 +21,7 @@
 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;
@@ -644,7 +644,7 @@ pub fn successors_mut(&mut self) -> Vec<&mut BasicBlock> {
 }
 
 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 {
@@ -1182,15 +1182,21 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
 
 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
+                })
+            },
         })
     }
 
@@ -1416,10 +1422,8 @@ fn fmt_tuple(fmt: &mut Formatter, lvs: &[Operand]) -> fmt::Result {
 
                             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);
                                 }
                             });
 
@@ -1436,10 +1440,8 @@ fn fmt_tuple(fmt: &mut Formatter, lvs: &[Operand]) -> fmt::Result {
 
                             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() {
@@ -1477,12 +1479,8 @@ pub struct Constant<'tcx> {
 
 #[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`.
@@ -1500,12 +1498,9 @@ impl<'tcx> Debug for Literal<'tcx> {
     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)
@@ -1520,9 +1515,9 @@ fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ConstVal) -> fmt::Result {
     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();
@@ -1532,8 +1527,8 @@ fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ConstVal) -> fmt::Result {
         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)
     }
 }
 
@@ -2000,17 +1995,16 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
 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
         }
     }
 }