Skip to content

Commit 4784611

Browse files
committed
librustc: Fully de-@mut trait_impls in the type context
1 parent fecef74 commit 4784611

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,8 @@ fn encode_extension_implementations(ecx: &EncodeContext,
903903
match trait_impls.get().find(&trait_def_id) {
904904
None => {}
905905
Some(&implementations) => {
906-
for implementation in implementations.iter() {
906+
let implementations = implementations.borrow();
907+
for implementation in implementations.get().iter() {
907908
ebml_w.start_tag(tag_items_data_item_extension_impl);
908909
encode_def_id(ebml_w, implementation.did);
909910
ebml_w.end_tag();

src/librustc/middle/ty.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ struct ctxt_ {
333333
destructors: RefCell<HashSet<ast::DefId>>,
334334

335335
// Maps a trait onto a list of impls of that trait.
336-
trait_impls: RefCell<HashMap<ast::DefId, @mut ~[@Impl]>>,
336+
trait_impls: RefCell<HashMap<ast::DefId, @RefCell<~[@Impl]>>>,
337337

338338
// Maps a def_id of a type to a list of its inherent impls.
339339
// Contains implementations of methods that are inherent to a type.
@@ -4507,15 +4507,16 @@ fn record_trait_implementation(tcx: ctxt,
45074507
let mut trait_impls = tcx.trait_impls.borrow_mut();
45084508
match trait_impls.get().find(&trait_def_id) {
45094509
None => {
4510-
implementation_list = @mut ~[];
4510+
implementation_list = @RefCell::new(~[]);
45114511
trait_impls.get().insert(trait_def_id, implementation_list);
45124512
}
45134513
Some(&existing_implementation_list) => {
45144514
implementation_list = existing_implementation_list
45154515
}
45164516
}
45174517

4518-
implementation_list.push(implementation);
4518+
let mut implementation_list = implementation_list.borrow_mut();
4519+
implementation_list.get().push(implementation);
45194520
}
45204521

45214522
/// Populates the type context with all the implementations for the given type

src/librustc/middle/typeck/check/method.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ impl<'a> LookupContext<'a> {
357357
let trait_impls = self.tcx().trait_impls.borrow();
358358
let opt_impl_infos = trait_impls.get().find(trait_did);
359359
for impl_infos in opt_impl_infos.iter() {
360-
for impl_info in impl_infos.iter() {
360+
let impl_infos = impl_infos.borrow();
361+
for impl_info in impl_infos.get().iter() {
361362
let mut extension_candidates =
362363
self.extension_candidates.borrow_mut();
363364
self.push_candidates_from_impl(

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use middle::subst::Subst;
2424
use util::common::indenter;
2525
use util::ppaux;
2626

27+
use std::cell::RefCell;
2728
use std::hashmap::HashSet;
2829
use std::result;
2930
use syntax::ast;
@@ -333,10 +334,11 @@ fn search_for_vtable(vcx: &VtableContext,
333334
let trait_impls = tcx.trait_impls.borrow();
334335
trait_impls.get()
335336
.find(&trait_ref.def_id)
336-
.map_default(@mut ~[], |x| *x)
337+
.map_default(@RefCell::new(~[]), |x| *x)
337338
};
338339
// impls is the list of all impls in scope for trait_ref.
339-
for im in impls.iter() {
340+
let impls = impls.borrow();
341+
for im in impls.get().iter() {
340342
// im is one specific impl of trait_ref.
341343

342344
// First, ensure we haven't processed this impl yet.

src/librustc/middle/typeck/coherence.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,16 @@ impl CoherenceChecker {
412412
let mut trait_impls = tcx.trait_impls.borrow_mut();
413413
match trait_impls.get().find(&base_def_id) {
414414
None => {
415-
implementation_list = @mut ~[];
415+
implementation_list = @RefCell::new(~[]);
416416
trait_impls.get().insert(base_def_id, implementation_list);
417417
}
418418
Some(&existing_implementation_list) => {
419419
implementation_list = existing_implementation_list;
420420
}
421421
}
422422

423-
implementation_list.push(implementation);
423+
let mut implementation_list = implementation_list.borrow_mut();
424+
implementation_list.get().push(implementation);
424425
}
425426

426427
pub fn check_implementation_coherence(&self) {
@@ -467,7 +468,8 @@ impl CoherenceChecker {
467468
let trait_impls = self.crate_context.tcx.trait_impls.borrow();
468469
match trait_impls.get().find(&trait_def_id) {
469470
Some(impls) => {
470-
for &im in impls.iter() {
471+
let impls = impls.borrow();
472+
for &im in impls.get().iter() {
471473
f(im);
472474
}
473475
}
@@ -708,7 +710,8 @@ impl CoherenceChecker {
708710
Some(found_impls) => impls = found_impls
709711
}
710712

711-
for impl_info in impls.iter() {
713+
let impls = impls.borrow();
714+
for impl_info in impls.get().iter() {
712715
if impl_info.methods.len() < 1 {
713716
// We'll error out later. For now, just don't ICE.
714717
continue;

0 commit comments

Comments
 (0)