librustc: De-`@mut` `inherent_candidates` and `extension_candidates` in

method lookup
This commit is contained in:
Patrick Walton 2013-12-22 14:12:45 -08:00
parent 1a6c1e5d32
commit 0afae85bc2
1 changed files with 23 additions and 15 deletions

View File

@ -142,8 +142,8 @@ pub fn lookup(
m_name: m_name,
supplied_tps: supplied_tps,
impl_dups: impl_dups,
inherent_candidates: @mut ~[],
extension_candidates: @mut ~[],
inherent_candidates: @RefCell::new(~[]),
extension_candidates: @RefCell::new(~[]),
deref_args: deref_args,
check_traits: check_traits,
autoderef_receiver: autoderef_receiver,
@ -176,8 +176,8 @@ pub struct LookupContext<'a> {
m_name: ast::Name,
supplied_tps: &'a [ty::t],
impl_dups: @RefCell<HashSet<DefId>>,
inherent_candidates: @mut ~[Candidate],
extension_candidates: @mut ~[Candidate],
inherent_candidates: @RefCell<~[Candidate]>,
extension_candidates: @RefCell<~[Candidate]>,
deref_args: check::DerefArgs,
check_traits: CheckTraitsFlag,
autoderef_receiver: AutoderefReceiverFlag,
@ -279,8 +279,8 @@ impl<'a> LookupContext<'a> {
// Candidate collection (see comment at start of file)
fn reset_candidates(&self) {
*self.inherent_candidates = ~[];
*self.extension_candidates = ~[];
self.inherent_candidates.set(~[]);
self.extension_candidates.set(~[]);
}
fn push_inherent_candidates(&self, self_ty: ty::t) {
@ -358,8 +358,10 @@ impl<'a> LookupContext<'a> {
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 mut extension_candidates =
self.extension_candidates.borrow_mut();
self.push_candidates_from_impl(
self.extension_candidates, *impl_info);
extension_candidates.get(), *impl_info);
}
}
@ -511,7 +513,9 @@ impl<'a> LookupContext<'a> {
pos, this_bound_idx);
debug!("pushing inherent candidate for param: {:?}", cand);
self.inherent_candidates.push(cand);
let mut inherent_candidates = self.inherent_candidates
.borrow_mut();
inherent_candidates.get().push(cand);
}
None => {
debug!("trait doesn't contain method: {:?}",
@ -533,8 +537,10 @@ impl<'a> LookupContext<'a> {
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(
self.inherent_candidates, *impl_info);
let mut inherent_candidates = self.inherent_candidates
.borrow_mut();
self.push_candidates_from_impl(inherent_candidates.get(),
*impl_info);
}
}
}
@ -828,7 +834,8 @@ impl<'a> LookupContext<'a> {
// existing code.
debug!("searching inherent candidates");
match self.consider_candidates(rcvr_ty, self.inherent_candidates) {
let mut inherent_candidates = self.inherent_candidates.borrow_mut();
match self.consider_candidates(rcvr_ty, inherent_candidates.get()) {
None => {}
Some(mme) => {
return Some(mme);
@ -836,7 +843,8 @@ impl<'a> LookupContext<'a> {
}
debug!("searching extension candidates");
match self.consider_candidates(rcvr_ty, self.extension_candidates) {
let mut extension_candidates = self.extension_candidates.borrow_mut();
match self.consider_candidates(rcvr_ty, extension_candidates.get()) {
None => {
return None;
}
@ -847,9 +855,9 @@ impl<'a> LookupContext<'a> {
}
fn consider_candidates(&self,
rcvr_ty: ty::t,
candidates: &mut ~[Candidate])
-> Option<method_map_entry> {
rcvr_ty: ty::t,
candidates: &mut ~[Candidate])
-> Option<method_map_entry> {
// XXX(pcwalton): Do we need to clone here?
let relevant_candidates: ~[Candidate] =
candidates.iter().map(|c| (*c).clone()).