diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 1ea632d9618f..b6061f39233d 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1197,7 +1197,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - if let Some(ty) = tcx.node_types.borrow().get(&id) { + if let Some(ty) = tcx.node_types().get(&id) { rbml_w.tag(c::tag_table_node_type, |rbml_w| { rbml_w.id(id); rbml_w.emit_ty(ecx, *ty); @@ -1884,7 +1884,7 @@ fn decode_side_tables(dcx: &DecodeContext, let ty = val_dsr.read_ty(dcx); debug!("inserting ty for node {}: {}", id, ty_to_string(dcx.tcx, ty)); - dcx.tcx.node_types.borrow_mut().insert(id, ty); + dcx.tcx.node_type_insert(id, ty); } c::tag_table_item_subst => { let item_substs = ty::ItemSubsts { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 2130ec4eb633..2bfc9689ac2f 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -68,7 +68,7 @@ use util::nodemap::FnvHashMap; use arena::TypedArena; use std::borrow::{Borrow, Cow}; -use std::cell::{Cell, RefCell}; +use std::cell::{Cell, RefCell, Ref}; use std::cmp; use std::fmt; use std::hash::{Hash, SipHasher, Hasher}; @@ -689,7 +689,7 @@ pub struct ctxt<'tcx> { /// Stores the types for various nodes in the AST. Note that this table /// is not guaranteed to be populated until after typeck. See /// typeck::check::fn_ctxt for details. - pub node_types: RefCell>>, + node_types: RefCell>>, /// Stores the type parameters which were substituted to obtain the type /// of this node. This only applies to nodes that refer to entities @@ -854,6 +854,13 @@ pub struct ctxt<'tcx> { pub const_qualif_map: RefCell>, } +impl<'tcx> ctxt<'tcx> { + pub fn node_types(&self) -> Ref>> { self.node_types.borrow() } + pub fn node_type_insert(&self, id: NodeId, ty: Ty<'tcx>) { + self.node_types.borrow_mut().insert(id, ty); + } +} + // Flags that we track on types. These flags are propagated upwards // through the type during type construction, so that we can quickly // check whether the type has various kinds of types in it without diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index a415875d852c..26fcf947e4f9 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -272,7 +272,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { let typ = ppaux::ty_to_string( &self.analysis.ty_cx, - *self.analysis.ty_cx.node_types.borrow().get(&id).unwrap()); + *self.analysis.ty_cx.node_types().get(&id).unwrap()); // get the span only for the name of the variable (I hope the path is only ever a // variable name, but who knows?) self.fmt.formal_str(p.span, @@ -436,7 +436,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { let typ = ppaux::ty_to_string( &self.analysis.ty_cx, - *self.analysis.ty_cx.node_types.borrow().get(&field.node.id).unwrap()); + *self.analysis.ty_cx.node_types().get(&field.node.id).unwrap()); match self.span.sub_span_before_token(field.span, token::Colon) { Some(sub_span) => self.fmt.field_str(field.span, Some(sub_span), @@ -1471,7 +1471,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { for &(id, ref p, ref immut, _) in &self.collected_paths { let value = if *immut { value.to_string() } else { "".to_string() }; - let types = self.analysis.ty_cx.node_types.borrow(); + let types = self.analysis.ty_cx.node_types(); let typ = ppaux::ty_to_string(&self.analysis.ty_cx, *types.get(&id).unwrap()); // Get the span only for the name of the variable (I hope the path // is only ever a variable name, but who knows?). diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index f2c24501c66c..8e9ae2eba0bc 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -3207,7 +3207,7 @@ fn fn_should_be_ignored(fcx: &FunctionContext) -> bool { fn assert_type_for_node_id(cx: &CrateContext, node_id: ast::NodeId, error_reporting_span: Span) { - if !cx.tcx().node_types.borrow().contains_key(&node_id) { + if !cx.tcx().node_types().contains_key(&node_id) { cx.sess().span_bug(error_reporting_span, "debuginfo: Could not find type for node id!"); } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 91410fa808c7..9d6c04b1ad49 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -146,7 +146,7 @@ pub struct CrateCtxt<'a, 'tcx: 'a> { fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) { debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_string(tcx, ty)); assert!(!ty::type_needs_infer(ty)); - tcx.node_types.borrow_mut().insert(node_id, ty); + tcx.node_type_insert(node_id, ty); } fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,