Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Saleem Jaffer committed Feb 27, 2019
1 parent 937f713 commit 2123539
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 38 deletions.
28 changes: 12 additions & 16 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::ty::steal::Steal;
use crate::ty::subst::{UserSubsts, UnpackedKind};
use crate::ty::{BoundVar, BindingMode};
use crate::ty::CanonicalPolyFnSig;
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap};
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet};
use crate::util::nodemap::{FxHashMap, FxHashSet};
use errors::DiagnosticBuilder;
use rustc_data_structures::interner::HashInterner;
Expand Down Expand Up @@ -409,9 +409,7 @@ pub struct TypeckTables<'tcx> {
/// MIR construction and hence is not serialized to metadata.
fru_field_types: ItemLocalMap<Vec<Ty<'tcx>>>,

/// Maps a cast expression to its kind. This is keyed on the
/// *from* expression of the cast, not the cast itself.
cast_kinds: ItemLocalMap<ty::cast::CastKind>,
coercion_casts: ItemLocalSet,

/// Set of trait imports actually used in the method resolution.
/// This is used for warning unused imports. During type
Expand Down Expand Up @@ -456,7 +454,7 @@ impl<'tcx> TypeckTables<'tcx> {
closure_kind_origins: Default::default(),
liberated_fn_sigs: Default::default(),
fru_field_types: Default::default(),
cast_kinds: Default::default(),
coercion_casts: Default::default(),
used_trait_imports: Lrc::new(Default::default()),
tainted_by_errors: false,
free_region_map: Default::default(),
Expand Down Expand Up @@ -718,19 +716,17 @@ impl<'tcx> TypeckTables<'tcx> {
}
}

pub fn cast_kinds(&self) -> LocalTableInContext<'_, ty::cast::CastKind> {
LocalTableInContext {
local_id_root: self.local_id_root,
data: &self.cast_kinds
pub fn is_coercion_cast(&self, hir_id: &hir::HirId) -> bool {
if self.coercion_casts.contains(&hir_id.local_id) {
return true
}
false
}

pub fn cast_kinds_mut(&mut self) -> LocalTableInContextMut<'_, ty::cast::CastKind> {
LocalTableInContextMut {
local_id_root: self.local_id_root,
data: &mut self.cast_kinds
}
pub fn set_coercion_cast(&mut self, hir_id: &hir::HirId) -> () {
self.coercion_casts.insert(hir_id.local_id);
}

}

impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
Expand All @@ -753,7 +749,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
ref liberated_fn_sigs,
ref fru_field_types,

ref cast_kinds,
ref coercion_casts,

ref used_trait_imports,
tainted_by_errors,
Expand Down Expand Up @@ -798,7 +794,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
closure_kind_origins.hash_stable(hcx, hasher);
liberated_fn_sigs.hash_stable(hcx, hasher);
fru_field_types.hash_stable(hcx, hasher);
cast_kinds.hash_stable(hcx, hasher);
coercion_casts.hash_stable(hcx, hasher);
used_trait_imports.hash_stable(hcx, hasher);
tainted_by_errors.hash_stable(hcx, hasher);
free_region_map.hash_stable(hcx, hasher);
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
user_ty,
);

let source_ty = cx.tables().expr_ty(source);
let cast = if source_ty == expr_ty {
// Check to see if this cast is a "coercion cast", where the cast is actually done
// using a coercion (or is a no-op).
let cast = if cx.tables().is_coercion_cast(&source.hir_id)
{
// Convert the lexpr to a vexpr.
ExprKind::Use { source: source.to_ref() }
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,12 @@ 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_mut().insert(self.expr.hir_id,
CastKind::CoercionCast);
fcx.tables.borrow_mut().set_coercion_cast(&self.expr.hir_id);

} else {
match self.do_check(fcx) {
Ok(k) => {
debug!(" -> {:?}", k);
fcx.tables.borrow_mut().cast_kinds_mut().insert(self.expr.hir_id, k);
}
Err(e) => self.report_cast_error(fcx, e),
};
Expand Down
17 changes: 0 additions & 17 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
wbcx.visit_liberated_fn_sigs();
wbcx.visit_fru_field_types();
wbcx.visit_opaque_types(body.value.span);
wbcx.visit_cast_types();
wbcx.visit_free_region_map();
wbcx.visit_user_provided_tys();
wbcx.visit_user_provided_sigs();
Expand Down Expand Up @@ -355,22 +354,6 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
}
}

fn visit_cast_types(&mut self) {
let fcx_tables = self.fcx.tables.borrow();
let fcx_cast_kinds = fcx_tables.cast_kinds();
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
let mut self_cast_kinds = self.tables.cast_kinds_mut();
let common_local_id_root = fcx_tables.local_id_root.unwrap();

for (&local_id, &cast_kind) in fcx_cast_kinds.iter() {
let hir_id = hir::HirId {
owner: common_local_id_root.index,
local_id,
};
self_cast_kinds.insert(hir_id, cast_kind);
}
}

fn visit_free_region_map(&mut self) {
let free_region_map = self.tcx()
.lift_to_global(&self.fcx.tables.borrow().free_region_map);
Expand Down

0 comments on commit 2123539

Please sign in to comment.