]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_const_eval/eval.rs
use suggestions instead of helps with code in them
[rust.git] / src / librustc_const_eval / eval.rs
index c899d2109f51cf54140098dc3456795b1a3e9d2f..47a98155fc4b026a425a37fd0a1f9805140b83a7 100644 (file)
@@ -8,14 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//#![allow(non_camel_case_types)]
-
 use rustc::middle::const_val::ConstVal::*;
 use rustc::middle::const_val::ConstVal;
 use self::ErrKind::*;
 use self::EvalHint::*;
 
-use rustc::hir::map as ast_map;
+use rustc::hir::map as hir_map;
 use rustc::hir::map::blocks::FnLikeNode;
 use rustc::traits;
 use rustc::hir::def::Def;
@@ -52,16 +50,16 @@ macro_rules! math {
 
 fn lookup_variant_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                   variant_def: DefId)
-                                  -> Option<(&'tcx Expr, Option<&'a ty::Tables<'tcx>>)> {
-    if let Some(variant_node_id) = tcx.map.as_local_node_id(variant_def) {
-        let enum_node_id = tcx.map.get_parent(variant_node_id);
-        if let Some(ast_map::NodeItem(it)) = tcx.map.find(enum_node_id) {
+                                  -> Option<(&'tcx Expr, Option<&'a ty::TypeckTables<'tcx>>)> {
+    if let Some(variant_node_id) = tcx.hir.as_local_node_id(variant_def) {
+        let enum_node_id = tcx.hir.get_parent(variant_node_id);
+        if let Some(hir_map::NodeItem(it)) = tcx.hir.find(enum_node_id) {
             if let hir::ItemEnum(ref edef, _) = it.node {
                 for variant in &edef.variants {
                     if variant.node.data.id() == variant_node_id {
                         return variant.node.disr_expr.map(|e| {
-                            let def_id = tcx.map.body_owner_def_id(e);
-                            (&tcx.map.body(e).value,
+                            let def_id = tcx.hir.body_owner_def_id(e);
+                            (&tcx.hir.body(e).value,
                              tcx.tables.borrow().get(&def_id).cloned())
                         });
                     }
@@ -81,31 +79,31 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                         def_id: DefId,
                                         substs: Option<&'tcx Substs<'tcx>>)
                                         -> Option<(&'tcx Expr,
-                                                   Option<&'a ty::Tables<'tcx>>,
+                                                   Option<&'a ty::TypeckTables<'tcx>>,
                                                    Option<ty::Ty<'tcx>>)> {
-    if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
-        match tcx.map.find(node_id) {
+    if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
+        match tcx.hir.find(node_id) {
             None => None,
-            Some(ast_map::NodeItem(&hir::Item {
+            Some(hir_map::NodeItem(&hir::Item {
                 node: hir::ItemConst(ref ty, body), ..
             })) |
-            Some(ast_map::NodeImplItem(&hir::ImplItem {
+            Some(hir_map::NodeImplItem(&hir::ImplItem {
                 node: hir::ImplItemKind::Const(ref ty, body), ..
             })) => {
-                Some((&tcx.map.body(body).value,
+                Some((&tcx.hir.body(body).value,
                       tcx.tables.borrow().get(&def_id).cloned(),
                       tcx.ast_ty_to_prim_ty(ty)))
             }
-            Some(ast_map::NodeTraitItem(ti)) => match ti.node {
+            Some(hir_map::NodeTraitItem(ti)) => match ti.node {
                 hir::TraitItemKind::Const(ref ty, default) => {
                     if let Some(substs) = substs {
                         // If we have a trait item and the substitutions for it,
                         // `resolve_trait_associated_const` will select an impl
                         // or the default.
-                        let trait_id = tcx.map.get_parent(node_id);
-                        let trait_id = tcx.map.local_def_id(trait_id);
+                        let trait_id = tcx.hir.get_parent(node_id);
+                        let trait_id = tcx.hir.local_def_id(trait_id);
                         let default_value = default.map(|body| {
-                            (&tcx.map.body(body).value,
+                            (&tcx.hir.body(body).value,
                              tcx.tables.borrow().get(&def_id).cloned(),
                              tcx.ast_ty_to_prim_ty(ty))
                         });
@@ -154,12 +152,12 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 }
 
 fn lookup_const_fn_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
-                                   -> Option<(&'tcx hir::Body, Option<&'a ty::Tables<'tcx>>)>
+                                   -> Option<(&'tcx hir::Body, Option<&'a ty::TypeckTables<'tcx>>)>
 {
-    if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
-        FnLikeNode::from_node(tcx.map.get(node_id)).and_then(|fn_like| {
+    if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
+        FnLikeNode::from_node(tcx.hir.get(node_id)).and_then(|fn_like| {
             if fn_like.constness() == hir::Constness::Const {
-                Some((tcx.map.body(fn_like.body()),
+                Some((tcx.hir.body(fn_like.body()),
                       tcx.tables.borrow().get(&def_id).cloned()))
             } else {
                 None
@@ -226,13 +224,13 @@ pub fn note_const_eval_err<'a, 'tcx>(
 
 pub struct ConstContext<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    tables: Option<&'a ty::Tables<'tcx>>,
+    tables: Option<&'a ty::TypeckTables<'tcx>>,
     fn_args: Option<DefIdMap<ConstVal>>
 }
 
 impl<'a, 'tcx> ConstContext<'a, 'tcx> {
     pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, body: hir::BodyId) -> Self {
-        let def_id = tcx.map.body_owner_def_id(body);
+        let def_id = tcx.hir.body_owner_def_id(body);
         ConstContext {
             tcx: tcx,
             tables: tcx.tables.borrow().get(&def_id).cloned(),
@@ -240,7 +238,7 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, body: hir::BodyId) -> Self {
         }
     }
 
-    pub fn with_tables(tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::Tables<'tcx>) -> Self {
+    pub fn with_tables(tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>) -> Self {
         ConstContext {
             tcx: tcx,
             tables: Some(tables),
@@ -808,7 +806,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
                 _ => bug!()
             }
           } else {
-            let n = &tcx.map.body(count).value;
+            let n = &tcx.hir.body(count).value;
             match ConstContext::new(tcx, count).eval(n, len_hint)? {
                 Integral(Usize(i)) => i.as_u64(tcx.sess.target.uint_type),
                 Integral(_) => signal!(e, RepeatCountNotNatural),
@@ -920,10 +918,10 @@ fn infer<'a, 'tcx>(i: ConstInt,
 fn resolve_trait_associated_const<'a, 'tcx: 'a>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     trait_item_id: DefId,
-    default_value: Option<(&'tcx Expr, Option<&'a ty::Tables<'tcx>>, Option<ty::Ty<'tcx>>)>,
+    default_value: Option<(&'tcx Expr, Option<&'a ty::TypeckTables<'tcx>>, Option<ty::Ty<'tcx>>)>,
     trait_id: DefId,
     rcvr_substs: &'tcx Substs<'tcx>
-) -> Option<(&'tcx Expr, Option<&'a ty::Tables<'tcx>>, Option<ty::Ty<'tcx>>)>
+) -> Option<(&'tcx Expr, Option<&'a ty::TypeckTables<'tcx>>, Option<ty::Ty<'tcx>>)>
 {
     let trait_ref = ty::Binder(ty::TraitRef::new(trait_id, rcvr_substs));
     debug!("resolve_trait_associated_const: trait_ref={:?}",
@@ -1203,7 +1201,7 @@ pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                              -> Result<usize, ErrorReported>
 {
     let hint = UncheckedExprHint(tcx.types.usize);
-    let count_expr = &tcx.map.body(count).value;
+    let count_expr = &tcx.hir.body(count).value;
     match ConstContext::new(tcx, count).eval(count_expr, hint) {
         Ok(Integral(Usize(count))) => {
             let val = count.as_u64(tcx.sess.target.uint_type);
@@ -1227,7 +1225,7 @@ pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
             if let hir::ExprPath(hir::QPath::Resolved(None, ref path)) = count_expr.node {
                 if let Def::Local(..) = path.def {
                     diag.note(&format!("`{}` is a variable",
-                                       tcx.map.node_to_pretty_string(count_expr.id)));
+                                       tcx.hir.node_to_pretty_string(count_expr.id)));
                 }
             }