Skip to content

Commit 2123539

Browse files
author
Saleem Jaffer
committed
minor
1 parent 937f713 commit 2123539

File tree

4 files changed

+18
-38
lines changed

4 files changed

+18
-38
lines changed

src/librustc/ty/context.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::ty::steal::Steal;
4040
use crate::ty::subst::{UserSubsts, UnpackedKind};
4141
use crate::ty::{BoundVar, BindingMode};
4242
use crate::ty::CanonicalPolyFnSig;
43-
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap};
43+
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet};
4444
use crate::util::nodemap::{FxHashMap, FxHashSet};
4545
use errors::DiagnosticBuilder;
4646
use rustc_data_structures::interner::HashInterner;
@@ -409,9 +409,7 @@ pub struct TypeckTables<'tcx> {
409409
/// MIR construction and hence is not serialized to metadata.
410410
fru_field_types: ItemLocalMap<Vec<Ty<'tcx>>>,
411411

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

416414
/// Set of trait imports actually used in the method resolution.
417415
/// This is used for warning unused imports. During type
@@ -456,7 +454,7 @@ impl<'tcx> TypeckTables<'tcx> {
456454
closure_kind_origins: Default::default(),
457455
liberated_fn_sigs: Default::default(),
458456
fru_field_types: Default::default(),
459-
cast_kinds: Default::default(),
457+
coercion_casts: Default::default(),
460458
used_trait_imports: Lrc::new(Default::default()),
461459
tainted_by_errors: false,
462460
free_region_map: Default::default(),
@@ -718,19 +716,17 @@ impl<'tcx> TypeckTables<'tcx> {
718716
}
719717
}
720718

721-
pub fn cast_kinds(&self) -> LocalTableInContext<'_, ty::cast::CastKind> {
722-
LocalTableInContext {
723-
local_id_root: self.local_id_root,
724-
data: &self.cast_kinds
719+
pub fn is_coercion_cast(&self, hir_id: &hir::HirId) -> bool {
720+
if self.coercion_casts.contains(&hir_id.local_id) {
721+
return true
725722
}
723+
false
726724
}
727725

728-
pub fn cast_kinds_mut(&mut self) -> LocalTableInContextMut<'_, ty::cast::CastKind> {
729-
LocalTableInContextMut {
730-
local_id_root: self.local_id_root,
731-
data: &mut self.cast_kinds
732-
}
726+
pub fn set_coercion_cast(&mut self, hir_id: &hir::HirId) -> () {
727+
self.coercion_casts.insert(hir_id.local_id);
733728
}
729+
734730
}
735731

736732
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
@@ -753,7 +749,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
753749
ref liberated_fn_sigs,
754750
ref fru_field_types,
755751

756-
ref cast_kinds,
752+
ref coercion_casts,
757753

758754
ref used_trait_imports,
759755
tainted_by_errors,
@@ -798,7 +794,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
798794
closure_kind_origins.hash_stable(hcx, hasher);
799795
liberated_fn_sigs.hash_stable(hcx, hasher);
800796
fru_field_types.hash_stable(hcx, hasher);
801-
cast_kinds.hash_stable(hcx, hasher);
797+
coercion_casts.hash_stable(hcx, hasher);
802798
used_trait_imports.hash_stable(hcx, hasher);
803799
tainted_by_errors.hash_stable(hcx, hasher);
804800
free_region_map.hash_stable(hcx, hasher);

src/librustc_mir/hair/cx/expr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
651651
user_ty,
652652
);
653653

654-
let source_ty = cx.tables().expr_ty(source);
655-
let cast = if source_ty == expr_ty {
654+
// Check to see if this cast is a "coercion cast", where the cast is actually done
655+
// using a coercion (or is a no-op).
656+
let cast = if cx.tables().is_coercion_cast(&source.hir_id)
657+
{
656658
// Convert the lexpr to a vexpr.
657659
ExprKind::Use { source: source.to_ref() }
658660
} else {

src/librustc_typeck/check/cast.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
428428
} else if self.try_coercion_cast(fcx) {
429429
self.trivial_cast_lint(fcx);
430430
debug!(" -> CoercionCast");
431-
fcx.tables.borrow_mut().cast_kinds_mut().insert(self.expr.hir_id,
432-
CastKind::CoercionCast);
431+
fcx.tables.borrow_mut().set_coercion_cast(&self.expr.hir_id);
432+
433433
} else {
434434
match self.do_check(fcx) {
435435
Ok(k) => {
436436
debug!(" -> {:?}", k);
437-
fcx.tables.borrow_mut().cast_kinds_mut().insert(self.expr.hir_id, k);
438437
}
439438
Err(e) => self.report_cast_error(fcx, e),
440439
};

src/librustc_typeck/check/writeback.rs

-17
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5050
wbcx.visit_liberated_fn_sigs();
5151
wbcx.visit_fru_field_types();
5252
wbcx.visit_opaque_types(body.value.span);
53-
wbcx.visit_cast_types();
5453
wbcx.visit_free_region_map();
5554
wbcx.visit_user_provided_tys();
5655
wbcx.visit_user_provided_sigs();
@@ -355,22 +354,6 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
355354
}
356355
}
357356

358-
fn visit_cast_types(&mut self) {
359-
let fcx_tables = self.fcx.tables.borrow();
360-
let fcx_cast_kinds = fcx_tables.cast_kinds();
361-
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
362-
let mut self_cast_kinds = self.tables.cast_kinds_mut();
363-
let common_local_id_root = fcx_tables.local_id_root.unwrap();
364-
365-
for (&local_id, &cast_kind) in fcx_cast_kinds.iter() {
366-
let hir_id = hir::HirId {
367-
owner: common_local_id_root.index,
368-
local_id,
369-
};
370-
self_cast_kinds.insert(hir_id, cast_kind);
371-
}
372-
}
373-
374357
fn visit_free_region_map(&mut self) {
375358
let free_region_map = self.tcx()
376359
.lift_to_global(&self.fcx.tables.borrow().free_region_map);

0 commit comments

Comments
 (0)