Navigation Menu

Skip to content

Commit

Permalink
Use ItemLocalId as key for TypeckTables::cast_kinds.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Aug 11, 2017
1 parent 801dd07 commit fbc7398
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_ty.rs
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/ty/context.rs
Expand Up @@ -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<ty::cast::CastKind>,
pub cast_kinds: ItemLocalMap<ty::cast::CastKind>,

/// Set of trait imports actually used in the method resolution.
/// This is used for warning unused imports.
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_passes/consts.rs
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_typeck/check/cast.rs
Expand Up @@ -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),
};
Expand Down

0 comments on commit fbc7398

Please sign in to comment.