Skip to content

Commit f4010d7

Browse files
committed
move cast_kinds into TypeckTables where it belongs
1 parent 463affe commit f4010d7

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

src/librustc/ty/context.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ pub struct TypeckTables<'tcx> {
231231
/// of the struct - this is needed because it is non-trivial to
232232
/// normalize while preserving regions. This table is used only in
233233
/// MIR construction and hence is not serialized to metadata.
234-
pub fru_field_types: NodeMap<Vec<Ty<'tcx>>>
234+
pub fru_field_types: NodeMap<Vec<Ty<'tcx>>>,
235+
236+
/// Maps a cast expression to its kind. This is keyed on the
237+
/// *from* expression of the cast, not the cast itself.
238+
pub cast_kinds: NodeMap<ty::cast::CastKind>,
235239
}
236240

237241
impl<'tcx> TypeckTables<'tcx> {
@@ -246,7 +250,8 @@ impl<'tcx> TypeckTables<'tcx> {
246250
closure_tys: NodeMap(),
247251
closure_kinds: NodeMap(),
248252
liberated_fn_sigs: NodeMap(),
249-
fru_field_types: NodeMap()
253+
fru_field_types: NodeMap(),
254+
cast_kinds: NodeMap(),
250255
}
251256
}
252257

@@ -533,10 +538,6 @@ pub struct GlobalCtxt<'tcx> {
533538
/// expression defining the closure.
534539
pub closure_kinds: RefCell<DepTrackingMap<maps::ClosureKinds<'tcx>>>,
535540

536-
/// Maps a cast expression to its kind. This is keyed on the
537-
/// *from* expression of the cast, not the cast itself.
538-
pub cast_kinds: RefCell<NodeMap<ty::cast::CastKind>>,
539-
540541
/// Maps Fn items to a collection of fragment infos.
541542
///
542543
/// The main goal is to identify data (each of which may be moved
@@ -792,7 +793,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
792793
custom_coerce_unsized_kinds: RefCell::new(DefIdMap()),
793794
closure_tys: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
794795
closure_kinds: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
795-
cast_kinds: RefCell::new(NodeMap()),
796796
fragment_infos: RefCell::new(DefIdMap()),
797797
crate_name: Symbol::intern(crate_name),
798798
data_layout: data_layout,

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
663663
hir::ExprCast(ref source, _) => {
664664
// Check to see if this cast is a "coercion cast", where the cast is actually done
665665
// using a coercion (or is a no-op).
666-
if let Some(&TyCastKind::CoercionCast) = cx.tcx.cast_kinds.borrow().get(&source.id) {
666+
if let Some(&TyCastKind::CoercionCast) = cx.tables().cast_kinds.get(&source.id) {
667667
// Convert the lexpr to a vexpr.
668668
ExprKind::Use { source: source.to_ref() }
669669
} else {

src/librustc_passes/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
314314
}
315315
hir::ExprCast(ref from, _) => {
316316
debug!("Checking const cast(id={})", from.id);
317-
match v.tcx.cast_kinds.borrow().get(&from.id) {
317+
match v.tables.cast_kinds.get(&from.id) {
318318
None => span_bug!(e.span, "no kind for cast"),
319319
Some(&CastKind::PtrAddrCast) | Some(&CastKind::FnPtrAddrCast) => {
320320
v.promotable = false;

src/librustc_typeck/check/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
348348
} else if self.try_coercion_cast(fcx) {
349349
self.trivial_cast_lint(fcx);
350350
debug!(" -> CoercionCast");
351-
fcx.tcx.cast_kinds.borrow_mut().insert(self.expr.id, CastKind::CoercionCast);
351+
fcx.tables.borrow_mut().cast_kinds.insert(self.expr.id, CastKind::CoercionCast);
352352
} else {
353353
match self.do_check(fcx) {
354354
Ok(k) => {
355355
debug!(" -> {:?}", k);
356-
fcx.tcx.cast_kinds.borrow_mut().insert(self.expr.id, k);
356+
fcx.tables.borrow_mut().cast_kinds.insert(self.expr.id, k);
357357
}
358358
Err(e) => self.report_cast_error(fcx, e),
359359
};

src/librustc_typeck/check/writeback.rs

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5151
wbcx.visit_anon_types();
5252
wbcx.visit_deferred_obligations(item_id);
5353
wbcx.visit_type_nodes();
54+
wbcx.visit_cast_types();
5455

5556
let tables = self.tcx.alloc_tables(wbcx.tables);
5657
self.tcx.tables.borrow_mut().insert(item_def_id, tables);
@@ -291,6 +292,15 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
291292
}
292293
}
293294

295+
fn visit_cast_types(&mut self) {
296+
if self.fcx.writeback_errors.get() {
297+
return
298+
}
299+
300+
self.tables.cast_kinds.extend(
301+
self.fcx.tables.borrow().cast_kinds.iter().map(|(&key, &value)| (key, value)));
302+
}
303+
294304
fn visit_anon_types(&self) {
295305
if self.fcx.writeback_errors.get() {
296306
return

0 commit comments

Comments
 (0)