提交 00ebebb2 编写于 作者: B bors

auto merge of #17654 : gereeter/rust/no-unnecessary-cell, r=alexcrichton

There is more that could be done, but this was the low hanging fruit.
...@@ -538,7 +538,7 @@ fn encode_reexports(ecx: &EncodeContext, ...@@ -538,7 +538,7 @@ fn encode_reexports(ecx: &EncodeContext,
id: NodeId, id: NodeId,
path: PathElems) { path: PathElems) {
debug!("(encoding info for module) encoding reexports for {}", id); debug!("(encoding info for module) encoding reexports for {}", id);
match ecx.reexports2.borrow().find(&id) { match ecx.reexports2.find(&id) {
Some(ref exports) => { Some(ref exports) => {
debug!("(encoding info for module) found reexports for {}", id); debug!("(encoding info for module) found reexports for {}", id);
for exp in exports.iter() { for exp in exports.iter() {
......
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
...@@ -347,9 +347,8 @@ fn visit_mod(&mut self, m: &ast::Mod, _sp: Span, id: ast::NodeId) { ...@@ -347,9 +347,8 @@ fn visit_mod(&mut self, m: &ast::Mod, _sp: Span, id: ast::NodeId) {
// This code is here instead of in visit_item so that the // This code is here instead of in visit_item so that the
// crate module gets processed as well. // crate module gets processed as well.
if self.prev_exported { if self.prev_exported {
let exp_map2 = self.exp_map2.borrow(); assert!(self.exp_map2.contains_key(&id), "wut {:?}", id);
assert!(exp_map2.contains_key(&id), "wut {:?}", id); for export in self.exp_map2.get(&id).iter() {
for export in exp_map2.get(&id).iter() {
if is_local(export.def_id) { if is_local(export.def_id) {
self.reexports.insert(export.def_id.node); self.reexports.insert(export.def_id.node);
} }
......
...@@ -81,7 +81,7 @@ struct binding_info { ...@@ -81,7 +81,7 @@ struct binding_info {
// This is the replacement export map. It maps a module to all of the exports // This is the replacement export map. It maps a module to all of the exports
// within. // within.
pub type ExportMap2 = RefCell<NodeMap<Vec<Export2> >>; pub type ExportMap2 = NodeMap<Vec<Export2>>;
pub struct Export2 { pub struct Export2 {
pub name: String, // The name of the target. pub name: String, // The name of the target.
...@@ -360,14 +360,14 @@ enum DuplicateCheckingMode { ...@@ -360,14 +360,14 @@ enum DuplicateCheckingMode {
/// One local scope. /// One local scope.
struct Rib { struct Rib {
bindings: RefCell<HashMap<Name, DefLike>>, bindings: HashMap<Name, DefLike>,
kind: RibKind, kind: RibKind,
} }
impl Rib { impl Rib {
fn new(kind: RibKind) -> Rib { fn new(kind: RibKind) -> Rib {
Rib { Rib {
bindings: RefCell::new(HashMap::new()), bindings: HashMap::new(),
kind: kind kind: kind
} }
} }
...@@ -856,7 +856,7 @@ struct Resolver<'a> { ...@@ -856,7 +856,7 @@ struct Resolver<'a> {
graph_root: NameBindings, graph_root: NameBindings,
trait_item_map: RefCell<FnvHashMap<(Name, DefId), TraitItemKind>>, trait_item_map: FnvHashMap<(Name, DefId), TraitItemKind>,
structs: FnvHashMap<DefId, Vec<Name>>, structs: FnvHashMap<DefId, Vec<Name>>,
...@@ -868,13 +868,13 @@ struct Resolver<'a> { ...@@ -868,13 +868,13 @@ struct Resolver<'a> {
// The current set of local scopes, for values. // The current set of local scopes, for values.
// FIXME #4948: Reuse ribs to avoid allocation. // FIXME #4948: Reuse ribs to avoid allocation.
value_ribs: RefCell<Vec<Rib>>, value_ribs: Vec<Rib>,
// The current set of local scopes, for types. // The current set of local scopes, for types.
type_ribs: RefCell<Vec<Rib>>, type_ribs: Vec<Rib>,
// The current set of local scopes, for labels. // The current set of local scopes, for labels.
label_ribs: RefCell<Vec<Rib>>, label_ribs: Vec<Rib>,
// The trait that the current context can refer to. // The trait that the current context can refer to.
current_trait_ref: Option<(DefId, TraitRef)>, current_trait_ref: Option<(DefId, TraitRef)>,
...@@ -893,7 +893,7 @@ struct Resolver<'a> { ...@@ -893,7 +893,7 @@ struct Resolver<'a> {
def_map: DefMap, def_map: DefMap,
freevars: RefCell<FreevarMap>, freevars: RefCell<FreevarMap>,
freevars_seen: RefCell<NodeMap<NodeSet>>, freevars_seen: RefCell<NodeMap<NodeSet>>,
capture_mode_map: RefCell<CaptureModeMap>, capture_mode_map: CaptureModeMap,
export_map2: ExportMap2, export_map2: ExportMap2,
trait_map: TraitMap, trait_map: TraitMap,
external_exports: ExternalExports, external_exports: ExternalExports,
...@@ -980,15 +980,15 @@ fn new(session: &'a Session, crate_span: Span) -> Resolver<'a> { ...@@ -980,15 +980,15 @@ fn new(session: &'a Session, crate_span: Span) -> Resolver<'a> {
graph_root: graph_root, graph_root: graph_root,
trait_item_map: RefCell::new(FnvHashMap::new()), trait_item_map: FnvHashMap::new(),
structs: FnvHashMap::new(), structs: FnvHashMap::new(),
unresolved_imports: 0, unresolved_imports: 0,
current_module: current_module, current_module: current_module,
value_ribs: RefCell::new(Vec::new()), value_ribs: Vec::new(),
type_ribs: RefCell::new(Vec::new()), type_ribs: Vec::new(),
label_ribs: RefCell::new(Vec::new()), label_ribs: Vec::new(),
current_trait_ref: None, current_trait_ref: None,
current_self_type: None, current_self_type: None,
...@@ -1001,8 +1001,8 @@ fn new(session: &'a Session, crate_span: Span) -> Resolver<'a> { ...@@ -1001,8 +1001,8 @@ fn new(session: &'a Session, crate_span: Span) -> Resolver<'a> {
def_map: RefCell::new(NodeMap::new()), def_map: RefCell::new(NodeMap::new()),
freevars: RefCell::new(NodeMap::new()), freevars: RefCell::new(NodeMap::new()),
freevars_seen: RefCell::new(NodeMap::new()), freevars_seen: RefCell::new(NodeMap::new()),
capture_mode_map: RefCell::new(NodeMap::new()), capture_mode_map: NodeMap::new(),
export_map2: RefCell::new(NodeMap::new()), export_map2: NodeMap::new(),
trait_map: NodeMap::new(), trait_map: NodeMap::new(),
used_imports: HashSet::new(), used_imports: HashSet::new(),
used_crates: HashSet::new(), used_crates: HashSet::new(),
...@@ -1516,9 +1516,7 @@ fn build_reduced_graph_for_item(&mut self, ...@@ -1516,9 +1516,7 @@ fn build_reduced_graph_for_item(&mut self,
} }
}; };
self.trait_item_map self.trait_item_map.insert((ident.name, def_id), kind);
.borrow_mut()
.insert((ident.name, def_id), kind);
} }
name_bindings.define_type(DefTrait(def_id), sp, is_public); name_bindings.define_type(DefTrait(def_id), sp, is_public);
...@@ -1850,10 +1848,7 @@ fn handle_external_def(&mut self, ...@@ -1850,10 +1848,7 @@ fn handle_external_def(&mut self,
adding trait item '{}'", adding trait item '{}'",
token::get_ident(trait_item_name)); token::get_ident(trait_item_name));
self.trait_item_map self.trait_item_map.insert((trait_item_name.name, def_id), trait_item_kind);
.borrow_mut()
.insert((trait_item_name.name, def_id),
trait_item_kind);
if is_exported { if is_exported {
self.external_exports self.external_exports
...@@ -3760,7 +3755,7 @@ fn record_exports_for_module(&mut self, module_: &Module) { ...@@ -3760,7 +3755,7 @@ fn record_exports_for_module(&mut self, module_: &Module) {
self.add_exports_for_module(&mut exports2, module_); self.add_exports_for_module(&mut exports2, module_);
match module_.def_id.get() { match module_.def_id.get() {
Some(def_id) => { Some(def_id) => {
self.export_map2.borrow_mut().insert(def_id.node, exports2); self.export_map2.insert(def_id.node, exports2);
debug!("(computing exports) writing exports for {} (some)", debug!("(computing exports) writing exports for {} (some)",
def_id.node); def_id.node);
} }
...@@ -4017,7 +4012,7 @@ fn search_ribs(&self, ...@@ -4017,7 +4012,7 @@ fn search_ribs(&self,
// FIXME #4950: Try caching? // FIXME #4950: Try caching?
for (i, rib) in ribs.iter().enumerate().rev() { for (i, rib) in ribs.iter().enumerate().rev() {
match rib.bindings.borrow().find_copy(&name) { match rib.bindings.find_copy(&name) {
Some(def_like) => { Some(def_like) => {
return self.upvarify(ribs.slice_from(i + 1), def_like, span); return self.upvarify(ribs.slice_from(i + 1), def_like, span);
} }
...@@ -4093,13 +4088,12 @@ fn resolve_item(&mut self, item: &Item) { ...@@ -4093,13 +4088,12 @@ fn resolve_item(&mut self, item: &Item) {
ItemTrait(ref generics, ref unbound, ref bounds, ref methods) => { ItemTrait(ref generics, ref unbound, ref bounds, ref methods) => {
// Create a new rib for the self type. // Create a new rib for the self type.
let self_type_rib = Rib::new(ItemRibKind); let mut self_type_rib = Rib::new(ItemRibKind);
// plain insert (no renaming, types are not currently hygienic....) // plain insert (no renaming, types are not currently hygienic....)
let name = self.type_self_name; let name = self.type_self_name;
self_type_rib.bindings.borrow_mut() self_type_rib.bindings.insert(name, DlDef(DefSelfTy(item.id)));
.insert(name, DlDef(DefSelfTy(item.id))); self.type_ribs.push(self_type_rib);
self.type_ribs.borrow_mut().push(self_type_rib);
// Create a new rib for the trait-wide type parameters. // Create a new rib for the trait-wide type parameters.
self.with_type_parameter_rib(HasTypeParameters(generics, self.with_type_parameter_rib(HasTypeParameters(generics,
...@@ -4168,7 +4162,7 @@ fn resolve_item(&mut self, item: &Item) { ...@@ -4168,7 +4162,7 @@ fn resolve_item(&mut self, item: &Item) {
} }
}); });
self.type_ribs.borrow_mut().pop(); self.type_ribs.pop();
} }
ItemStruct(ref struct_def, ref generics) => { ItemStruct(ref struct_def, ref generics) => {
...@@ -4236,7 +4230,7 @@ fn with_type_parameter_rib(&mut self, ...@@ -4236,7 +4230,7 @@ fn with_type_parameter_rib(&mut self,
HasTypeParameters(generics, space, node_id, HasTypeParameters(generics, space, node_id,
rib_kind) => { rib_kind) => {
let function_type_rib = Rib::new(rib_kind); let mut function_type_rib = Rib::new(rib_kind);
for (index, type_parameter) in generics.ty_params.iter().enumerate() { for (index, type_parameter) in generics.ty_params.iter().enumerate() {
let ident = type_parameter.ident; let ident = type_parameter.ident;
...@@ -4250,10 +4244,9 @@ fn with_type_parameter_rib(&mut self, ...@@ -4250,10 +4244,9 @@ fn with_type_parameter_rib(&mut self,
self.record_def(type_parameter.id, self.record_def(type_parameter.id,
(DefTyParamBinder(node_id), LastMod(AllPublic))); (DefTyParamBinder(node_id), LastMod(AllPublic)));
// plain insert (no renaming) // plain insert (no renaming)
function_type_rib.bindings.borrow_mut() function_type_rib.bindings.insert(ident.name, def_like);
.insert(ident.name, def_like);
} }
self.type_ribs.borrow_mut().push(function_type_rib); self.type_ribs.push(function_type_rib);
} }
NoTypeParameters => { NoTypeParameters => {
...@@ -4264,23 +4257,23 @@ fn with_type_parameter_rib(&mut self, ...@@ -4264,23 +4257,23 @@ fn with_type_parameter_rib(&mut self,
f(self); f(self);
match type_parameters { match type_parameters {
HasTypeParameters(..) => { self.type_ribs.borrow_mut().pop(); } HasTypeParameters(..) => { self.type_ribs.pop(); }
NoTypeParameters => { } NoTypeParameters => { }
} }
} }
fn with_label_rib(&mut self, f: |&mut Resolver|) { fn with_label_rib(&mut self, f: |&mut Resolver|) {
self.label_ribs.borrow_mut().push(Rib::new(NormalRibKind)); self.label_ribs.push(Rib::new(NormalRibKind));
f(self); f(self);
self.label_ribs.borrow_mut().pop(); self.label_ribs.pop();
} }
fn with_constant_rib(&mut self, f: |&mut Resolver|) { fn with_constant_rib(&mut self, f: |&mut Resolver|) {
self.value_ribs.borrow_mut().push(Rib::new(ConstantItemRibKind)); self.value_ribs.push(Rib::new(ConstantItemRibKind));
self.type_ribs.borrow_mut().push(Rib::new(ConstantItemRibKind)); self.type_ribs.push(Rib::new(ConstantItemRibKind));
f(self); f(self);
self.type_ribs.borrow_mut().pop(); self.type_ribs.pop();
self.value_ribs.borrow_mut().pop(); self.value_ribs.pop();
} }
fn resolve_function(&mut self, fn resolve_function(&mut self,
...@@ -4290,11 +4283,11 @@ fn resolve_function(&mut self, ...@@ -4290,11 +4283,11 @@ fn resolve_function(&mut self,
block: &Block) { block: &Block) {
// Create a value rib for the function. // Create a value rib for the function.
let function_value_rib = Rib::new(rib_kind); let function_value_rib = Rib::new(rib_kind);
self.value_ribs.borrow_mut().push(function_value_rib); self.value_ribs.push(function_value_rib);
// Create a label rib for the function. // Create a label rib for the function.
let function_label_rib = Rib::new(rib_kind); let function_label_rib = Rib::new(rib_kind);
self.label_ribs.borrow_mut().push(function_label_rib); self.label_ribs.push(function_label_rib);
// If this function has type parameters, add them now. // If this function has type parameters, add them now.
self.with_type_parameter_rib(type_parameters, |this| { self.with_type_parameter_rib(type_parameters, |this| {
...@@ -4336,8 +4329,8 @@ fn resolve_function(&mut self, ...@@ -4336,8 +4329,8 @@ fn resolve_function(&mut self,
debug!("(resolving function) leaving function"); debug!("(resolving function) leaving function");
}); });
self.label_ribs.borrow_mut().pop(); self.label_ribs.pop();
self.value_ribs.borrow_mut().pop(); self.value_ribs.pop();
} }
fn resolve_type_parameters(&mut self, fn resolve_type_parameters(&mut self,
...@@ -4680,7 +4673,7 @@ fn check_trait_item(&self, ident: Ident, span: Span) { ...@@ -4680,7 +4673,7 @@ fn check_trait_item(&self, ident: Ident, span: Span) {
for &(did, ref trait_ref) in self.current_trait_ref.iter() { for &(did, ref trait_ref) in self.current_trait_ref.iter() {
let method_name = ident.name; let method_name = ident.name;
if self.trait_item_map.borrow().find(&(method_name, did)).is_none() { if self.trait_item_map.find(&(method_name, did)).is_none() {
let path_str = self.path_idents_to_string(&trait_ref.path); let path_str = self.path_idents_to_string(&trait_ref.path);
self.resolve_error(span, self.resolve_error(span,
format!("method `{}` is not a member of trait `{}`", format!("method `{}` is not a member of trait `{}`",
...@@ -4780,7 +4773,7 @@ fn check_consistent_bindings(&mut self, arm: &Arm) { ...@@ -4780,7 +4773,7 @@ fn check_consistent_bindings(&mut self, arm: &Arm) {
} }
fn resolve_arm(&mut self, arm: &Arm) { fn resolve_arm(&mut self, arm: &Arm) {
self.value_ribs.borrow_mut().push(Rib::new(NormalRibKind)); self.value_ribs.push(Rib::new(NormalRibKind));
let mut bindings_list = HashMap::new(); let mut bindings_list = HashMap::new();
for pattern in arm.pats.iter() { for pattern in arm.pats.iter() {
...@@ -4794,12 +4787,12 @@ fn resolve_arm(&mut self, arm: &Arm) { ...@@ -4794,12 +4787,12 @@ fn resolve_arm(&mut self, arm: &Arm) {
visit::walk_expr_opt(self, &arm.guard); visit::walk_expr_opt(self, &arm.guard);
self.resolve_expr(&*arm.body); self.resolve_expr(&*arm.body);
self.value_ribs.borrow_mut().pop(); self.value_ribs.pop();
} }
fn resolve_block(&mut self, block: &Block) { fn resolve_block(&mut self, block: &Block) {
debug!("(resolving block) entering block"); debug!("(resolving block) entering block");
self.value_ribs.borrow_mut().push(Rib::new(NormalRibKind)); self.value_ribs.push(Rib::new(NormalRibKind));
// Move down in the graph, if there's an anonymous module rooted here. // Move down in the graph, if there's an anonymous module rooted here.
let orig_module = self.current_module.clone(); let orig_module = self.current_module.clone();
...@@ -4818,7 +4811,7 @@ fn resolve_block(&mut self, block: &Block) { ...@@ -4818,7 +4811,7 @@ fn resolve_block(&mut self, block: &Block) {
// Move back up. // Move back up.
self.current_module = orig_module; self.current_module = orig_module;
self.value_ribs.borrow_mut().pop(); self.value_ribs.pop();
debug!("(resolving block) leaving block"); debug!("(resolving block) leaving block");
} }
...@@ -5061,12 +5054,8 @@ struct or enum variant", ...@@ -5061,12 +5054,8 @@ struct or enum variant",
if !bindings_list.contains_key(&renamed) { if !bindings_list.contains_key(&renamed) {
let this = &mut *self; let this = &mut *self;
let value_ribs = this.value_ribs.borrow(); let last_rib = this.value_ribs.last_mut().unwrap();
let length = value_ribs.len(); last_rib.bindings.insert(renamed, DlDef(def));
let last_rib = value_ribs.get(
length - 1);
last_rib.bindings.borrow_mut()
.insert(renamed, DlDef(def));
bindings_list.insert(renamed, pat_id); bindings_list.insert(renamed, pat_id);
} else if bindings_list.find(&renamed) == } else if bindings_list.find(&renamed) ==
Some(&pat_id) { Some(&pat_id) {
...@@ -5416,7 +5405,7 @@ fn resolve_module_relative_path(&mut self, ...@@ -5416,7 +5405,7 @@ fn resolve_module_relative_path(&mut self,
TraitModuleKind | ImplModuleKind => { TraitModuleKind | ImplModuleKind => {
match containing_module.def_id.get() { match containing_module.def_id.get() {
Some(def_id) => { Some(def_id) => {
match self.trait_item_map.borrow().find(&(ident.name, def_id)) { match self.trait_item_map.find(&(ident.name, def_id)) {
Some(&StaticMethodTraitItemKind) => (), Some(&StaticMethodTraitItemKind) => (),
Some(&TypeTraitItemKind) => (), Some(&TypeTraitItemKind) => (),
None => (), None => (),
...@@ -5508,12 +5497,12 @@ fn resolve_identifier_in_local_ribs(&mut self, ...@@ -5508,12 +5497,12 @@ fn resolve_identifier_in_local_ribs(&mut self,
let search_result = match namespace { let search_result = match namespace {
ValueNS => { ValueNS => {
let renamed = mtwt::resolve(ident); let renamed = mtwt::resolve(ident);
self.search_ribs(self.value_ribs.borrow().as_slice(), self.search_ribs(self.value_ribs.as_slice(),
renamed, span) renamed, span)
} }
TypeNS => { TypeNS => {
let name = ident.name; let name = ident.name;
self.search_ribs(self.type_ribs.borrow().as_slice(), name, span) self.search_ribs(self.type_ribs.as_slice(), name, span)
} }
}; };
...@@ -5688,12 +5677,11 @@ fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident]) ...@@ -5688,12 +5677,11 @@ fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident])
} }
// Look for a method in the current trait. // Look for a method in the current trait.
let trait_item_map = self.trait_item_map.borrow();
match self.current_trait_ref { match self.current_trait_ref {
Some((did, ref trait_ref)) => { Some((did, ref trait_ref)) => {
let path_str = self.path_idents_to_string(&trait_ref.path); let path_str = self.path_idents_to_string(&trait_ref.path);
match trait_item_map.find(&(name, did)) { match self.trait_item_map.find(&(name, did)) {
Some(&StaticMethodTraitItemKind) => return StaticTraitMethod(path_str), Some(&StaticMethodTraitItemKind) => return StaticTraitMethod(path_str),
Some(_) => return TraitItem, Some(_) => return TraitItem,
None => {} None => {}
...@@ -5712,12 +5700,8 @@ fn find_best_match_for_name(&mut self, name: &str, max_distance: uint) ...@@ -5712,12 +5700,8 @@ fn find_best_match_for_name(&mut self, name: &str, max_distance: uint)
let mut maybes: Vec<token::InternedString> = Vec::new(); let mut maybes: Vec<token::InternedString> = Vec::new();
let mut values: Vec<uint> = Vec::new(); let mut values: Vec<uint> = Vec::new();
let mut j = this.value_ribs.borrow().len(); for rib in this.value_ribs.iter().rev() {
while j != 0 { for (&k, _) in rib.bindings.iter() {
j -= 1;
let value_ribs = this.value_ribs.borrow();
let bindings = value_ribs.get(j).bindings.borrow();
for (&k, _) in bindings.iter() {
maybes.push(token::get_name(k)); maybes.push(token::get_name(k));
values.push(uint::MAX); values.push(uint::MAX);
} }
...@@ -5807,7 +5791,7 @@ fn resolve_expr(&mut self, expr: &Expr) { ...@@ -5807,7 +5791,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
} }
_ => { _ => {
let mut method_scope = false; let mut method_scope = false;
self.value_ribs.borrow().iter().rev().all(|rib| { self.value_ribs.iter().rev().all(|rib| {
let res = match *rib { let res = match *rib {
Rib { bindings: _, kind: MethodRibKind(_, _) } => true, Rib { bindings: _, kind: MethodRibKind(_, _) } => true,
Rib { bindings: _, kind: ItemRibKind } => false, Rib { bindings: _, kind: ItemRibKind } => false,
...@@ -5866,20 +5850,20 @@ fn resolve_expr(&mut self, expr: &Expr) { ...@@ -5866,20 +5850,20 @@ fn resolve_expr(&mut self, expr: &Expr) {
ExprFnBlock(_, ref fn_decl, ref block) => { ExprFnBlock(_, ref fn_decl, ref block) => {
// NOTE(stage0): After snapshot, change to: // NOTE(stage0): After snapshot, change to:
// //
//self.capture_mode_map.borrow_mut().insert(expr.id, capture_clause); //self.capture_mode_map.insert(expr.id, capture_clause);
self.capture_mode_map.borrow_mut().insert(expr.id, ast::CaptureByRef); self.capture_mode_map.insert(expr.id, ast::CaptureByRef);
self.resolve_function(ClosureRibKind(expr.id, ast::DUMMY_NODE_ID), self.resolve_function(ClosureRibKind(expr.id, ast::DUMMY_NODE_ID),
Some(&**fn_decl), NoTypeParameters, Some(&**fn_decl), NoTypeParameters,
&**block); &**block);
} }
ExprProc(ref fn_decl, ref block) => { ExprProc(ref fn_decl, ref block) => {
self.capture_mode_map.borrow_mut().insert(expr.id, ast::CaptureByValue); self.capture_mode_map.insert(expr.id, ast::CaptureByValue);
self.resolve_function(ClosureRibKind(expr.id, block.id), self.resolve_function(ClosureRibKind(expr.id, block.id),
Some(&**fn_decl), NoTypeParameters, Some(&**fn_decl), NoTypeParameters,
&**block); &**block);
} }
ExprUnboxedFn(capture_clause, _, ref fn_decl, ref block) => { ExprUnboxedFn(capture_clause, _, ref fn_decl, ref block) => {
self.capture_mode_map.borrow_mut().insert(expr.id, capture_clause); self.capture_mode_map.insert(expr.id, capture_clause);
self.resolve_function(ClosureRibKind(expr.id, block.id), self.resolve_function(ClosureRibKind(expr.id, block.id),
Some(&**fn_decl), NoTypeParameters, Some(&**fn_decl), NoTypeParameters,
&**block); &**block);
...@@ -5908,11 +5892,9 @@ fn resolve_expr(&mut self, expr: &Expr) { ...@@ -5908,11 +5892,9 @@ fn resolve_expr(&mut self, expr: &Expr) {
let def_like = DlDef(DefLabel(expr.id)); let def_like = DlDef(DefLabel(expr.id));
{ {
let label_ribs = this.label_ribs.borrow(); let rib = this.label_ribs.last_mut().unwrap();
let length = label_ribs.len();
let rib = label_ribs.get(length - 1);
let renamed = mtwt::resolve(label); let renamed = mtwt::resolve(label);
rib.bindings.borrow_mut().insert(renamed, def_like); rib.bindings.insert(renamed, def_like);
} }
visit::walk_expr(this, expr); visit::walk_expr(this, expr);
...@@ -5922,7 +5904,7 @@ fn resolve_expr(&mut self, expr: &Expr) { ...@@ -5922,7 +5904,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
ExprForLoop(ref pattern, ref head, ref body, optional_label) => { ExprForLoop(ref pattern, ref head, ref body, optional_label) => {
self.resolve_expr(&**head); self.resolve_expr(&**head);
self.value_ribs.borrow_mut().push(Rib::new(NormalRibKind)); self.value_ribs.push(Rib::new(NormalRibKind));
self.resolve_pattern(&**pattern, self.resolve_pattern(&**pattern,
LocalIrrefutableMode, LocalIrrefutableMode,
...@@ -5932,17 +5914,13 @@ fn resolve_expr(&mut self, expr: &Expr) { ...@@ -5932,17 +5914,13 @@ fn resolve_expr(&mut self, expr: &Expr) {
None => {} None => {}
Some(label) => { Some(label) => {
self.label_ribs self.label_ribs
.borrow_mut()
.push(Rib::new(NormalRibKind)); .push(Rib::new(NormalRibKind));
let def_like = DlDef(DefLabel(expr.id)); let def_like = DlDef(DefLabel(expr.id));
{ {
let label_ribs = self.label_ribs.borrow(); let rib = self.label_ribs.last_mut().unwrap();
let length = label_ribs.len();
let rib = label_ribs.get(length - 1);
let renamed = mtwt::resolve(label); let renamed = mtwt::resolve(label);
rib.bindings.borrow_mut().insert(renamed, rib.bindings.insert(renamed, def_like);
def_like);
} }
} }
} }
...@@ -5950,15 +5928,15 @@ fn resolve_expr(&mut self, expr: &Expr) { ...@@ -5950,15 +5928,15 @@ fn resolve_expr(&mut self, expr: &Expr) {
self.resolve_block(&**body); self.resolve_block(&**body);
if optional_label.is_some() { if optional_label.is_some() {
drop(self.label_ribs.borrow_mut().pop()) drop(self.label_ribs.pop())
} }
self.value_ribs.borrow_mut().pop(); self.value_ribs.pop();
} }
ExprBreak(Some(label)) | ExprAgain(Some(label)) => { ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
let renamed = mtwt::resolve(label); let renamed = mtwt::resolve(label);
match self.search_ribs(self.label_ribs.borrow().as_slice(), match self.search_ribs(self.label_ribs.as_slice(),
renamed, expr.span) { renamed, expr.span) {
None => { None => {
self.resolve_error( self.resolve_error(
...@@ -6027,9 +6005,7 @@ fn add_trait_info(found_traits: &mut Vec<DefId>, ...@@ -6027,9 +6005,7 @@ fn add_trait_info(found_traits: &mut Vec<DefId>,
// Look for the current trait. // Look for the current trait.
match self.current_trait_ref { match self.current_trait_ref {
Some((trait_def_id, _)) => { Some((trait_def_id, _)) => {
let trait_item_map = self.trait_item_map.borrow(); if self.trait_item_map.contains_key(&(name, trait_def_id)) {
if trait_item_map.contains_key(&(name, trait_def_id)) {
add_trait_info(&mut found_traits, trait_def_id, name); add_trait_info(&mut found_traits, trait_def_id, name);
} }
} }
...@@ -6040,7 +6016,6 @@ fn add_trait_info(found_traits: &mut Vec<DefId>, ...@@ -6040,7 +6016,6 @@ fn add_trait_info(found_traits: &mut Vec<DefId>,
self.populate_module_if_necessary(&search_module); self.populate_module_if_necessary(&search_module);
{ {
let trait_item_map = self.trait_item_map.borrow();
for (_, child_names) in search_module.children.borrow().iter() { for (_, child_names) in search_module.children.borrow().iter() {
let def = match child_names.def_for_namespace(TypeNS) { let def = match child_names.def_for_namespace(TypeNS) {
Some(def) => def, Some(def) => def,
...@@ -6050,7 +6025,7 @@ fn add_trait_info(found_traits: &mut Vec<DefId>, ...@@ -6050,7 +6025,7 @@ fn add_trait_info(found_traits: &mut Vec<DefId>,
DefTrait(trait_def_id) => trait_def_id, DefTrait(trait_def_id) => trait_def_id,
_ => continue, _ => continue,
}; };
if trait_item_map.contains_key(&(name, trait_def_id)) { if self.trait_item_map.contains_key(&(name, trait_def_id)) {
add_trait_info(&mut found_traits, trait_def_id, name); add_trait_info(&mut found_traits, trait_def_id, name);
} }
} }
...@@ -6066,7 +6041,7 @@ fn add_trait_info(found_traits: &mut Vec<DefId>, ...@@ -6066,7 +6041,7 @@ fn add_trait_info(found_traits: &mut Vec<DefId>,
Some(DefTrait(trait_def_id)) => trait_def_id, Some(DefTrait(trait_def_id)) => trait_def_id,
Some(..) | None => continue, Some(..) | None => continue,
}; };
if self.trait_item_map.borrow().contains_key(&(name, did)) { if self.trait_item_map.contains_key(&(name, did)) {
add_trait_info(&mut found_traits, did, name); add_trait_info(&mut found_traits, did, name);
self.used_imports.insert((import.type_id, TypeNS)); self.used_imports.insert((import.type_id, TypeNS));
match target.target_module.def_id.get() { match target.target_module.def_id.get() {
...@@ -6331,7 +6306,7 @@ pub fn resolve_crate(session: &Session, ...@@ -6331,7 +6306,7 @@ pub fn resolve_crate(session: &Session,
CrateMap { CrateMap {
def_map: resolver.def_map, def_map: resolver.def_map,
freevars: resolver.freevars, freevars: resolver.freevars,
capture_mode_map: resolver.capture_mode_map, capture_mode_map: RefCell::new(resolver.capture_mode_map),
exp_map2: resolver.export_map2, exp_map2: resolver.export_map2,
trait_map: resolver.trait_map, trait_map: resolver.trait_map,
external_exports: resolver.external_exports, external_exports: resolver.external_exports,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册