Skip to content

Commit 9bcd9fe

Browse files
committed
Address review comments
1 parent 770be24 commit 9bcd9fe

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

src/librustc/ty/sty.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use polonius_engine::Atom;
2020
use rustc_ast::ast::{self, Ident};
2121
use rustc_data_structures::captures::Captures;
2222
use rustc_hir as hir;
23-
use rustc_hir::def_id::DefId;
23+
use rustc_hir::def_id::{DefId, LocalDefId};
2424
use rustc_index::vec::Idx;
2525
use rustc_macros::HashStable;
2626
use rustc_span::symbol::{kw, Symbol};
@@ -2404,15 +2404,17 @@ static_assert_size!(Const<'_>, 48);
24042404
impl<'tcx> Const<'tcx> {
24052405
/// Literals and const generic parameters are eagerly converted to a constant, everything else
24062406
/// becomes `Unevaluated`.
2407-
pub fn from_hir_anon_const(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>) -> &'tcx Self {
2408-
debug!("Const::from_hir_anon_const(id={:?})", def_id);
2407+
pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx Self {
2408+
debug!("Const::from_anon_const(id={:?})", def_id);
24092409

2410-
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
2410+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
24112411

24122412
let body_id = tcx.hir().body_owned_by(hir_id);
24132413

24142414
let expr = &tcx.hir().body(body_id).value;
24152415

2416+
let ty = tcx.type_of(def_id.to_def_id());
2417+
24162418
let lit_input = match expr.kind {
24172419
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
24182420
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => match expr.kind {
@@ -2457,8 +2459,8 @@ impl<'tcx> Const<'tcx> {
24572459
ty::ConstKind::Param(ty::ParamConst::new(index, name))
24582460
}
24592461
_ => ty::ConstKind::Unevaluated(
2460-
def_id,
2461-
InternalSubsts::identity_for_item(tcx, def_id),
2462+
def_id.to_def_id(),
2463+
InternalSubsts::identity_for_item(tcx, def_id.to_def_id()),
24622464
None,
24632465
),
24642466
};

src/librustc_mir_build/hair/cx/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ fn make_mirror_unadjusted<'a, 'tcx>(
406406

407407
// Now comes the rote stuff:
408408
hir::ExprKind::Repeat(ref v, ref count) => {
409-
let count = cx.tcx.hir().local_def_id(count.hir_id);
410-
let count = ty::Const::from_hir_anon_const(cx.tcx, count, cx.tcx.types.usize);
409+
let count_def_id = cx.tcx.hir().local_def_id(count.hir_id).expect_local();
410+
let count = ty::Const::from_anon_const(cx.tcx, count_def_id);
411411

412412
ExprKind::Repeat { value: v.to_ref(), count }
413413
}

src/librustc_typeck/astconv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
780780
}
781781
}
782782
(GenericParamDefKind::Const, GenericArg::Const(ct)) => {
783-
let ct = tcx.hir().local_def_id(ct.value.hir_id);
784-
ty::Const::from_hir_anon_const(tcx, ct, tcx.type_of(param.def_id)).into()
783+
let ct_def_id = tcx.hir().local_def_id(ct.value.hir_id).expect_local();
784+
ty::Const::from_anon_const(tcx, ct_def_id).into()
785785
}
786786
_ => unreachable!(),
787787
},
@@ -2765,8 +2765,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27652765
.unwrap_or(tcx.types.err)
27662766
}
27672767
hir::TyKind::Array(ref ty, ref length) => {
2768-
let length = tcx.hir().local_def_id(length.hir_id);
2769-
let length = ty::Const::from_hir_anon_const(tcx, length, tcx.types.usize);
2768+
let length_def_id = tcx.hir().local_def_id(length.hir_id).expect_local();
2769+
let length = ty::Const::from_anon_const(tcx, length_def_id);
27702770
let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length));
27712771
self.normalize_ty(ast_ty.span, array_ty)
27722772
}

src/librustc_typeck/check/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10071007
_expr: &'tcx hir::Expr<'tcx>,
10081008
) -> Ty<'tcx> {
10091009
let tcx = self.tcx;
1010-
let count_def_id = tcx.hir().local_def_id(count.hir_id);
1011-
let count = self.to_const(count, tcx.type_of(count_def_id));
1010+
let count = self.to_const(count);
10121011

10131012
let uty = match expected {
10141013
ExpectHasType(uty) => match uty.kind {

src/librustc_typeck/check/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
331331
}
332332
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => self.to_ty(ty).into(),
333333
(GenericParamDefKind::Const, GenericArg::Const(ct)) => {
334-
self.to_const(&ct.value, self.tcx.type_of(param.def_id)).into()
334+
self.to_const(&ct.value).into()
335335
}
336336
_ => unreachable!(),
337337
},

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,9 +3279,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32793279
ty
32803280
}
32813281

3282-
pub fn to_const(&self, ast_c: &hir::AnonConst, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
3283-
let c = self.tcx.hir().local_def_id(ast_c.hir_id);
3284-
ty::Const::from_hir_anon_const(self.tcx, c, ty)
3282+
pub fn to_const(&self, ast_c: &hir::AnonConst) -> &'tcx ty::Const<'tcx> {
3283+
let c = self.tcx.hir().local_def_id(ast_c.hir_id).expect_local();
3284+
ty::Const::from_anon_const(self.tcx, c)
32853285
}
32863286

32873287
// If the type given by the user has free regions, save it for later, since
@@ -5510,7 +5510,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
55105510
self.to_ty(ty).into()
55115511
}
55125512
(GenericParamDefKind::Const, GenericArg::Const(ct)) => {
5513-
self.to_const(&ct.value, self.tcx.type_of(param.def_id)).into()
5513+
self.to_const(&ct.value).into()
55145514
}
55155515
_ => unreachable!(),
55165516
},

0 commit comments

Comments
 (0)