From 47846110a469d7682189e75b3bfe35f9ff02a9aa Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 22 Dec 2013 16:36:47 -0800 Subject: [PATCH] librustc: Fully de-`@mut` `trait_impls` in the type context --- src/librustc/metadata/encoder.rs | 3 ++- src/librustc/middle/ty.rs | 7 ++++--- src/librustc/middle/typeck/check/method.rs | 3 ++- src/librustc/middle/typeck/check/vtable.rs | 6 ++++-- src/librustc/middle/typeck/coherence.rs | 11 +++++++---- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index b09b448e1fe0..961431ca11df 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -903,7 +903,8 @@ fn encode_extension_implementations(ecx: &EncodeContext, match trait_impls.get().find(&trait_def_id) { None => {} Some(&implementations) => { - for implementation in implementations.iter() { + let implementations = implementations.borrow(); + for implementation in implementations.get().iter() { ebml_w.start_tag(tag_items_data_item_extension_impl); encode_def_id(ebml_w, implementation.did); ebml_w.end_tag(); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index ff925305acf1..12e7439744b5 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -333,7 +333,7 @@ struct ctxt_ { destructors: RefCell>, // Maps a trait onto a list of impls of that trait. - trait_impls: RefCell>, + trait_impls: RefCell>>, // Maps a def_id of a type to a list of its inherent impls. // Contains implementations of methods that are inherent to a type. @@ -4507,7 +4507,7 @@ fn record_trait_implementation(tcx: ctxt, let mut trait_impls = tcx.trait_impls.borrow_mut(); match trait_impls.get().find(&trait_def_id) { None => { - implementation_list = @mut ~[]; + implementation_list = @RefCell::new(~[]); trait_impls.get().insert(trait_def_id, implementation_list); } Some(&existing_implementation_list) => { @@ -4515,7 +4515,8 @@ fn record_trait_implementation(tcx: ctxt, } } - implementation_list.push(implementation); + let mut implementation_list = implementation_list.borrow_mut(); + implementation_list.get().push(implementation); } /// Populates the type context with all the implementations for the given type diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 0f92cdaae63f..7fc2798c7aa6 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -357,7 +357,8 @@ impl<'a> LookupContext<'a> { let trait_impls = self.tcx().trait_impls.borrow(); let opt_impl_infos = trait_impls.get().find(trait_did); for impl_infos in opt_impl_infos.iter() { - for impl_info in impl_infos.iter() { + let impl_infos = impl_infos.borrow(); + for impl_info in impl_infos.get().iter() { let mut extension_candidates = self.extension_candidates.borrow_mut(); self.push_candidates_from_impl( diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a773a3a19757..212c37f4ed11 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -24,6 +24,7 @@ use middle::subst::Subst; use util::common::indenter; use util::ppaux; +use std::cell::RefCell; use std::hashmap::HashSet; use std::result; use syntax::ast; @@ -333,10 +334,11 @@ fn search_for_vtable(vcx: &VtableContext, let trait_impls = tcx.trait_impls.borrow(); trait_impls.get() .find(&trait_ref.def_id) - .map_default(@mut ~[], |x| *x) + .map_default(@RefCell::new(~[]), |x| *x) }; // impls is the list of all impls in scope for trait_ref. - for im in impls.iter() { + let impls = impls.borrow(); + for im in impls.get().iter() { // im is one specific impl of trait_ref. // First, ensure we haven't processed this impl yet. diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index b7e0e2078d93..d3cd6465edf2 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -412,7 +412,7 @@ impl CoherenceChecker { let mut trait_impls = tcx.trait_impls.borrow_mut(); match trait_impls.get().find(&base_def_id) { None => { - implementation_list = @mut ~[]; + implementation_list = @RefCell::new(~[]); trait_impls.get().insert(base_def_id, implementation_list); } Some(&existing_implementation_list) => { @@ -420,7 +420,8 @@ impl CoherenceChecker { } } - implementation_list.push(implementation); + let mut implementation_list = implementation_list.borrow_mut(); + implementation_list.get().push(implementation); } pub fn check_implementation_coherence(&self) { @@ -467,7 +468,8 @@ impl CoherenceChecker { let trait_impls = self.crate_context.tcx.trait_impls.borrow(); match trait_impls.get().find(&trait_def_id) { Some(impls) => { - for &im in impls.iter() { + let impls = impls.borrow(); + for &im in impls.get().iter() { f(im); } } @@ -708,7 +710,8 @@ impl CoherenceChecker { Some(found_impls) => impls = found_impls } - for impl_info in impls.iter() { + let impls = impls.borrow(); + for impl_info in impls.get().iter() { if impl_info.methods.len() < 1 { // We'll error out later. For now, just don't ICE. continue;