about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2020-03-17 18:54:20 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2020-03-23 13:15:02 +0100
commit770be24ccd9c47c05aceff91ce5a081798d97c67 (patch)
treeea77a8d00898aa993c98f65a8079b72d9deb9d69
parent3f89c38bc0231f08e0eee6fa9942e7c71b5544f3 (diff)
downloadrust-770be24ccd9c47c05aceff91ce5a081798d97c67.tar.gz
rust-770be24ccd9c47c05aceff91ce5a081798d97c67.zip
Use `DefId`s to identify anon consts when converting from HIR to ty::Const
-rw-r--r--src/librustc/ty/sty.rs14
-rw-r--r--src/librustc_mir_build/hair/cx/expr.rs1
-rw-r--r--src/librustc_typeck/astconv.rs4
-rw-r--r--src/librustc_typeck/check/mod.rs3
4 files changed, 12 insertions, 10 deletions
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index 9e0f4668d95..e5c88c1c9ba 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -2404,16 +2404,14 @@ static_assert_size!(Const<'_>, 48);
 impl<'tcx> Const<'tcx> {
     /// Literals and const generic parameters are eagerly converted to a constant, everything else
     /// becomes `Unevaluated`.
-    pub fn from_hir_anon_const(
-        tcx: TyCtxt<'tcx>,
-        ast_const: &hir::AnonConst,
-        ty: Ty<'tcx>,
-    ) -> &'tcx Self {
-        debug!("Const::from_hir_anon_const(id={:?}, ast_const={:?})", ast_const.hir_id, ast_const);
+    pub fn from_hir_anon_const(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>) -> &'tcx Self {
+        debug!("Const::from_hir_anon_const(id={:?})", def_id);
+
+        let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
 
-        let def_id = tcx.hir().local_def_id(ast_const.hir_id);
+        let body_id = tcx.hir().body_owned_by(hir_id);
 
-        let expr = &tcx.hir().body(ast_const.body).value;
+        let expr = &tcx.hir().body(body_id).value;
 
         let lit_input = match expr.kind {
             hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs
index b9c9e9834ef..73c442e4a91 100644
--- a/src/librustc_mir_build/hair/cx/expr.rs
+++ b/src/librustc_mir_build/hair/cx/expr.rs
@@ -406,6 +406,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
 
         // Now comes the rote stuff:
         hir::ExprKind::Repeat(ref v, ref count) => {
+            let count = cx.tcx.hir().local_def_id(count.hir_id);
             let count = ty::Const::from_hir_anon_const(cx.tcx, count, cx.tcx.types.usize);
 
             ExprKind::Repeat { value: v.to_ref(), count }
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 2d7bf81aedd..ee713482268 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -780,7 +780,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                     }
                 }
                 (GenericParamDefKind::Const, GenericArg::Const(ct)) => {
-                    ty::Const::from_hir_anon_const(tcx, &ct.value, tcx.type_of(param.def_id)).into()
+                    let ct = tcx.hir().local_def_id(ct.value.hir_id);
+                    ty::Const::from_hir_anon_const(tcx, ct, tcx.type_of(param.def_id)).into()
                 }
                 _ => unreachable!(),
             },
@@ -2764,6 +2765,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                     .unwrap_or(tcx.types.err)
             }
             hir::TyKind::Array(ref ty, ref length) => {
+                let length = tcx.hir().local_def_id(length.hir_id);
                 let length = ty::Const::from_hir_anon_const(tcx, length, tcx.types.usize);
                 let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length));
                 self.normalize_ty(ast_ty.span, array_ty)
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 292ad1e94a7..f790bcfbb09 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -3280,7 +3280,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     }
 
     pub fn to_const(&self, ast_c: &hir::AnonConst, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
-        ty::Const::from_hir_anon_const(self.tcx, ast_c, ty)
+        let c = self.tcx.hir().local_def_id(ast_c.hir_id);
+        ty::Const::from_hir_anon_const(self.tcx, c, ty)
     }
 
     // If the type given by the user has free regions, save it for later, since