1
Fork 0

auto merge of #18914 : Gankro/rust/cloned, r=aturon

Part of #18424. r? @aturon 

[breaking-change]
This commit is contained in:
bors 2014-11-17 09:26:57 +00:00
commit edfb83c9e2
31 changed files with 121 additions and 119 deletions

View file

@ -150,6 +150,7 @@ use mem;
use result::{Result, Ok, Err}; use result::{Result, Ok, Err};
use slice; use slice;
use slice::AsSlice; use slice::AsSlice;
use clone::Clone;
// Note that this is not a lang item per se, but it has a hidden dependency on // Note that this is not a lang item per se, but it has a hidden dependency on
// `Iterator`, which is one. The compiler assumes that the `next` method of // `Iterator`, which is one. The compiler assumes that the `next` method of
@ -691,6 +692,14 @@ impl<T> Option<T> {
} }
} }
impl<'a, T: Clone> Option<&'a T> {
/// Maps an Option<&T> to an Option<T> by cloning the contents of the Option<&T>.
#[unstable = "recently added as part of collections reform"]
pub fn cloned(self) -> Option<T> {
self.map(|t| t.clone())
}
}
impl<T: Default> Option<T> { impl<T: Default> Option<T> {
/// Returns the contained value or a default /// Returns the contained value or a default
/// ///

View file

@ -11,6 +11,7 @@
use core::option::*; use core::option::*;
use core::kinds::marker; use core::kinds::marker;
use core::mem; use core::mem;
use core::clone::Clone;
#[test] #[test]
fn test_get_ptr() { fn test_get_ptr() {
@ -239,3 +240,15 @@ fn test_collect() {
assert!(v == None); assert!(v == None);
} }
fn test_cloned() {
let s = 1u32;
let n: Option<&'static u32> = None;
let o = Some(&s);
assert_eq!(o.clone(), Some(&s));
assert_eq!(o.cloned(), Some(1u32));
assert_eq!(n.clone(), None);
assert_eq!(n.cloned(), None);
}

View file

@ -391,7 +391,7 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) { fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
match self.cx.tcx.def_map.borrow().get_copy(&path_id) { match self.cx.tcx.def_map.borrow()[path_id].clone() {
def::DefPrimTy(ast::TyInt(ast::TyI)) => { def::DefPrimTy(ast::TyInt(ast::TyI)) => {
self.cx.span_lint(IMPROPER_CTYPES, sp, self.cx.span_lint(IMPROPER_CTYPES, sp,
"found rust type `int` in foreign module, while \ "found rust type `int` in foreign module, while \
@ -869,7 +869,7 @@ fn method_context(cx: &Context, m: &ast::Method) -> MethodContext {
node: m.id node: m.id
}; };
match cx.tcx.impl_or_trait_items.borrow().find_copy(&did) { match cx.tcx.impl_or_trait_items.borrow().get(&did).cloned() {
None => cx.sess().span_bug(m.span, "missing method descriptor?!"), None => cx.sess().span_bug(m.span, "missing method descriptor?!"),
Some(md) => { Some(md) => {
match md { match md {

View file

@ -1863,7 +1863,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
match item.node { match item.node {
ItemImpl(_, Some(ref trait_ref), _, _) => { ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = &self.ecx.tcx.def_map; let def_map = &self.ecx.tcx.def_map;
let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id); let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
let def_id = trait_def.def_id(); let def_id = trait_def.def_id();
// Load eagerly if this is an implementation of the Drop trait // Load eagerly if this is an implementation of the Drop trait

View file

@ -439,7 +439,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
pos: pos, pos: pos,
len: len }; len: len };
match st.tcx.rcache.borrow().find_copy(&key) { match st.tcx.rcache.borrow().get(&key).cloned() {
Some(tt) => return tt, Some(tt) => return tt,
None => {} None => {}
} }

View file

@ -1200,8 +1200,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
var_id: var_id, var_id: var_id,
closure_expr_id: id closure_expr_id: id
}; };
let upvar_borrow = tcx.upvar_borrow_map.borrow() let upvar_borrow = tcx.upvar_borrow_map.borrow()[upvar_id].clone();
.get_copy(&upvar_id);
var_id.encode(rbml_w); var_id.encode(rbml_w);
upvar_borrow.encode(rbml_w); upvar_borrow.encode(rbml_w);
}) })

View file

@ -295,7 +295,7 @@ impl MoveData {
fn existing_move_path(&self, lp: &Rc<LoanPath>) fn existing_move_path(&self, lp: &Rc<LoanPath>)
-> Option<MovePathIndex> { -> Option<MovePathIndex> {
self.path_map.borrow().find_copy(lp) self.path_map.borrow().get(lp).cloned()
} }
fn existing_base_paths(&self, lp: &Rc<LoanPath>) fn existing_base_paths(&self, lp: &Rc<LoanPath>)
@ -312,7 +312,7 @@ impl MoveData {
* paths of `lp` to `result`, but does not add new move paths * paths of `lp` to `result`, but does not add new move paths
*/ */
match self.path_map.borrow().find_copy(lp) { match self.path_map.borrow().get(lp).cloned() {
Some(index) => { Some(index) => {
self.each_base_path(index, |p| { self.each_base_path(index, |p| {
result.push(p); result.push(p);

View file

@ -359,7 +359,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
fn fold_pat(&mut self, pat: P<Pat>) -> P<Pat> { fn fold_pat(&mut self, pat: P<Pat>) -> P<Pat> {
match pat.node { match pat.node {
PatIdent(..) | PatEnum(..) => { PatIdent(..) | PatEnum(..) => {
let def = self.tcx.def_map.borrow().find_copy(&pat.id); let def = self.tcx.def_map.borrow().get(&pat.id).cloned();
match def { match def {
Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did) { Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did) {
Some(const_expr) => { Some(const_expr) => {
@ -749,7 +749,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
Some(Vec::from_elem(arity, DUMMY_WILD_PAT)), Some(Vec::from_elem(arity, DUMMY_WILD_PAT)),
&PatIdent(_, _, _) => { &PatIdent(_, _, _) => {
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat_id); let opt_def = cx.tcx.def_map.borrow().get(&pat_id).cloned();
match opt_def { match opt_def {
Some(DefConst(..)) => Some(DefConst(..)) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \ cx.tcx.sess.span_bug(pat_span, "const pattern should've \
@ -764,7 +764,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
} }
&PatEnum(_, ref args) => { &PatEnum(_, ref args) => {
let def = cx.tcx.def_map.borrow().get_copy(&pat_id); let def = cx.tcx.def_map.borrow()[pat_id].clone();
match def { match def {
DefConst(..) => DefConst(..) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \ cx.tcx.sess.span_bug(pat_span, "const pattern should've \
@ -782,7 +782,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
&PatStruct(_, ref pattern_fields, _) => { &PatStruct(_, ref pattern_fields, _) => {
// Is this a struct or an enum variant? // Is this a struct or an enum variant?
let def = cx.tcx.def_map.borrow().get_copy(&pat_id); let def = cx.tcx.def_map.borrow()[pat_id].clone();
let class_id = match def { let class_id = match def {
DefConst(..) => DefConst(..) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \ cx.tcx.sess.span_bug(pat_span, "const pattern should've \

View file

@ -85,7 +85,7 @@ pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
} }
fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> { fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> {
let opt_def = tcx.def_map.borrow().find_copy(&e.id); let opt_def = tcx.def_map.borrow().get(&e.id).cloned();
match opt_def { match opt_def {
Some(def::DefConst(def_id)) => { Some(def::DefConst(def_id)) => {
lookup_const_by_id(tcx, def_id) lookup_const_by_id(tcx, def_id)
@ -320,7 +320,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect()), PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect()),
ExprCall(ref callee, ref args) => { ExprCall(ref callee, ref args) => {
let def = tcx.def_map.borrow().get_copy(&callee.id); let def = tcx.def_map.borrow()[callee.id].clone();
match tcx.def_map.borrow_mut().entry(expr.id) { match tcx.def_map.borrow_mut().entry(expr.id) {
Vacant(entry) => { entry.set(def); } Vacant(entry) => { entry.set(def); }
_ => {} _ => {}
@ -352,7 +352,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
} }
ExprPath(ref path) => { ExprPath(ref path) => {
let opt_def = tcx.def_map.borrow().find_copy(&expr.id); let opt_def = tcx.def_map.borrow().get(&expr.id).cloned();
match opt_def { match opt_def {
Some(def::DefStruct(..)) => Some(def::DefStruct(..)) =>
PatStruct(path.clone(), vec![], false), PatStruct(path.clone(), vec![], false),

View file

@ -850,7 +850,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
// Each match binding is effectively an assignment to the // Each match binding is effectively an assignment to the
// binding being produced. // binding being produced.
let def = def_map.borrow().get_copy(&pat.id); let def = def_map.borrow()[pat.id].clone();
match mc.cat_def(pat.id, pat.span, pat_ty, def) { match mc.cat_def(pat.id, pat.span, pat_ty, def) {
Ok(binding_cmt) => { Ok(binding_cmt) => {
delegate.mutate(pat.id, pat.span, binding_cmt, Init); delegate.mutate(pat.id, pat.span, binding_cmt, Init);
@ -957,8 +957,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
// inferred by regionbk // inferred by regionbk
let upvar_id = ty::UpvarId { var_id: id_var, let upvar_id = ty::UpvarId { var_id: id_var,
closure_expr_id: closure_expr.id }; closure_expr_id: closure_expr.id };
let upvar_borrow = self.tcx().upvar_borrow_map.borrow() let upvar_borrow = self.tcx().upvar_borrow_map.borrow()[upvar_id].clone();
.get_copy(&upvar_id);
self.delegate.borrow(closure_expr.id, self.delegate.borrow(closure_expr.id,
closure_expr.span, closure_expr.span,

View file

@ -449,7 +449,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node { match expr.node {
// live nodes required for uses or definitions of variables: // live nodes required for uses or definitions of variables:
ExprPath(_) => { ExprPath(_) => {
let def = ir.tcx.def_map.borrow().get_copy(&expr.id); let def = ir.tcx.def_map.borrow()[expr.id].clone();
debug!("expr {}: path that leads to {}", expr.id, def); debug!("expr {}: path that leads to {}", expr.id, def);
match def { match def {
DefLocal(..) => ir.add_live_node_for_node(expr.id, ExprNode(expr.span)), DefLocal(..) => ir.add_live_node_for_node(expr.id, ExprNode(expr.span)),
@ -1316,7 +1316,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint) fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
-> LiveNode { -> LiveNode {
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) { match self.ir.tcx.def_map.borrow()[expr.id].clone() {
DefLocal(nid) => { DefLocal(nid) => {
let ln = self.live_node(expr.id, expr.span); let ln = self.live_node(expr.id, expr.span);
if acc != 0u { if acc != 0u {
@ -1582,7 +1582,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn check_lvalue(&mut self, expr: &Expr) { fn check_lvalue(&mut self, expr: &Expr) {
match expr.node { match expr.node {
ExprPath(_) => { ExprPath(_) => {
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) { match self.ir.tcx.def_map.borrow()[expr.id].clone() {
DefLocal(nid) => { DefLocal(nid) => {
// Assignment to an immutable variable or argument: only legal // Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually // if there is no later assignment. If this local is actually

View file

@ -245,7 +245,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
ast::ItemImpl(_, _, ref ty, ref impl_items) => { ast::ItemImpl(_, _, ref ty, ref impl_items) => {
let public_ty = match ty.node { let public_ty = match ty.node {
ast::TyPath(_, _, id) => { ast::TyPath(_, _, id) => {
match self.tcx.def_map.borrow().get_copy(&id) { match self.tcx.def_map.borrow()[id].clone() {
def::DefPrimTy(..) => true, def::DefPrimTy(..) => true,
def => { def => {
let did = def.def_id(); let did = def.def_id();
@ -313,7 +313,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
ast::ItemTy(ref ty, _) if public_first => { ast::ItemTy(ref ty, _) if public_first => {
match ty.node { match ty.node {
ast::TyPath(_, _, id) => { ast::TyPath(_, _, id) => {
match self.tcx.def_map.borrow().get_copy(&id) { match self.tcx.def_map.borrow()[id].clone() {
def::DefPrimTy(..) | def::DefTyParam(..) => {}, def::DefPrimTy(..) | def::DefTyParam(..) => {},
def => { def => {
let did = def.def_id(); let did = def.def_id();
@ -620,7 +620,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
ast::TyPath(_, _, id) => id, ast::TyPath(_, _, id) => id,
_ => return Some((err_span, err_msg, None)), _ => return Some((err_span, err_msg, None)),
}; };
let def = self.tcx.def_map.borrow().get_copy(&id); let def = self.tcx.def_map.borrow()[id].clone();
let did = def.def_id(); let did = def.def_id();
assert!(is_local(did)); assert!(is_local(did));
match self.tcx.map.get(did.node) { match self.tcx.map.get(did.node) {
@ -706,7 +706,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// Checks that a path is in scope. // Checks that a path is in scope.
fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) { fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
debug!("privacy - path {}", self.nodestr(path_id)); debug!("privacy - path {}", self.nodestr(path_id));
let orig_def = self.tcx.def_map.borrow().get_copy(&path_id); let orig_def = self.tcx.def_map.borrow()[path_id].clone();
let ck = |tyname: &str| { let ck = |tyname: &str| {
let ck_public = |def: ast::DefId| { let ck_public = |def: ast::DefId| {
let name = token::get_ident(path.segments let name = token::get_ident(path.segments
@ -789,7 +789,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// def map is not. Therefore the names we work out below will not always // def map is not. Therefore the names we work out below will not always
// be accurate and we can get slightly wonky error messages (but type // be accurate and we can get slightly wonky error messages (but type
// checking is always correct). // checking is always correct).
match self.tcx.def_map.borrow().get_copy(&path_id) { match self.tcx.def_map.borrow()[path_id].clone() {
def::DefStaticMethod(..) => ck("static method"), def::DefStaticMethod(..) => ck("static method"),
def::DefFn(..) => ck("function"), def::DefFn(..) => ck("function"),
def::DefStatic(..) => ck("static"), def::DefStatic(..) => ck("static"),
@ -873,7 +873,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
} }
} }
ty::ty_enum(_, _) => { ty::ty_enum(_, _) => {
match self.tcx.def_map.borrow().get_copy(&expr.id) { match self.tcx.def_map.borrow()[expr.id].clone() {
def::DefVariant(_, variant_id, _) => { def::DefVariant(_, variant_id, _) => {
for field in fields.iter() { for field in fields.iter() {
self.check_field(expr.span, variant_id, self.check_field(expr.span, variant_id,
@ -1255,7 +1255,7 @@ struct CheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> {
impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
fn path_is_private_type(&self, path_id: ast::NodeId) -> bool { fn path_is_private_type(&self, path_id: ast::NodeId) -> bool {
let did = match self.tcx.def_map.borrow().find_copy(&path_id) { let did = match self.tcx.def_map.borrow().get(&path_id).cloned() {
// `int` etc. (None doesn't seem to occur.) // `int` etc. (None doesn't seem to occur.)
None | Some(def::DefPrimTy(..)) => return false, None | Some(def::DefPrimTy(..)) => return false,
Some(def) => def.def_id() Some(def) => def.def_id()

View file

@ -1097,7 +1097,7 @@ impl<'a> Resolver<'a> {
sp); sp);
// Add or reuse the child. // Add or reuse the child.
let child = module_.children.borrow().find_copy(&name); let child = module_.children.borrow().get(&name).cloned();
match child { match child {
None => { None => {
let child = Rc::new(NameBindings::new()); let child = Rc::new(NameBindings::new());
@ -1381,7 +1381,7 @@ impl<'a> Resolver<'a> {
let mod_name = path.segments.last().unwrap().identifier.name; let mod_name = path.segments.last().unwrap().identifier.name;
let parent_opt = parent.module().children.borrow() let parent_opt = parent.module().children.borrow()
.find_copy(&mod_name); .get(&mod_name).cloned();
let new_parent = match parent_opt { let new_parent = match parent_opt {
// It already exists // It already exists
Some(ref child) if child.get_module_if_available() Some(ref child) if child.get_module_if_available()
@ -2676,7 +2676,7 @@ impl<'a> Resolver<'a> {
BoundResult(..) => {} BoundResult(..) => {}
_ => { _ => {
match containing_module.external_module_children.borrow_mut() match containing_module.external_module_children.borrow_mut()
.find_copy(&source) { .get(&source).cloned() {
None => {} // Continue. None => {} // Continue.
Some(module) => { Some(module) => {
debug!("(resolving single import) found external \ debug!("(resolving single import) found external \
@ -3191,7 +3191,7 @@ impl<'a> Resolver<'a> {
fn search_parent_externals(needle: Name, module: &Rc<Module>) fn search_parent_externals(needle: Name, module: &Rc<Module>)
-> Option<Rc<Module>> { -> Option<Rc<Module>> {
module.external_module_children.borrow() module.external_module_children.borrow()
.find_copy(&needle) .get(&needle).cloned()
.map(|_| module.clone()) .map(|_| module.clone())
.or_else(|| { .or_else(|| {
match module.parent_link.clone() { match module.parent_link.clone() {
@ -3478,7 +3478,7 @@ impl<'a> Resolver<'a> {
// Search for external modules. // Search for external modules.
if namespace == TypeNS { if namespace == TypeNS {
match module_.external_module_children.borrow().find_copy(&name) { match module_.external_module_children.borrow().get(&name).cloned() {
None => {} None => {}
Some(module) => { Some(module) => {
let name_bindings = let name_bindings =
@ -3763,7 +3763,7 @@ impl<'a> Resolver<'a> {
// Finally, search through external children. // Finally, search through external children.
if namespace == TypeNS { if namespace == TypeNS {
match module_.external_module_children.borrow().find_copy(&name) { match module_.external_module_children.borrow().get(&name).cloned() {
None => {} None => {}
Some(module) => { Some(module) => {
let name_bindings = let name_bindings =
@ -4043,7 +4043,7 @@ impl<'a> Resolver<'a> {
// item, it's ok // item, it's ok
match def { match def {
DefTyParam(_, did, _) if { DefTyParam(_, did, _) if {
self.def_map.borrow().find_copy(&did.node) self.def_map.borrow().get(&did.node).cloned()
== Some(DefTyParamBinder(item_id)) == Some(DefTyParamBinder(item_id))
} => {} // ok } => {} // ok
DefSelfTy(did) if did == item_id => {} // ok DefSelfTy(did) if did == item_id => {} // ok
@ -4096,7 +4096,7 @@ impl<'a> Resolver<'a> {
// item, it's ok // item, it's ok
match def { match def {
DefTyParam(_, did, _) if { DefTyParam(_, did, _) if {
self.def_map.borrow().find_copy(&did.node) self.def_map.borrow().get(&did.node).cloned()
== Some(DefTyParamBinder(item_id)) == Some(DefTyParamBinder(item_id))
} => {} // ok } => {} // ok
DefSelfTy(did) if did == item_id => {} // ok DefSelfTy(did) if did == item_id => {} // ok
@ -4148,7 +4148,7 @@ impl<'a> Resolver<'a> {
// 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.find_copy(&name) { match rib.bindings.get(&name).cloned() {
Some(def_like) => { Some(def_like) => {
return self.upvarify(ribs[i + 1..], def_like, span); return self.upvarify(ribs[i + 1..], def_like, span);
} }
@ -5444,7 +5444,7 @@ impl<'a> Resolver<'a> {
// Finally, search through external children. // Finally, search through external children.
if namespace == TypeNS { if namespace == TypeNS {
match containing_module.external_module_children.borrow() match containing_module.external_module_children.borrow()
.find_copy(&name) { .get(&name).cloned() {
None => {} None => {}
Some(module) => { Some(module) => {
match module.def_id.get() { match module.def_id.get() {

View file

@ -139,7 +139,7 @@ pub fn lookup(tcx: &ty::ctxt, id: DefId) -> Option<Stability> {
lookup(tcx, trait_method_id) lookup(tcx, trait_method_id)
} }
_ if is_local(id) => { _ if is_local(id) => {
tcx.stability.borrow().local.find_copy(&id.node) tcx.stability.borrow().local.get(&id.node).cloned()
} }
_ => { _ => {
let stab = csearch::get_stability(&tcx.sess.cstore, id); let stab = csearch::get_stability(&tcx.sess.cstore, id);

View file

@ -568,7 +568,7 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
ast::PatLit(ref l) => ConstantValue(ConstantExpr(&**l)), ast::PatLit(ref l) => ConstantValue(ConstantExpr(&**l)),
ast::PatIdent(..) | ast::PatEnum(..) | ast::PatStruct(..) => { ast::PatIdent(..) | ast::PatEnum(..) | ast::PatStruct(..) => {
// This is either an enum variant or a variable binding. // This is either an enum variant or a variable binding.
let opt_def = tcx.def_map.borrow().find_copy(&cur.id); let opt_def = tcx.def_map.borrow().get(&cur.id).cloned();
match opt_def { match opt_def {
Some(def::DefVariant(enum_id, var_id, _)) => { Some(def::DefVariant(enum_id, var_id, _)) => {
let variant = ty::enum_variant_with_id(tcx, enum_id, var_id); let variant = ty::enum_variant_with_id(tcx, enum_id, var_id);
@ -1642,7 +1642,7 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} }
} }
ast::PatEnum(_, ref sub_pats) => { ast::PatEnum(_, ref sub_pats) => {
let opt_def = bcx.tcx().def_map.borrow().find_copy(&pat.id); let opt_def = bcx.tcx().def_map.borrow().get(&pat.id).cloned();
match opt_def { match opt_def {
Some(def::DefVariant(enum_id, var_id, _)) => { Some(def::DefVariant(enum_id, var_id, _)) => {
let repr = adt::represent_node(bcx, pat.id); let repr = adt::represent_node(bcx, pat.id);

View file

@ -2266,7 +2266,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
static"); static");
} }
let v = ccx.static_values().borrow().get_copy(&item.id); let v = ccx.static_values().borrow()[item.id].clone();
unsafe { unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) { if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
ccx.sess().span_fatal(expr.span, "static assertion failed"); ccx.sess().span_fatal(expr.span, "static assertion failed");
@ -2656,7 +2656,7 @@ fn contains_null(s: &str) -> bool {
pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
debug!("get_item_val(id=`{}`)", id); debug!("get_item_val(id=`{}`)", id);
match ccx.item_vals().borrow().find_copy(&id) { match ccx.item_vals().borrow().get(&id).cloned() {
Some(v) => return v, Some(v) => return v,
None => {} None => {}
} }

View file

@ -526,12 +526,12 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
} }
fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow { fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow {
self.tcx().upvar_borrow_map.borrow().get_copy(&upvar_id) self.tcx().upvar_borrow_map.borrow()[upvar_id].clone()
} }
fn capture_mode(&self, closure_expr_id: ast::NodeId) fn capture_mode(&self, closure_expr_id: ast::NodeId)
-> ast::CaptureClause { -> ast::CaptureClause {
self.tcx().capture_modes.borrow().get_copy(&closure_expr_id) self.tcx().capture_modes.borrow()[closure_expr_id].clone()
} }
} }

View file

@ -184,7 +184,7 @@ pub fn get_const_val(cx: &CrateContext,
} }
} }
cx.const_values().borrow().get_copy(&def_id.node) cx.const_values().borrow()[def_id.node].clone()
} }
pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) { pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) {
@ -192,7 +192,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) {
let mut llconst = llconst; let mut llconst = llconst;
let ety = ty::expr_ty(cx.tcx(), e); let ety = ty::expr_ty(cx.tcx(), e);
let mut ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e); let mut ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e);
let opt_adj = cx.tcx().adjustments.borrow().find_copy(&e.id); let opt_adj = cx.tcx().adjustments.borrow().get(&e.id).cloned();
match opt_adj { match opt_adj {
None => { } None => { }
Some(adj) => { Some(adj) => {
@ -551,7 +551,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
_ => break, _ => break,
} }
} }
let opt_def = cx.tcx().def_map.borrow().find_copy(&cur.id); let opt_def = cx.tcx().def_map.borrow().get(&cur.id).cloned();
match opt_def { match opt_def {
Some(def::DefStatic(def_id, _)) => { Some(def::DefStatic(def_id, _)) => {
let ty = ty::expr_ty(cx.tcx(), e); let ty = ty::expr_ty(cx.tcx(), e);
@ -626,7 +626,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
// Assert that there are no type parameters in this path. // Assert that there are no type parameters in this path.
assert!(pth.segments.iter().all(|seg| !seg.parameters.has_types())); assert!(pth.segments.iter().all(|seg| !seg.parameters.has_types()));
let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id); let opt_def = cx.tcx().def_map.borrow().get(&e.id).cloned();
match opt_def { match opt_def {
Some(def::DefFn(def_id, _)) => { Some(def::DefFn(def_id, _)) => {
if !ast_util::is_local(def_id) { if !ast_util::is_local(def_id) {
@ -660,7 +660,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
} }
} }
ast::ExprCall(ref callee, ref args) => { ast::ExprCall(ref callee, ref args) => {
let opt_def = cx.tcx().def_map.borrow().find_copy(&callee.id); let opt_def = cx.tcx().def_map.borrow().get(&callee.id).cloned();
match opt_def { match opt_def {
Some(def::DefStruct(_)) => { Some(def::DefStruct(_)) => {
let ety = ty::expr_ty(cx.tcx(), e); let ety = ty::expr_ty(cx.tcx(), e);
@ -702,7 +702,7 @@ pub fn trans_static(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) {
let g = base::get_item_val(ccx, id); let g = base::get_item_val(ccx, id);
// At this point, get_item_val has already translated the // At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type. // constant's initializer to determine its LLVM type.
let v = ccx.static_values().borrow().get_copy(&id); let v = ccx.static_values().borrow()[id].clone();
// boolean SSA values are i1, but they have to be stored in i8 slots, // boolean SSA values are i1, but they have to be stored in i8 slots,
// otherwise some LLVM optimization passes don't work as expected // otherwise some LLVM optimization passes don't work as expected
let v = if llvm::LLVMTypeOf(v) == Type::i1(ccx).to_ref() { let v = if llvm::LLVMTypeOf(v) == Type::i1(ccx).to_ref() {

View file

@ -519,7 +519,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
} }
pub fn get_intrinsic(&self, key: & &'static str) -> ValueRef { pub fn get_intrinsic(&self, key: & &'static str) -> ValueRef {
match self.intrinsics().borrow().find_copy(key) { match self.intrinsics().borrow().get(key).cloned() {
Some(v) => return v, Some(v) => return v,
_ => {} _ => {}
} }

View file

@ -301,11 +301,11 @@ impl TypeMap {
} }
fn find_metadata_for_type(&self, type_: ty::t) -> Option<DIType> { fn find_metadata_for_type(&self, type_: ty::t) -> Option<DIType> {
self.type_to_metadata.find_copy(&type_) self.type_to_metadata.get(&type_).cloned()
} }
fn find_metadata_for_unique_id(&self, unique_type_id: UniqueTypeId) -> Option<DIType> { fn find_metadata_for_unique_id(&self, unique_type_id: UniqueTypeId) -> Option<DIType> {
self.unique_id_to_metadata.find_copy(&unique_type_id) self.unique_id_to_metadata.get(&unique_type_id).cloned()
} }
// Get the string representation of a UniqueTypeId. This method will fail if // Get the string representation of a UniqueTypeId. This method will fail if
@ -341,7 +341,7 @@ impl TypeMap {
// unique vec box (~[]) -> {HEAP_VEC_BOX<:pointee-uid:>} // unique vec box (~[]) -> {HEAP_VEC_BOX<:pointee-uid:>}
// gc box -> {GC_BOX<:pointee-uid:>} // gc box -> {GC_BOX<:pointee-uid:>}
match self.type_to_unique_id.find_copy(&type_) { match self.type_to_unique_id.get(&type_).cloned() {
Some(unique_type_id) => return unique_type_id, Some(unique_type_id) => return unique_type_id,
None => { /* generate one */} None => { /* generate one */}
}; };
@ -499,7 +499,7 @@ impl TypeMap {
// First, find out the 'real' def_id of the type. Items inlined from // First, find out the 'real' def_id of the type. Items inlined from
// other crates have to be mapped back to their source. // other crates have to be mapped back to their source.
let source_def_id = if def_id.krate == ast::LOCAL_CRATE { let source_def_id = if def_id.krate == ast::LOCAL_CRATE {
match cx.external_srcs().borrow().find_copy(&def_id.node) { match cx.external_srcs().borrow().get(&def_id.node).cloned() {
Some(source_def_id) => { Some(source_def_id) => {
// The given def_id identifies the inlined copy of a // The given def_id identifies the inlined copy of a
// type definition, let's take the source of the copy. // type definition, let's take the source of the copy.
@ -853,7 +853,7 @@ pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) {
pat_util::pat_bindings(def_map, &*local.pat, |_, node_id, span, path1| { pat_util::pat_bindings(def_map, &*local.pat, |_, node_id, span, path1| {
let var_ident = path1.node; let var_ident = path1.node;
let datum = match bcx.fcx.lllocals.borrow().find_copy(&node_id) { let datum = match bcx.fcx.lllocals.borrow().get(&node_id).cloned() {
Some(datum) => datum, Some(datum) => datum,
None => { None => {
bcx.sess().span_bug(span, bcx.sess().span_bug(span,
@ -1016,7 +1016,7 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata; let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata;
pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, span, path1| { pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, span, path1| {
let llarg = match bcx.fcx.lllocals.borrow().find_copy(&node_id) { let llarg = match bcx.fcx.lllocals.borrow().get(&node_id).cloned() {
Some(v) => v, Some(v) => v,
None => { None => {
bcx.sess().span_bug(span, bcx.sess().span_bug(span,
@ -1707,7 +1707,7 @@ fn scope_metadata(fcx: &FunctionContext,
let scope_map = &fcx.debug_context let scope_map = &fcx.debug_context
.get_ref(fcx.ccx, error_reporting_span) .get_ref(fcx.ccx, error_reporting_span)
.scope_map; .scope_map;
match scope_map.borrow().find_copy(&node_id) { match scope_map.borrow().get(&node_id).cloned() {
Some(scope_metadata) => scope_metadata, Some(scope_metadata) => scope_metadata,
None => { None => {
let node = fcx.ccx.tcx().map.get(node_id); let node = fcx.ccx.tcx().map.get(node_id);
@ -2417,7 +2417,7 @@ fn prepare_enum_metadata(cx: &CrateContext,
// this cache. // this cache.
let cached_discriminant_type_metadata = debug_context(cx).created_enum_disr_types let cached_discriminant_type_metadata = debug_context(cx).created_enum_disr_types
.borrow() .borrow()
.find_copy(&enum_def_id); .get(&enum_def_id).cloned();
match cached_discriminant_type_metadata { match cached_discriminant_type_metadata {
Some(discriminant_type_metadata) => discriminant_type_metadata, Some(discriminant_type_metadata) => discriminant_type_metadata,
None => { None => {
@ -3987,7 +3987,7 @@ fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> Rc<NamespaceTree
current_key.push(name); current_key.push(name);
let existing_node = debug_context(cx).namespace_map.borrow() let existing_node = debug_context(cx).namespace_map.borrow()
.find_copy(&current_key); .get(&current_key).cloned();
let current_node = match existing_node { let current_node = match existing_node {
Some(existing_node) => existing_node, Some(existing_node) => existing_node,
None => { None => {

View file

@ -184,7 +184,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let mut bcx = bcx; let mut bcx = bcx;
let mut datum = datum; let mut datum = datum;
let adjustment = match bcx.tcx().adjustments.borrow().find_copy(&expr.id) { let adjustment = match bcx.tcx().adjustments.borrow().get(&expr.id).cloned() {
None => { None => {
return DatumBlock::new(bcx, datum); return DatumBlock::new(bcx, datum);
} }
@ -1293,7 +1293,7 @@ pub fn with_field_tys<R>(tcx: &ty::ctxt,
ty.repr(tcx)).as_slice()); ty.repr(tcx)).as_slice());
} }
Some(node_id) => { Some(node_id) => {
let def = tcx.def_map.borrow().get_copy(&node_id); let def = tcx.def_map.borrow()[node_id].clone();
match def { match def {
def::DefVariant(enum_id, variant_id, _) => { def::DefVariant(enum_id, variant_id, _) => {
let variant_info = ty::enum_variant_with_id( let variant_info = ty::enum_variant_with_id(

View file

@ -301,7 +301,7 @@ pub fn trans_static_method_callee(bcx: Block,
fn method_with_name(ccx: &CrateContext, impl_id: ast::DefId, name: ast::Name) fn method_with_name(ccx: &CrateContext, impl_id: ast::DefId, name: ast::Name)
-> ast::DefId { -> ast::DefId {
match ccx.impl_method_cache().borrow().find_copy(&(impl_id, name)) { match ccx.impl_method_cache().borrow().get(&(impl_id, name)).cloned() {
Some(m) => return m, Some(m) => return m,
None => {} None => {}
} }

View file

@ -174,7 +174,7 @@ pub fn type_of_fn_from_ty(cx: &CrateContext, fty: ty::t) -> Type {
// recursive types. For example, enum types rely on this behavior. // recursive types. For example, enum types rely on this behavior.
pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type { pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
match cx.llsizingtypes().borrow().find_copy(&t) { match cx.llsizingtypes().borrow().get(&t).cloned() {
Some(t) => return t, Some(t) => return t,
None => () None => ()
} }

View file

@ -3189,7 +3189,7 @@ pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> Rc<ty::TraitRef> {
} }
pub fn try_node_id_to_type(cx: &ctxt, id: ast::NodeId) -> Option<t> { pub fn try_node_id_to_type(cx: &ctxt, id: ast::NodeId) -> Option<t> {
cx.node_types.borrow().find_copy(&id) cx.node_types.borrow().get(&id).cloned()
} }
pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t { pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t {
@ -4051,7 +4051,7 @@ fn lookup_locally_or_in_crate_store<V:Clone>(
* the crate loading code (and cache the result for the future). * the crate loading code (and cache the result for the future).
*/ */
match map.find_copy(&def_id) { match map.get(&def_id).cloned() {
Some(v) => { return v; } Some(v) => { return v; }
None => { } None => { }
} }
@ -4073,7 +4073,7 @@ pub fn trait_item(cx: &ctxt, trait_did: ast::DefId, idx: uint)
pub fn trait_items(cx: &ctxt, trait_did: ast::DefId) pub fn trait_items(cx: &ctxt, trait_did: ast::DefId)
-> Rc<Vec<ImplOrTraitItem>> { -> Rc<Vec<ImplOrTraitItem>> {
let mut trait_items = cx.trait_items_cache.borrow_mut(); let mut trait_items = cx.trait_items_cache.borrow_mut();
match trait_items.find_copy(&trait_did) { match trait_items.get(&trait_did).cloned() {
Some(trait_items) => trait_items, Some(trait_items) => trait_items,
None => { None => {
let def_ids = ty::trait_item_def_ids(cx, trait_did); let def_ids = ty::trait_item_def_ids(cx, trait_did);
@ -4623,7 +4623,7 @@ pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId, substs: &Subst
// This may change if abstract return types of some sort are // This may change if abstract return types of some sort are
// implemented. // implemented.
assert!(closure_id.krate == ast::LOCAL_CRATE); assert!(closure_id.krate == ast::LOCAL_CRATE);
let capture_mode = tcx.capture_modes.borrow().get_copy(&closure_id.node); let capture_mode = tcx.capture_modes.borrow()[closure_id.node].clone();
match tcx.freevars.borrow().get(&closure_id.node) { match tcx.freevars.borrow().get(&closure_id.node) {
None => vec![], None => vec![],
Some(ref freevars) => { Some(ref freevars) => {
@ -4632,10 +4632,10 @@ pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId, substs: &Subst
let freevar_ty = node_id_to_type(tcx, freevar_def_id.node); let freevar_ty = node_id_to_type(tcx, freevar_def_id.node);
let mut freevar_ty = freevar_ty.subst(tcx, substs); let mut freevar_ty = freevar_ty.subst(tcx, substs);
if capture_mode == ast::CaptureByRef { if capture_mode == ast::CaptureByRef {
let borrow = tcx.upvar_borrow_map.borrow().get_copy(&ty::UpvarId { let borrow = tcx.upvar_borrow_map.borrow()[ty::UpvarId {
var_id: freevar_def_id.node, var_id: freevar_def_id.node,
closure_expr_id: closure_id.node closure_expr_id: closure_id.node
}); }].clone();
freevar_ty = mk_rptr(tcx, borrow.region, ty::mt { freevar_ty = mk_rptr(tcx, borrow.region, ty::mt {
ty: freevar_ty, ty: freevar_ty,
mutbl: borrow.kind.to_mutbl_lossy() mutbl: borrow.kind.to_mutbl_lossy()
@ -4734,7 +4734,7 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t {
fn tcx(&self) -> &ctxt<'tcx> { let TypeNormalizer(c) = *self; c } fn tcx(&self) -> &ctxt<'tcx> { let TypeNormalizer(c) = *self; c }
fn fold_ty(&mut self, t: ty::t) -> ty::t { fn fold_ty(&mut self, t: ty::t) -> ty::t {
match self.tcx().normalized_cache.borrow().find_copy(&t) { match self.tcx().normalized_cache.borrow().get(&t).cloned() {
None => {} None => {}
Some(u) => return u Some(u) => return u
} }
@ -4886,7 +4886,7 @@ pub fn required_region_bounds(tcx: &ctxt,
pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, String> { pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, String> {
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| { tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
tcx.intrinsic_defs.borrow().find_copy(&tydesc_lang_item) tcx.intrinsic_defs.borrow().get(&tydesc_lang_item).cloned()
.expect("Failed to resolve TyDesc") .expect("Failed to resolve TyDesc")
}) })
} }
@ -5037,7 +5037,7 @@ pub fn impl_of_method(tcx: &ctxt, def_id: ast::DefId)
ImplContainer(def_id) => Some(def_id), ImplContainer(def_id) => Some(def_id),
}; };
} }
match tcx.impl_or_trait_items.borrow().find_copy(&def_id) { match tcx.impl_or_trait_items.borrow().get(&def_id).cloned() {
Some(trait_item) => { Some(trait_item) => {
match trait_item.container() { match trait_item.container() {
TraitContainer(_) => None, TraitContainer(_) => None,
@ -5055,7 +5055,7 @@ pub fn trait_of_item(tcx: &ctxt, def_id: ast::DefId) -> Option<ast::DefId> {
if def_id.krate != LOCAL_CRATE { if def_id.krate != LOCAL_CRATE {
return csearch::get_trait_of_item(&tcx.sess.cstore, def_id, tcx); return csearch::get_trait_of_item(&tcx.sess.cstore, def_id, tcx);
} }
match tcx.impl_or_trait_items.borrow().find_copy(&def_id) { match tcx.impl_or_trait_items.borrow().get(&def_id).cloned() {
Some(impl_or_trait_item) => { Some(impl_or_trait_item) => {
match impl_or_trait_item.container() { match impl_or_trait_item.container() {
TraitContainer(def_id) => Some(def_id), TraitContainer(def_id) => Some(def_id),
@ -5444,12 +5444,12 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> {
} }
fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow { fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow {
self.upvar_borrow_map.borrow().get_copy(&upvar_id) self.upvar_borrow_map.borrow()[upvar_id].clone()
} }
fn capture_mode(&self, closure_expr_id: ast::NodeId) fn capture_mode(&self, closure_expr_id: ast::NodeId)
-> ast::CaptureClause { -> ast::CaptureClause {
self.capture_modes.borrow().get_copy(&closure_expr_id) self.capture_modes.borrow()[closure_expr_id].clone()
} }
fn unboxed_closures<'a>(&'a self) fn unboxed_closures<'a>(&'a self)

View file

@ -71,7 +71,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
demand::eqtype(fcx, pat.span, expected, lhs_ty); 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, pat) => {
let const_did = tcx.def_map.borrow().get_copy(&pat.id).def_id(); let const_did = tcx.def_map.borrow()[pat.id].clone().def_id();
let const_pty = ty::lookup_item_type(tcx, const_did); let const_pty = ty::lookup_item_type(tcx, const_did);
fcx.write_ty(pat.id, const_pty.ty); fcx.write_ty(pat.id, const_pty.ty);
demand::suptype(fcx, pat.span, expected, const_pty.ty); demand::suptype(fcx, pat.span, expected, const_pty.ty);
@ -296,7 +296,7 @@ pub fn check_pat_struct(pcx: &pat_ctxt, pat: &ast::Pat,
let fcx = pcx.fcx; let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx; let tcx = pcx.fcx.ccx.tcx;
let def = tcx.def_map.borrow().get_copy(&pat.id); let def = tcx.def_map.borrow()[pat.id].clone();
let def_type = ty::lookup_item_type(tcx, def.def_id()); let def_type = ty::lookup_item_type(tcx, def.def_id());
let (enum_def_id, variant_def_id) = match ty::get(def_type.ty).sty { let (enum_def_id, variant_def_id) = match ty::get(def_type.ty).sty {
ty::ty_struct(struct_def_id, _) => ty::ty_struct(struct_def_id, _) =>
@ -341,7 +341,7 @@ pub fn check_pat_enum(pcx: &pat_ctxt, pat: &ast::Pat,
let fcx = pcx.fcx; let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx; let tcx = pcx.fcx.ccx.tcx;
let def = tcx.def_map.borrow().get_copy(&pat.id); let def = tcx.def_map.borrow()[pat.id].clone();
let enum_def = def.variant_def_ids() let enum_def = def.variant_def_ids()
.map_or_else(|| def.def_id(), |(enum_def, _)| enum_def); .map_or_else(|| def.def_id(), |(enum_def, _)| enum_def);
@ -449,7 +449,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
} }
Vacant(vacant) => { Vacant(vacant) => {
vacant.set(span); vacant.set(span);
field_type_map.find_copy(&field.ident.name) field_type_map.get(&field.ident.name).cloned()
.unwrap_or_else(|| { .unwrap_or_else(|| {
span_err!(tcx.sess, span, E0026, span_err!(tcx.sess, span, E0026,
"struct `{}` does not have a field named `{}`", "struct `{}` does not have a field named `{}`",

View file

@ -309,7 +309,7 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> {
self.tcx().temporary_scope(rvalue_id) self.tcx().temporary_scope(rvalue_id)
} }
fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow { fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow {
self.inh.upvar_borrow_map.borrow().get_copy(&upvar_id) self.inh.upvar_borrow_map.borrow()[upvar_id].clone()
} }
fn capture_mode(&self, closure_expr_id: ast::NodeId) fn capture_mode(&self, closure_expr_id: ast::NodeId)
-> ast::CaptureClause { -> ast::CaptureClause {
@ -450,7 +450,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> {
debug!("Local variable {} is assigned type {}", debug!("Local variable {} is assigned type {}",
self.fcx.pat_to_string(&*local.pat), self.fcx.pat_to_string(&*local.pat),
self.fcx.infcx().ty_to_string( self.fcx.infcx().ty_to_string(
self.fcx.inh.locals.borrow().get_copy(&local.id))); self.fcx.inh.locals.borrow()[local.id].clone()));
visit::walk_local(self, local); visit::walk_local(self, local);
} }
@ -467,7 +467,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> {
debug!("Pattern binding {} is assigned to {} with type {}", debug!("Pattern binding {} is assigned to {} with type {}",
token::get_ident(path1.node), token::get_ident(path1.node),
self.fcx.infcx().ty_to_string( self.fcx.infcx().ty_to_string(
self.fcx.inh.locals.borrow().get_copy(&p.id)), self.fcx.inh.locals.borrow()[p.id].clone()),
var_ty.repr(self.fcx.tcx())); var_ty.repr(self.fcx.tcx()));
} }
_ => {} _ => {}

View file

@ -479,12 +479,12 @@ impl<'fcx, 'tcx> mc::Typer<'tcx> for Rcx<'fcx, 'tcx> {
} }
fn upvar_borrow(&self, id: ty::UpvarId) -> ty::UpvarBorrow { fn upvar_borrow(&self, id: ty::UpvarId) -> ty::UpvarBorrow {
self.fcx.inh.upvar_borrow_map.borrow().get_copy(&id) self.fcx.inh.upvar_borrow_map.borrow()[id].clone()
} }
fn capture_mode(&self, closure_expr_id: ast::NodeId) fn capture_mode(&self, closure_expr_id: ast::NodeId)
-> ast::CaptureClause { -> ast::CaptureClause {
self.tcx().capture_modes.borrow().get_copy(&closure_expr_id) self.tcx().capture_modes.borrow()[closure_expr_id].clone()
} }
fn unboxed_closures<'a>(&'a self) fn unboxed_closures<'a>(&'a self)
@ -871,7 +871,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
}); });
} }
ty::ty_unboxed_closure(_, region, _) => { ty::ty_unboxed_closure(_, region, _) => {
if tcx.capture_modes.borrow().get_copy(&expr.id) == ast::CaptureByRef { if tcx.capture_modes.borrow()[expr.id].clone() == ast::CaptureByRef {
ty::with_freevars(tcx, expr.id, |freevars| { ty::with_freevars(tcx, expr.id, |freevars| {
if !freevars.is_empty() { if !freevars.is_empty() {
// Variables being referenced must be constrained and registered // Variables being referenced must be constrained and registered
@ -896,7 +896,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
}) })
} }
ty::ty_unboxed_closure(..) => { ty::ty_unboxed_closure(..) => {
if tcx.capture_modes.borrow().get_copy(&expr.id) == ast::CaptureByRef { if tcx.capture_modes.borrow()[expr.id].clone() == ast::CaptureByRef {
ty::with_freevars(tcx, expr.id, |freevars| { ty::with_freevars(tcx, expr.id, |freevars| {
propagate_upupvar_borrow_kind(rcx, expr, freevars); propagate_upupvar_borrow_kind(rcx, expr, freevars);
}); });
@ -1847,7 +1847,7 @@ fn link_upvar_borrow_kind_for_nested_closures(rcx: &mut Rcx,
inner_upvar_id, outer_upvar_id); inner_upvar_id, outer_upvar_id);
let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
let inner_borrow = upvar_borrow_map.get_copy(&inner_upvar_id); let inner_borrow = upvar_borrow_map[inner_upvar_id].clone();
match upvar_borrow_map.get_mut(&outer_upvar_id) { match upvar_borrow_map.get_mut(&outer_upvar_id) {
Some(outer_borrow) => { Some(outer_borrow) => {
adjust_upvar_borrow_kind(rcx, outer_upvar_id, outer_borrow, inner_borrow.kind); adjust_upvar_borrow_kind(rcx, outer_upvar_id, outer_borrow, inner_borrow.kind);

View file

@ -317,7 +317,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
fn get_self_type_for_implementation(&self, impl_did: DefId) fn get_self_type_for_implementation(&self, impl_did: DefId)
-> Polytype { -> Polytype {
self.crate_context.tcx.tcache.borrow().get_copy(&impl_did) self.crate_context.tcx.tcache.borrow()[impl_did].clone()
} }
// Converts an implementation in the AST to a vector of items. // Converts an implementation in the AST to a vector of items.
@ -428,7 +428,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
}; };
let impl_items = tcx.impl_items.borrow(); let impl_items = tcx.impl_items.borrow();
let trait_impls = match tcx.trait_impls.borrow().find_copy(&drop_trait) { let trait_impls = match tcx.trait_impls.borrow().get(&drop_trait).cloned() {
None => return, // No types with (new-style) dtors present. None => return, // No types with (new-style) dtors present.
Some(found_impls) => found_impls Some(found_impls) => found_impls
}; };

View file

@ -1520,7 +1520,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
ConstrainVarSubReg(_, region) => { ConstrainVarSubReg(_, region) => {
state.result.push(RegionAndOrigin { state.result.push(RegionAndOrigin {
region: region, region: region,
origin: this.constraints.borrow().get_copy(&edge.data) origin: this.constraints.borrow()[edge.data].clone()
}); });
} }
} }

View file

@ -37,7 +37,6 @@ use super::table::{
}; };
// FIXME(conventions): update capacity management to match other collections (no auto-shrink) // FIXME(conventions): update capacity management to match other collections (no auto-shrink)
// FIXME(conventions): axe find_copy/get_copy in favour of Option.cloned (also implement that)
const INITIAL_LOG2_CAP: uint = 5; const INITIAL_LOG2_CAP: uint = 5;
pub const INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5 pub const INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5
@ -1220,36 +1219,18 @@ fn search_entry_hashed<'a, K: Eq, V>(table: &'a mut RawTable<K,V>, hash: SafeHas
} }
impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> { impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
/// Deprecated: Use `map.get(k).cloned()`.
///
/// Return a copy of the value corresponding to the key. /// Return a copy of the value corresponding to the key.
/// #[deprecated = "Use `map.get(k).cloned()`"]
/// # Example
///
/// ```
/// use std::collections::HashMap;
///
/// let mut map: HashMap<uint, String> = HashMap::new();
/// map.insert(1u, "foo".to_string());
/// let s: String = map.find_copy(&1).unwrap();
/// ```
pub fn find_copy(&self, k: &K) -> Option<V> { pub fn find_copy(&self, k: &K) -> Option<V> {
self.get(k).map(|v| (*v).clone()) self.get(k).cloned()
} }
/// Deprecated: Use `map[k].clone()`.
///
/// Return a copy of the value corresponding to the key. /// Return a copy of the value corresponding to the key.
/// #[deprecated = "Use `map[k].clone()`"]
/// # Panics
///
/// Panics if the key is not present.
///
/// # Example
///
/// ```
/// use std::collections::HashMap;
///
/// let mut map: HashMap<uint, String> = HashMap::new();
/// map.insert(1u, "foo".to_string());
/// let s: String = map.get_copy(&1);
/// ```
pub fn get_copy(&self, k: &K) -> V { pub fn get_copy(&self, k: &K) -> V {
self[*k].clone() self[*k].clone()
} }
@ -1844,6 +1825,7 @@ mod test_map {
} }
#[test] #[test]
#[allow(deprecated)]
fn test_find_copy() { fn test_find_copy() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.get(&1i).is_none()); assert!(m.get(&1i).is_none());

View file

@ -94,7 +94,7 @@ fn lookup_cur_matched_by_matched(r: &TtReader, start: Rc<NamedMatch>) -> Rc<Name
} }
fn lookup_cur_matched(r: &TtReader, name: Ident) -> Option<Rc<NamedMatch>> { fn lookup_cur_matched(r: &TtReader, name: Ident) -> Option<Rc<NamedMatch>> {
let matched_opt = r.interpolations.find_copy(&name); let matched_opt = r.interpolations.get(&name).cloned();
matched_opt.map(|s| lookup_cur_matched_by_matched(r, s)) matched_opt.map(|s| lookup_cur_matched_by_matched(r, s))
} }