From fbc7398badef55d58476b5410e7e911bb872f537 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 8 Aug 2017 12:25:22 +0200 Subject: [PATCH] Use ItemLocalId as key for TypeckTables::cast_kinds. --- src/librustc/ich/impls_ty.rs | 2 +- src/librustc/ty/context.rs | 5 +++-- src/librustc_mir/hair/cx/expr.rs | 5 ++++- src/librustc_passes/consts.rs | 3 ++- src/librustc_typeck/check/cast.rs | 8 ++++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 84058119b4591..7b98eb0fb7178 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -658,7 +658,7 @@ for ty::TypeckTables<'gcx> { ich::hash_stable_itemlocalmap(hcx, hasher, closure_kinds); ich::hash_stable_itemlocalmap(hcx, hasher, liberated_fn_sigs); ich::hash_stable_itemlocalmap(hcx, hasher, fru_field_types); - ich::hash_stable_nodemap(hcx, hasher, cast_kinds); + ich::hash_stable_itemlocalmap(hcx, hasher, cast_kinds); ich::hash_stable_hashset(hcx, hasher, used_trait_imports, |hcx, def_id| { hcx.def_path_hash(*def_id) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index f09488ebcfa68..bf412b5700719 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -257,7 +257,7 @@ pub struct TypeckTables<'tcx> { /// Maps a cast expression to its kind. This is keyed on the /// *from* expression of the cast, not the cast itself. - pub cast_kinds: NodeMap, + pub cast_kinds: ItemLocalMap, /// Set of trait imports actually used in the method resolution. /// This is used for warning unused imports. @@ -287,7 +287,8 @@ impl<'tcx> TypeckTables<'tcx> { closure_kinds: ItemLocalMap(), liberated_fn_sigs: ItemLocalMap(), fru_field_types: ItemLocalMap(), - cast_kinds: NodeMap(), + cast_kinds: ItemLocalMap(), + lints: lint::LintTable::new(), used_trait_imports: DefIdSet(), tainted_by_errors: false, free_region_map: FreeRegionMap::new(), diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 30f7378e83b1e..05709fed0af8a 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -551,7 +551,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir::ExprCast(ref source, _) => { // Check to see if this cast is a "coercion cast", where the cast is actually done // using a coercion (or is a no-op). - if let Some(&TyCastKind::CoercionCast) = cx.tables().cast_kinds.get(&source.id) { + cx.tables().validate_hir_id(source.hir_id); + if let Some(&TyCastKind::CoercionCast) = cx.tables() + .cast_kinds + .get(&source.hir_id.local_id) { // Convert the lexpr to a vexpr. ExprKind::Use { source: source.to_ref() } } else { diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index c06ae721f365f..4a2925175c271 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -320,7 +320,8 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node } hir::ExprCast(ref from, _) => { debug!("Checking const cast(id={})", from.id); - match v.tables.cast_kinds.get(&from.id) { + v.tables.validate_hir_id(from.hir_id); + match v.tables.cast_kinds.get(&from.hir_id.local_id) { None => span_bug!(e.span, "no kind for cast"), Some(&CastKind::PtrAddrCast) | Some(&CastKind::FnPtrAddrCast) => { v.promotable = false; diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 5f256eab9a9c8..2be427eee1b91 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -330,12 +330,16 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } else if self.try_coercion_cast(fcx) { self.trivial_cast_lint(fcx); debug!(" -> CoercionCast"); - fcx.tables.borrow_mut().cast_kinds.insert(self.expr.id, CastKind::CoercionCast); + let mut tables = fcx.tables.borrow_mut(); + tables.validate_hir_id(self.expr.hir_id); + tables.cast_kinds.insert(self.expr.hir_id.local_id, CastKind::CoercionCast); } else { match self.do_check(fcx) { Ok(k) => { debug!(" -> {:?}", k); - fcx.tables.borrow_mut().cast_kinds.insert(self.expr.id, k); + let mut tables = fcx.tables.borrow_mut(); + tables.validate_hir_id(self.expr.hir_id); + tables.cast_kinds.insert(self.expr.hir_id.local_id, k); } Err(e) => self.report_cast_error(fcx, e), };