diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index cbc2ef1535ea6..60acf9de2df42 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -494,7 +494,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { let guard_exit = self.expr(&**guard, guard_start); let this_has_bindings = pat_util::pat_contains_bindings_or_wild( - &self.tcx.def_map, &**pat); + &self.tcx.def_map.borrow(), &**pat); // If both this pattern and the previous pattern // were free of bindings, they must consist only diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 79f4d62b45e75..86ebca2c3f338 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -692,7 +692,7 @@ fn is_useful(cx: &MatchCheckCtxt, Some(constructor) => { let matrix = rows.iter().filter_map(|r| { - if pat_is_binding_or_wild(&cx.tcx.def_map, raw_pat(r[0])) { + if pat_is_binding_or_wild(&cx.tcx.def_map.borrow(), raw_pat(r[0])) { Some(r.tail().to_vec()) } else { None @@ -1069,7 +1069,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, let def_map = &tcx.def_map; let mut by_ref_span = None; for pat in pats { - pat_bindings(def_map, &**pat, |bm, _, span, _path| { + pat_bindings(&def_map.borrow(), &**pat, |bm, _, span, _path| { match bm { ast::BindByRef(_) => { by_ref_span = Some(span); @@ -1084,7 +1084,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, // check legality of moving out of the enum // x @ Foo(..) is legal, but x @ Foo(y) isn't. - if sub.map_or(false, |p| pat_contains_bindings(def_map, &*p)) { + if sub.map_or(false, |p| pat_contains_bindings(&def_map.borrow(), &*p)) { span_err!(cx.tcx.sess, p.span, E0007, "cannot bind by-move with sub-bindings"); } else if has_guard { span_err!(cx.tcx.sess, p.span, E0008, "cannot bind by-move into a pattern guard"); @@ -1097,7 +1097,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, for pat in pats { ast_util::walk_pat(&**pat, |p| { - if pat_is_binding(def_map, &*p) { + if pat_is_binding(&def_map.borrow(), &*p) { match p.node { ast::PatIdent(ast::BindByValue(_), _, ref sub) => { let pat_ty = ty::node_id_to_type(tcx, p.id); @@ -1182,7 +1182,7 @@ struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> { impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> { fn visit_pat(&mut self, pat: &Pat) { - if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, pat) { + if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map.borrow(), pat) { span_err!(self.cx.tcx.sess, pat.span, E0303, "pattern bindings are not allowed \ after an `@`"); diff --git a/src/librustc/middle/check_static_recursion.rs b/src/librustc/middle/check_static_recursion.rs index b97978fc03fff..2e29e2c5872b2 100644 --- a/src/librustc/middle/check_static_recursion.rs +++ b/src/librustc/middle/check_static_recursion.rs @@ -94,7 +94,7 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> { fn visit_expr(&mut self, e: &ast::Expr) { match e.node { ast::ExprPath(..) => { - match self.def_map.borrow().get(&e.id).map(|d| d.base_def) { + match self.def_map.get(&e.id).map(|d| d.base_def) { Some(DefStatic(def_id, _)) | Some(DefConst(def_id)) if ast_util::is_local(def_id) => { diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 568375597c0de..25d33d4aceddc 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -284,7 +284,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> { ast::PatStruct(_, ref fields, _) => { self.handle_field_pattern_match(pat, fields); } - _ if pat_util::pat_is_const(def_map, pat) => { + _ if pat_util::pat_is_const(&def_map.borrow(), pat) => { // it might be the only use of a const self.lookup_and_handle_definition(&pat.id) } diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index 6707a4d3fd775..29275c50c407c 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -17,8 +17,6 @@ use util::nodemap::NodeMap; use syntax::ast; use syntax::ast_util::local_def; -use std::cell::RefCell; - #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum Def { DefFn(ast::DefId, bool /* is_ctor */), @@ -99,7 +97,7 @@ impl PathResolution { } // Definition mapping -pub type DefMap = RefCell>; +pub type DefMap = NodeMap; // This is the replacement export map. It maps a module to all of the exports // within. pub type ExportMap = NodeMap>; diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 2fa9c7c8fbebb..525b807d8073a 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -688,7 +688,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { match local.init { None => { let delegate = &mut self.delegate; - pat_util::pat_bindings(&self.typer.tcx().def_map, &*local.pat, + pat_util::pat_bindings(&self.typer.tcx().def_map.borrow(), &*local.pat, |_, id, span, _| { delegate.decl_without_init(id, span); }) @@ -969,7 +969,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| { let tcx = self.tcx(); let def_map = &self.tcx().def_map; - if pat_util::pat_is_binding(def_map, pat) { + if pat_util::pat_is_binding(&def_map.borrow(), pat) { match pat.node { ast::PatIdent(ast::BindByRef(_), _, _) => mode.lub(BorrowingMatch), @@ -1004,7 +1004,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { let def_map = &self.tcx().def_map; let delegate = &mut self.delegate; return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| { - if pat_util::pat_is_binding(def_map, pat) { + if pat_util::pat_is_binding(&def_map.borrow(), pat) { let tcx = typer.tcx(); debug!("binding cmt_pat={} pat={} match_mode={:?}", diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index d7161607b61eb..cb82d226b6aba 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -381,7 +381,7 @@ fn visit_fn(ir: &mut IrMaps, debug!("creating fn_maps: {:?}", &fn_maps as *const IrMaps); for arg in &decl.inputs { - pat_util::pat_bindings(&ir.tcx.def_map, + pat_util::pat_bindings(&ir.tcx.def_map.borrow(), &*arg.pat, |_bm, arg_id, _x, path1| { debug!("adding argument {}", arg_id); @@ -416,7 +416,7 @@ fn visit_fn(ir: &mut IrMaps, } fn visit_local(ir: &mut IrMaps, local: &ast::Local) { - pat_util::pat_bindings(&ir.tcx.def_map, &*local.pat, |_, p_id, sp, path1| { + pat_util::pat_bindings(&ir.tcx.def_map.borrow(), &*local.pat, |_, p_id, sp, path1| { debug!("adding local variable {}", p_id); let name = path1.node; ir.add_live_node_for_node(p_id, VarDefNode(sp)); @@ -430,7 +430,7 @@ fn visit_local(ir: &mut IrMaps, local: &ast::Local) { fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) { for pat in &arm.pats { - pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| { + pat_util::pat_bindings(&ir.tcx.def_map.borrow(), &**pat, |bm, p_id, sp, path1| { debug!("adding local variable {} from match with bm {:?}", p_id, bm); let name = path1.node; @@ -599,7 +599,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn pat_bindings(&mut self, pat: &ast::Pat, mut f: F) where F: FnMut(&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId), { - pat_util::pat_bindings(&self.ir.tcx.def_map, pat, |_bm, p_id, sp, _n| { + pat_util::pat_bindings(&self.ir.tcx.def_map.borrow(), pat, |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); let var = self.variable(p_id, sp); f(self, ln, var, sp, p_id); @@ -1595,7 +1595,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn warn_about_unused_args(&self, decl: &ast::FnDecl, entry_ln: LiveNode) { for arg in &decl.inputs { - pat_util::pat_bindings(&self.ir.tcx.def_map, + pat_util::pat_bindings(&self.ir.tcx.def_map.borrow(), &*arg.pat, |_bm, p_id, sp, path1| { let var = self.variable(p_id, sp); diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 12b56562c84d6..1802222edf12e 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -34,7 +34,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &ast::Pat) -> bool { ast::PatEnum(_, _) | ast::PatIdent(_, _, None) | ast::PatStruct(..) => { - match dm.borrow().get(&pat.id).map(|d| d.full_def()) { + match dm.get(&pat.id).map(|d| d.full_def()) { Some(DefVariant(..)) => true, _ => false } @@ -49,7 +49,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &ast::Pat) -> bool { ast::PatEnum(_, _) | ast::PatIdent(_, _, None) | ast::PatStruct(..) => { - match dm.borrow().get(&pat.id).map(|d| d.full_def()) { + match dm.get(&pat.id).map(|d| d.full_def()) { Some(DefVariant(..)) | Some(DefStruct(..)) => true, _ => false } @@ -61,7 +61,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &ast::Pat) -> bool { pub fn pat_is_const(dm: &DefMap, pat: &ast::Pat) -> bool { match pat.node { ast::PatIdent(_, _, None) | ast::PatEnum(..) => { - match dm.borrow().get(&pat.id).map(|d| d.full_def()) { + match dm.get(&pat.id).map(|d| d.full_def()) { Some(DefConst(..)) => true, _ => false } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index a3d71c989bfdf..2a070ef4c7777 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -172,7 +172,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> { ast::TyPath(None, ref path) => { // if this path references a trait, then this will resolve to // a trait ref, which introduces a binding scope. - match self.def_map.borrow().get(&ty.id).map(|d| (d.base_def, d.depth)) { + match self.def_map.get(&ty.id).map(|d| (d.base_def, d.depth)) { Some((def::DefTrait(..), 0)) => { self.with(LateScope(&Vec::new(), self.scope), |_, this| { this.visit_path(path, ty.id); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 1123c9236312a..90430f216e472 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -680,7 +680,7 @@ pub struct ctxt<'tcx> { pub types: CommonTypes<'tcx>, pub sess: Session, - pub def_map: DefMap, + pub def_map: RefCell, pub named_region_map: resolve_lifetime::NamedRegionMap, @@ -2611,7 +2611,7 @@ pub fn mk_ctxt<'tcx>(s: Session, item_variance_map: RefCell::new(DefIdMap()), variance_computed: Cell::new(false), sess: s, - def_map: def_map, + def_map: RefCell::new(def_map), region_maps: region_maps, node_types: RefCell::new(FnvHashMap()), item_substs: RefCell::new(NodeMap()), @@ -2733,11 +2733,11 @@ impl<'tcx> ctxt<'tcx> { } pub fn pat_contains_ref_binding(&self, pat: &ast::Pat) -> bool { - pat_util::pat_contains_ref_binding(&self.def_map, pat) + pat_util::pat_contains_ref_binding(&self.def_map.borrow(), pat) } pub fn arm_contains_ref_binding(&self, arm: &ast::Arm) -> bool { - pat_util::arm_contains_ref_binding(&self.def_map, arm) + pat_util::arm_contains_ref_binding(&self.def_map.borrow(), arm) } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 3bb737ddc1279..0eb6225c1e940 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1329,7 +1329,7 @@ impl UnusedMut { let mut mutables = FnvHashMap(); for p in pats { - pat_util::pat_bindings(&cx.tcx.def_map, &**p, |mode, id, _, path1| { + pat_util::pat_bindings(&cx.tcx.def_map.borrow(), &**p, |mode, id, _, path1| { let ident = path1.node; if let ast::BindByValue(ast::MutMutable) = mode { if !token::get_ident(ident).starts_with("_") { diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index aebbe14407380..070f1d5436090 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -68,8 +68,7 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> { "unused import".to_string()); } - let mut def_map = self.def_map.borrow_mut(); - let path_res = if let Some(r) = def_map.get_mut(&id) { + let path_res = if let Some(r) = self.resolver.def_map.get_mut(&id) { r } else { return; @@ -81,12 +80,12 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> { } }; - let mut v_used = if self.used_imports.contains(&(id, ValueNS)) { + let mut v_used = if self.resolver.used_imports.contains(&(id, ValueNS)) { Used } else { Unused }; - let t_used = if self.used_imports.contains(&(id, TypeNS)) { + let t_used = if self.resolver.used_imports.contains(&(id, TypeNS)) { Used } else { Unused diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 045320e4fa425..968996ab2f686 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -869,7 +869,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { primitive_type_table: PrimitiveTypeTable::new(), - def_map: RefCell::new(NodeMap()), + def_map: NodeMap(), freevars: RefCell::new(NodeMap()), freevars_seen: RefCell::new(NodeMap()), export_map: NodeMap(), @@ -1871,7 +1871,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ItemUse(ref view_path) => { // check for imports shadowing primitive types if let ast::ViewPathSimple(ident, _) = view_path.node { - match self.def_map.borrow().get(&item.id).map(|d| d.full_def()) { + match self.def_map.get(&item.id).map(|d| d.full_def()) { Some(DefTy(..)) | Some(DefStruct(..)) | Some(DefTrait(..)) | None => { self.check_if_primitive_type_name(ident.name, item.span); } @@ -2991,7 +2991,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if allowed == Everything { // Look for a field with the same name in the current self_type. - match self.def_map.borrow().get(&node_id).map(|d| d.full_def()) { + match self.def_map.get(&node_id).map(|d| d.full_def()) { Some(DefTy(did, _)) | Some(DefStruct(did)) | Some(DefVariant(_, did, _)) => match self.structs.get(&did) { @@ -3402,7 +3402,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { assert!(match resolution.last_private {LastImport{..} => false, _ => true}, "Import should only be used for `use` directives"); - if let Some(prev_res) = self.def_map.borrow_mut().insert(node_id, resolution) { + if let Some(prev_res) = self.def_map.insert(node_id, resolution) { let span = self.ast_map.opt_span(node_id).unwrap_or(codemap::DUMMY_SP); self.session.span_bug(span, &format!("path resolved multiple times \ ({:?} before, {:?} now)", diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index f1a8507b17811..d1136376ec1e4 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -684,14 +684,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { }; if let Some((def, _)) = value_def_and_priv { - self.resolver.def_map.borrow_mut().insert(directive.id, PathResolution { + self.resolver.def_map.insert(directive.id, PathResolution { base_def: def, last_private: import_lp, depth: 0 }); } if let Some((def, _)) = type_def_and_priv { - self.resolver.def_map.borrow_mut().insert(directive.id, PathResolution { + self.resolver.def_map.insert(directive.id, PathResolution { base_def: def, last_private: import_lp, depth: 0 @@ -815,7 +815,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { // Record the destination of this import if let Some(did) = target_module.def_id.get() { - self.resolver.def_map.borrow_mut().insert(id, PathResolution { + self.resolver.def_map.insert(id, PathResolution { base_def: DefMod(did), last_private: lp, depth: 0 diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index ef599a01e7c40..e28c758e63ec1 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -449,7 +449,7 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, let mut bound_ptrs = br.bound_ptrs.clone(); match this.node { ast::PatIdent(_, ref path, None) => { - if pat_is_binding(dm, &*this) { + if pat_is_binding(&dm, &*this) { bound_ptrs.push((path.node, val)); } } @@ -488,7 +488,7 @@ fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Collect all of the matches that can match against anything. enter_match(bcx, dm, m, col, val, |pats| { - if pat_is_binding_or_wild(dm, &*pats[col]) { + if pat_is_binding_or_wild(&dm, &*pats[col]) { let mut r = pats[..col].to_vec(); r.push_all(&pats[col + 1..]); Some(r) @@ -776,7 +776,7 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option { fn pat_score(def_map: &DefMap, pat: &ast::Pat) -> usize { match pat.node { ast::PatIdent(_, _, Some(ref inner)) => pat_score(def_map, &**inner), - _ if pat_is_refutable(def_map, pat) => 1, + _ if pat_is_refutable(&def_map, pat) => 1, _ => 0 } } @@ -996,9 +996,9 @@ fn compile_submatch<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, return; } - let tcx = bcx.tcx(); - let def_map = &tcx.def_map; - match pick_column_to_specialize(def_map, m) { + // On a separate line to limit the lifetime of the borrow + let col_opt = pick_column_to_specialize(&bcx.tcx().def_map.borrow(), m); + match col_opt { Some(col) => { let val = vals[col]; if has_nested_bindings(m, col) { @@ -1094,7 +1094,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, }; match adt_vals { Some(field_vals) => { - let pats = enter_match(bcx, dm, m, col, val, |pats| + let pats = enter_match(bcx, &dm.borrow(), m, col, val, |pats| check_match::specialize(&mcx, pats, &check_match::Single, col, field_vals.len()) @@ -1152,7 +1152,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, C_int(ccx, 0) // Placeholder for when not using a switch }; - let defaults = enter_default(else_cx, dm, m, col, val); + let defaults = enter_default(else_cx, &dm.borrow(), m, col, val); let exhaustive = chk.is_infallible() && defaults.len() == 0; let len = opts.len(); @@ -1252,7 +1252,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } ConstantValue(..) | ConstantRange(..) => () } - let opt_ms = enter_opt(opt_cx, pat_id, dm, m, opt, col, size, val); + let opt_ms = enter_opt(opt_cx, pat_id, &dm.borrow(), m, opt, col, size, val); let mut opt_vals = unpacked; opt_vals.push_all(&vals_left[..]); compile_submatch(opt_cx, @@ -1378,7 +1378,7 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat, let tcx = bcx.tcx(); let reassigned = is_discr_reassigned(bcx, discr, body); let mut bindings_map = FnvHashMap(); - pat_bindings(&tcx.def_map, &*pat, |bm, p_id, span, path1| { + pat_bindings(&tcx.def_map.borrow(), &*pat, |bm, p_id, span, path1| { let ident = path1.node; let variable_ty = node_id_type(bcx, p_id); let llvariable_ty = type_of::type_of(ccx, variable_ty); @@ -1524,7 +1524,7 @@ pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // create dummy memory for the variables if we have no // value to store into them immediately let tcx = bcx.tcx(); - pat_bindings(&tcx.def_map, pat, |_, p_id, _, path1| { + pat_bindings(&tcx.def_map.borrow(), pat, |_, p_id, _, path1| { let scope = cleanup::var_scope(tcx, p_id); bcx = mk_binding_alloca( bcx, p_id, &path1.node, scope, (), @@ -1681,7 +1681,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let ccx = bcx.ccx(); match pat.node { ast::PatIdent(pat_binding_mode, ref path1, ref inner) => { - if pat_is_binding(&tcx.def_map, &*pat) { + if pat_is_binding(&tcx.def_map.borrow(), &*pat) { // Allocate the stack slot where the value of this // binding will live and place it into the appropriate // map. diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 2747288b60755..9ba23016ed163 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -843,7 +843,7 @@ pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) { let def_map = &cx.tcx().def_map; let locals = bcx.fcx.lllocals.borrow(); - pat_util::pat_bindings(def_map, &*local.pat, |_, node_id, span, var_ident| { + pat_util::pat_bindings(&def_map.borrow(), &*local.pat, |_, node_id, span, var_ident| { let datum = match locals.get(&node_id) { Some(datum) => datum, None => { @@ -1021,7 +1021,7 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) { .fn_metadata; let locals = bcx.fcx.lllocals.borrow(); - pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, span, var_ident| { + pat_util::pat_bindings(&def_map.borrow(), &*arg.pat, |_, node_id, span, var_ident| { let datum = match locals.get(&node_id) { Some(v) => v, None => { @@ -3255,7 +3255,7 @@ fn create_scope_map(cx: &CrateContext, // Push argument identifiers onto the stack so arguments integrate nicely // with variable shadowing. for arg in args { - pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, _, path1| { + pat_util::pat_bindings(&def_map.borrow(), &*arg.pat, |_, node_id, _, path1| { scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata, ident: Some(path1.node) }); scope_map.insert(node_id, fn_metadata); @@ -3372,7 +3372,7 @@ fn create_scope_map(cx: &CrateContext, // Check if this is a binding. If so we need to put it on the // scope stack and maybe introduce an artificial scope - if pat_util::pat_is_binding(def_map, &*pat) { + if pat_util::pat_is_binding(&def_map.borrow(), &*pat) { let ident = path1.node; diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 8f1a67723cb79..655b6d18af35b 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -118,7 +118,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, // subtyping doesn't matter here, as the value is some kind of scalar demand::eqtype(fcx, pat.span, expected, lhs_ty); } - ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => { + ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map.borrow(), pat) => { let const_did = tcx.def_map.borrow().get(&pat.id).unwrap().def_id(); let const_scheme = ty::lookup_item_type(tcx, const_did); assert!(const_scheme.generics.is_empty()); @@ -134,7 +134,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, // is good enough. demand::suptype(fcx, pat.span, expected, const_ty); } - ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => { + ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map.borrow(), pat) => { let typ = fcx.local_ty(pat.span, pat.id); match bm { ast::BindByRef(mutbl) => { @@ -336,7 +336,7 @@ pub fn check_dereferencable<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, inner: &ast::Pat) -> bool { let fcx = pcx.fcx; let tcx = pcx.fcx.ccx.tcx; - if pat_is_binding(&tcx.def_map, inner) { + if pat_is_binding(&tcx.def_map.borrow(), inner) { let expected = fcx.infcx().shallow_resolve(expected); ty::deref(expected, true).map_or(true, |mt| match mt.ty.sty { ty::ty_trait(_) => { @@ -383,7 +383,7 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, for arm in arms { let mut pcx = pat_ctxt { fcx: fcx, - map: pat_id_map(&tcx.def_map, &*arm.pats[0]), + map: pat_id_map(&tcx.def_map.borrow(), &*arm.pats[0]), }; for p in &arm.pats { check_pat(&mut pcx, &**p, discrim_ty); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 156fbfede9c98..5dc3200663f97 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -574,7 +574,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { // Add pattern bindings. fn visit_pat(&mut self, p: &'tcx ast::Pat) { if let ast::PatIdent(_, ref path1, _) = p.node { - if pat_util::pat_is_binding(&self.fcx.ccx.tcx.def_map, p) { + if pat_util::pat_is_binding(&self.fcx.ccx.tcx.def_map.borrow(), p) { let var_ty = self.assign(p.span, p.id, None); self.fcx.require_type_is_sized(var_ty, p.span, @@ -679,7 +679,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, for (arg_ty, input) in arg_tys.iter().zip(decl.inputs.iter()) { // Create type variables for each argument. pat_util::pat_bindings( - &tcx.def_map, + &tcx.def_map.borrow(), &*input.pat, |_bm, pat_id, sp, _path| { let var_ty = visit.assign(sp, pat_id, None); @@ -690,7 +690,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, // Check the pattern. let pcx = pat_ctxt { fcx: &fcx, - map: pat_id_map(&tcx.def_map, &*input.pat), + map: pat_id_map(&tcx.def_map.borrow(), &*input.pat), }; _match::check_pat(&pcx, &*input.pat, *arg_ty); } @@ -3989,7 +3989,7 @@ pub fn check_decl_local<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, local: &'tcx ast::Local) let pcx = pat_ctxt { fcx: fcx, - map: pat_id_map(&tcx.def_map, &*local.pat), + map: pat_id_map(&tcx.def_map.borrow(), &*local.pat), }; _match::check_pat(&pcx, &*local.pat, t); let pat_ty = fcx.node_ty(local.pat.id); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 9171367468026..fff2cfdab75ac 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -446,7 +446,7 @@ fn visit_local(rcx: &mut Rcx, l: &ast::Local) { fn constrain_bindings_in_pat(pat: &ast::Pat, rcx: &mut Rcx) { let tcx = rcx.fcx.tcx(); debug!("regionck::visit_pat(pat={})", pat.repr(tcx)); - pat_util::pat_bindings(&tcx.def_map, pat, |_, id, span, _| { + pat_util::pat_bindings(&tcx.def_map.borrow(), pat, |_, id, span, _| { // If we have a variable that contains region'd data, that // data will be accessible from anywhere that the variable is // accessed. We must be wary of loops like this: diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 37f43252483aa..2135e5c53c046 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -55,7 +55,7 @@ pub fn resolve_type_vars_in_fn(fcx: &FnCtxt, wbcx.visit_pat(&*arg.pat); // Privacy needs the type for the whole pattern, not just each binding - if !pat_util::pat_is_binding(&fcx.tcx().def_map, &*arg.pat) { + if !pat_util::pat_is_binding(&fcx.tcx().def_map.borrow(), &*arg.pat) { wbcx.visit_node_id(ResolvingPattern(arg.pat.span), arg.pat.id); }