From 42f7f7f437ad978dd95d3ec39a0f231d6cd161da Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 19 Dec 2013 19:15:06 -0800 Subject: [PATCH] librustc: De-`@mut` `inherent_impls` in the type context --- src/librustc/metadata/encoder.rs | 6 ++++-- src/librustc/middle/dead.rs | 3 ++- src/librustc/middle/ty.rs | 9 +++++---- src/librustc/middle/typeck/check/method.rs | 3 ++- src/librustc/middle/typeck/coherence.rs | 5 +++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 35652e809c52..c04d7b1418fd 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -442,7 +442,8 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, exp: &middle::resolve::Export2) -> bool { - match ecx.tcx.inherent_impls.find(&exp.def_id) { + let inherent_impls = ecx.tcx.inherent_impls.borrow(); + match inherent_impls.get().find(&exp.def_id) { Some(implementations) => { for &base_impl in implementations.iter() { for &m in base_impl.methods.iter() { @@ -862,7 +863,8 @@ fn should_inline(attrs: &[Attribute]) -> bool { fn encode_inherent_implementations(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, def_id: DefId) { - match ecx.tcx.inherent_impls.find(&def_id) { + let inherent_impls = ecx.tcx.inherent_impls.borrow(); + match inherent_impls.get().find(&def_id) { None => {} Some(&implementations) => { for implementation in implementations.iter() { diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index fe4da4181da3..dd4f92212d3b 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -282,7 +282,8 @@ impl DeadVisitor { // method of a private type is used, but the type itself is never // called directly. let def_id = local_def(id); - match self.tcx.inherent_impls.find(&def_id) { + let inherent_impls = self.tcx.inherent_impls.borrow(); + match inherent_impls.get().find(&def_id) { None => (), Some(ref impl_list) => { for impl_ in impl_list.iter() { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index f3ba0feb37a9..976a4f3af68c 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -338,7 +338,7 @@ struct ctxt_ { // Maps a def_id of a type to a list of its inherent impls. // Contains implementations of methods that are inherent to a type. // Methods in these implementations don't need to be exported. - inherent_impls: @mut HashMap, + inherent_impls: RefCell>, // Maps a def_id of an impl to an Impl structure. // Note that this contains all of the impls that we know about, @@ -1006,7 +1006,7 @@ pub fn mk_ctxt(s: session::Session, destructor_for_type: RefCell::new(HashMap::new()), destructors: RefCell::new(HashSet::new()), trait_impls: RefCell::new(HashMap::new()), - inherent_impls: @mut HashMap::new(), + inherent_impls: RefCell::new(HashMap::new()), impls: @mut HashMap::new(), used_unsafe: @mut HashSet::new(), used_mut_nodes: @mut HashSet::new(), @@ -4549,10 +4549,11 @@ pub fn populate_implementations_for_type_if_necessary(tcx: ctxt, // If this is an inherent implementation, record it. if associated_traits.is_none() { let implementation_list; - match tcx.inherent_impls.find(&type_id) { + let mut inherent_impls = tcx.inherent_impls.borrow_mut(); + match inherent_impls.get().find(&type_id) { None => { implementation_list = @mut ~[]; - tcx.inherent_impls.insert(type_id, implementation_list); + inherent_impls.get().insert(type_id, implementation_list); } Some(&existing_implementation_list) => { implementation_list = existing_implementation_list; diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index f2222dba6977..2892ad62b736 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -527,7 +527,8 @@ impl<'a> LookupContext<'a> { // metadata if necessary. ty::populate_implementations_for_type_if_necessary(self.tcx(), did); - let opt_impl_infos = self.tcx().inherent_impls.find(&did); + let inherent_impls = self.tcx().inherent_impls.borrow(); + let opt_impl_infos = inherent_impls.get().find(&did); for impl_infos in opt_impl_infos.iter() { for impl_info in impl_infos.iter() { self.push_candidates_from_impl( diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index d9c053fa57e7..f4ffd03cf641 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -384,10 +384,11 @@ impl CoherenceChecker { implementation: @Impl) { let tcx = self.crate_context.tcx; let implementation_list; - match tcx.inherent_impls.find(&base_def_id) { + let mut inherent_impls = tcx.inherent_impls.borrow_mut(); + match inherent_impls.get().find(&base_def_id) { None => { implementation_list = @mut ~[]; - tcx.inherent_impls.insert(base_def_id, implementation_list); + inherent_impls.get().insert(base_def_id, implementation_list); } Some(&existing_implementation_list) => { implementation_list = existing_implementation_list;