diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index e39a4a9cc51f2c5d4365d419368ab2bf5e98becc..82e2e3147c93db1b0b39b18f39def54c789028d3 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -90,7 +90,7 @@ fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate { fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> { self.cx.path.borrow_mut().push(i.ident); debug!("current path: {}", - ast_util::path_name_i(self.cx.path.get().as_slice())); + ast_util::path_name_i(self.cx.path.borrow().as_slice())); if is_test_fn(&self.cx, i) || is_bench_fn(&self.cx, i) { match i.node { @@ -104,7 +104,7 @@ fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> { debug!("this is a test function"); let test = Test { span: i.span, - path: self.cx.path.get(), + path: self.cx.path.borrow().clone(), bench: is_bench_fn(&self.cx, i), ignore: is_ignored(&self.cx, i), should_fail: should_fail(i) diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 1da698beb389633b28af45016dba0b8347bbeb37..b7cba60abe6432c58b00bd6ecd16e91fd4a57cd9 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1345,7 +1345,7 @@ fn encode_info_for_items(ecx: &EncodeContext, } ebml_w.end_tag(); - return /*bad*/(*index).get(); + return /*bad*/index.borrow().clone(); } @@ -1365,7 +1365,7 @@ fn create_index( let mut buckets_frozen = Vec::new(); for bucket in buckets.iter() { - buckets_frozen.push(@/*bad*/(**bucket).get()); + buckets_frozen.push(@/*bad*/bucket.borrow().clone()); } return buckets_frozen; } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 1d23218583fc4b9d22effa975d7b2adfa8707c1d..d0bf70ea1c2c10c45b39ca6eaf573d9c1c20f645 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -270,7 +270,7 @@ fn create_and_seed_worklist(tcx: &ty::ctxt, } // Seed entry point - match tcx.sess.entry_fn.get() { + match *tcx.sess.entry_fn.borrow() { Some((id, _)) => worklist.push(id), None => () } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3e1c1828b6c483aa2402f77bfd66863570fb3f78..526ec66800a1614b819696612d78e9223a6a0794 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -385,6 +385,10 @@ struct ImportResolution { type_id: Cell, } +fn get(cell: &RefCell) -> T { + cell.borrow().clone() +} + impl ImportResolution { fn new(id: NodeId, is_public: bool) -> ImportResolution { ImportResolution { @@ -400,8 +404,8 @@ fn new(id: NodeId, is_public: bool) -> ImportResolution { fn target_for_namespace(&self, namespace: Namespace) -> Option { match namespace { - TypeNS => return self.type_target.get(), - ValueNS => return self.value_target.get(), + TypeNS => return self.type_target.borrow().clone(), + ValueNS => return self.value_target.borrow().clone(), } } @@ -546,7 +550,8 @@ fn define_module(&self, // Merges the module with the existing type def or creates a new one. let module_ = @Module::new(parent_link, def_id, kind, external, is_public); - match self.type_def.get() { + let type_def = self.type_def.borrow().clone(); + match type_def { None => { self.type_def.set(Some(TypeNsDef { is_public: is_public, @@ -574,7 +579,8 @@ fn set_module_kind(&self, external: bool, is_public: bool, _sp: Span) { - match self.type_def.get() { + let type_def = self.type_def.borrow().clone(); + match type_def { None => { let module = @Module::new(parent_link, def_id, kind, external, is_public); @@ -609,7 +615,8 @@ fn set_module_kind(&self, /// Records a type definition. fn define_type(&self, def: Def, sp: Span, is_public: bool) { // Merges the type with the existing type def or creates a new one. - match self.type_def.get() { + let type_def = self.type_def.borrow().clone(); + match type_def { None => { self.type_def.set(Some(TypeNsDef { module_def: None, @@ -662,17 +669,17 @@ fn get_module(&self) -> @Module { fn defined_in_namespace(&self, namespace: Namespace) -> bool { match namespace { - TypeNS => return self.type_def.get().is_some(), - ValueNS => return self.value_def.get().is_some() + TypeNS => return self.type_def.borrow().is_some(), + ValueNS => return self.value_def.borrow().is_some() } } fn defined_in_public_namespace(&self, namespace: Namespace) -> bool { match namespace { - TypeNS => match self.type_def.get() { + TypeNS => match *self.type_def.borrow() { Some(def) => def.is_public, None => false }, - ValueNS => match self.value_def.get() { + ValueNS => match *self.value_def.borrow() { Some(def) => def.is_public, None => false } } @@ -681,7 +688,7 @@ fn defined_in_public_namespace(&self, namespace: Namespace) -> bool { fn def_for_namespace(&self, namespace: Namespace) -> Option { match namespace { TypeNS => { - match self.type_def.get() { + match *self.type_def.borrow() { None => None, Some(type_def) => { match type_def.type_def { @@ -702,7 +709,7 @@ fn def_for_namespace(&self, namespace: Namespace) -> Option { } } ValueNS => { - match self.value_def.get() { + match *self.value_def.borrow() { None => None, Some(value_def) => Some(value_def.def) } @@ -714,13 +721,13 @@ fn span_for_namespace(&self, namespace: Namespace) -> Option { if self.defined_in_namespace(namespace) { match namespace { TypeNS => { - match self.type_def.get() { + match *self.type_def.borrow() { None => None, Some(type_def) => type_def.type_span } } ValueNS => { - match self.value_def.get() { + match *self.value_def.borrow() { None => None, Some(value_def) => value_def.value_span } @@ -1620,7 +1627,8 @@ fn handle_external_def(&mut self, match def { DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) | DefTy(def_id) => { - match child_name_bindings.type_def.get() { + let type_def = child_name_bindings.type_def.borrow().clone(); + match type_def { Some(TypeNsDef { module_def: Some(module_def), .. }) => { debug!("(building reduced graph for external crate) \ already created module"); @@ -1812,7 +1820,8 @@ fn build_reduced_graph_for_external_crate_def(&mut self, // Process the static methods. First, // create the module. let type_module; - match child_name_bindings.type_def.get() { + let type_def = child_name_bindings.type_def.borrow().clone(); + match type_def { Some(TypeNsDef { module_def: Some(module_def), .. @@ -2421,7 +2430,7 @@ fn get_binding(this: &mut Resolver, match type_result { BoundResult(target_module, name_bindings) => { debug!("(resolving single import) found type target: {:?}", - {name_bindings.type_def.get().unwrap().type_def}); + { name_bindings.type_def.borrow().clone().unwrap().type_def }); import_resolution.type_target.set( Some(Target::new(target_module, name_bindings))); import_resolution.type_id.set(directive.id); @@ -2433,8 +2442,8 @@ fn get_binding(this: &mut Resolver, } } - if import_resolution.value_target.get().is_none() && - import_resolution.type_target.get().is_none() { + if import_resolution.value_target.borrow().is_none() && + import_resolution.type_target.borrow().is_none() { let msg = format!("unresolved import: there is no \ `{}` in `{}`", token::get_ident(source), @@ -2452,7 +2461,7 @@ fn get_binding(this: &mut Resolver, // record what this import resolves to for later uses in documentation, // this may resolve to either a value or a type, but for documentation // purposes it's good enough to just favor one over the other. - let value_private = match import_resolution.value_target.get() { + let value_private = match *import_resolution.value_target.borrow() { Some(target) => { let def = target.bindings.def_for_namespace(ValueNS).unwrap(); self.def_map.borrow_mut().insert(directive.id, def); @@ -2463,7 +2472,7 @@ fn get_binding(this: &mut Resolver, // _exists is false. None => None, }; - let type_private = match import_resolution.type_target.get() { + let type_private = match *import_resolution.type_target.borrow() { Some(target) => { let def = target.bindings.def_for_namespace(TypeNS).unwrap(); self.def_map.borrow_mut().insert(directive.id, def); @@ -2513,7 +2522,7 @@ fn resolve_glob_import(&mut self, for (ident, target_import_resolution) in import_resolutions.iter() { debug!("(resolving glob import) writing module resolution \ {:?} into `{}`", - target_import_resolution.type_target.get().is_none(), + target_import_resolution.type_target.borrow().is_none(), self.module_to_str(module_)); if !target_import_resolution.is_public.get() { @@ -2529,9 +2538,9 @@ fn resolve_glob_import(&mut self, let new_import_resolution = @ImportResolution::new(id, is_public); new_import_resolution.value_target.set( - target_import_resolution.value_target.get()); + get(&target_import_resolution.value_target)); new_import_resolution.type_target.set( - target_import_resolution.type_target.get()); + get(&target_import_resolution.type_target)); import_resolutions.insert (*ident, new_import_resolution); @@ -2540,7 +2549,7 @@ fn resolve_glob_import(&mut self, // Merge the two import resolutions at a finer-grained // level. - match target_import_resolution.value_target.get() { + match *target_import_resolution.value_target.borrow() { None => { // Continue. } @@ -2549,7 +2558,7 @@ fn resolve_glob_import(&mut self, Some(value_target)); } } - match target_import_resolution.type_target.get() { + match *target_import_resolution.type_target.borrow() { None => { // Continue. } @@ -2692,7 +2701,7 @@ fn resolve_module_path_from_root(&mut self, Success((target, used_proxy)) => { // Check to see whether there are type bindings, and, if // so, whether there is a module within. - match target.bindings.type_def.get() { + match *target.bindings.type_def.borrow() { Some(type_def) => { match type_def.module_def { None => { @@ -3004,7 +3013,7 @@ fn resolve_module_in_lexical_scope(&mut self, match resolve_result { Success((target, _)) => { let bindings = &*target.bindings; - match bindings.type_def.get() { + match *bindings.type_def.borrow() { Some(type_def) => { match type_def.module_def { None => { @@ -4526,8 +4535,8 @@ fn resolve_bare_identifier_pattern(&mut self, name: Ident) debug!("(resolve bare identifier pattern) succeeded in \ finding {} at {:?}", token::get_ident(name), - target.bindings.value_def.get()); - match target.bindings.value_def.get() { + target.bindings.value_def.borrow()); + match *target.bindings.value_def.borrow() { None => { fail!("resolved name in the value namespace to a \ set of name bindings with no def?!"); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 133634a9e791cf94dfb36144d1cfb9bb48fff279..2f4163e8296f47b7cee6cbe4820102b005661ebd 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1128,7 +1128,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t) llvm::LLVMGetParam(fcx.llfn, 0) } else { let lloutputtype = type_of::type_of(fcx.ccx, output_type); - let bcx = fcx.entry_bcx.get().unwrap(); + let bcx = fcx.entry_bcx.borrow().clone().unwrap(); Alloca(bcx, lloutputtype, "__make_return_pointer") } } @@ -1399,7 +1399,7 @@ pub fn trans_closure(ccx: &CrateContext, // Create the first basic block in the function and keep a handle on it to // pass to finish_fn later. - let bcx_top = fcx.entry_bcx.get().unwrap(); + let bcx_top = fcx.entry_bcx.borrow().clone().unwrap(); let mut bcx = bcx_top; let block_ty = node_id_type(bcx, body.id); @@ -1547,7 +1547,7 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext, let arg_datums = create_datums_for_fn_args(&fcx, arg_tys.as_slice()); - let bcx = fcx.entry_bcx.get().unwrap(); + let bcx = fcx.entry_bcx.borrow().clone().unwrap(); if !type_is_zero_size(fcx.ccx, result_ty) { let repr = adt::represent_type(ccx, result_ty); @@ -1752,7 +1752,7 @@ pub fn register_fn_llvmty(ccx: &CrateContext, } pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool { - match sess.entry_fn.get() { + match *sess.entry_fn.borrow() { Some((entry_id, _)) => node_id == entry_id, None => false } diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 1d2e1d0232c348a411d4dcaf39a41daf86811b57..4671e21170e869bea654b35e18d8cd5c2db5ab51 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -464,7 +464,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, let arena = TypedArena::new(); let fcx = new_fn_ctxt(ccx, llfn, -1, true, f.sig.output, None, None, &arena); init_function(&fcx, true, f.sig.output, None); - let bcx = fcx.entry_bcx.get().unwrap(); + let bcx = fcx.entry_bcx.borrow().clone().unwrap(); let args = create_datums_for_fn_args(&fcx, ty::ty_fn_args(closure_ty) diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index da9d06b9a752613940d9a056bef6246e562eb361..87234ce3683531907f91b501a7c71a700cc54d77 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -463,7 +463,7 @@ fn make_generic_glue(ccx: &CrateContext, // llfn is expected be declared to take a parameter of the appropriate // type, so we don't need to explicitly cast the function parameter. - let bcx = fcx.entry_bcx.get().unwrap(); + let bcx = fcx.entry_bcx.borrow().clone().unwrap(); let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, fcx.arg_pos(0) as c_uint) }; let bcx = helper(bcx, llrawptr0, t); finish_fn(&fcx, bcx); diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index 95c0b08d400eac12b1537b1a523b0d7336943f97..28a39718e7fb6a32b6a79d300cd04cd941e89d5e 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -199,7 +199,7 @@ fn count_zeros_intrinsic(bcx: &Block, name: &'static str) { set_always_inline(fcx.llfn); - let mut bcx = fcx.entry_bcx.get().unwrap(); + let mut bcx = fcx.entry_bcx.borrow().clone().unwrap(); let first_real_arg = fcx.arg_pos(0u); let name = token::get_ident(item.ident); diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 7ad9010829c7fc8755419cff13266789fdad25ce..41d8b05c6eae1f58af32cd30bf0355c28f82729d 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -300,7 +300,7 @@ pub fn visit_ty(&mut self, t: ty::t) { // llvm::LLVMGetParam(llfdecl, fcx.arg_pos(0u) as c_uint) }; - let bcx = fcx.entry_bcx.get().unwrap(); + let bcx = fcx.entry_bcx.borrow().clone().unwrap(); let arg = BitCast(bcx, arg, llptrty); let ret = adt::trans_get_discr(bcx, repr, arg, Some(Type::i64(ccx))); Store(bcx, ret, fcx.llretptr.get().unwrap()); diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 5752a928358831ca541e9e541e3720f60f554d14..bbf2e60dfe325dd5b36f5912e5988538c1fd5acf 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2209,8 +2209,8 @@ fn check_expr_fn(fcx: &FnCtxt, fcx.write_ty(expr.id, fty); let (inherited_purity, id) = - ty::determine_inherited_purity((fcx.ps.get().purity, - fcx.ps.get().def), + ty::determine_inherited_purity((fcx.ps.borrow().purity, + fcx.ps.borrow().def), (purity, expr.id), sigil); diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index e67a83cd9269db5eac4d092094a2d82e54483b74..c8613fd70652ee60e8f5909de52c6c4029ea69de 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -398,7 +398,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { expr.repr(rcx.fcx.tcx()), rcx.repeating_scope); let method_call = MethodCall::expr(expr.id); - let has_method_map = rcx.fcx.inh.method_map.get().contains_key(&method_call); + let has_method_map = rcx.fcx.inh.method_map.borrow().contains_key(&method_call); // Check any autoderefs or autorefs that appear. for &adjustment in rcx.fcx.inh.adjustments.borrow().find(&expr.id).iter() { @@ -498,7 +498,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { ast::ExprUnary(ast::UnDeref, base) => { // For *a, the lifetime of a must enclose the deref let method_call = MethodCall::expr(expr.id); - let base_ty = match rcx.fcx.inh.method_map.get().find(&method_call) { + let base_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) { Some(method) => { constrain_call(rcx, None, expr, Some(base), [], true); ty::ty_fn_ret(method.ty) @@ -852,7 +852,7 @@ fn constrain_autoderefs(rcx: &mut Rcx, i, derefs); let method_call = MethodCall::autoderef(deref_expr.id, i as u32); - derefd_ty = match rcx.fcx.inh.method_map.get().find(&method_call) { + derefd_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) { Some(method) => { // Treat overloaded autoderefs as if an AutoRef adjustment // was applied on the base type, as that is always the case. diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 83ca7ea7dfbd4f46f218db98a424f047807d9942..9c947fb3360e455014adeb480934f15f3fad864e 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -1286,6 +1286,6 @@ fn num_to_str(counter: uint) -> ~str { } fn get_generated_lifetimes(&self) -> Vec { - self.generated.get() + self.generated.borrow().clone() } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index fb82bf9968afc1b80ceb4cfa4178c905003bb134..edfd9b43865842bda2f55949845782f3d340013e 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -431,7 +431,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt, fn check_for_entry_fn(ccx: &CrateCtxt) { let tcx = ccx.tcx; if !tcx.sess.building_library.get() { - match tcx.sess.entry_fn.get() { + match *tcx.sess.entry_fn.borrow() { Some((id, sp)) => match tcx.sess.entry_type.get() { Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp), Some(session::EntryStart) => check_start_fn_ty(ccx, id, sp), diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index eb114e895103aca49f89a243df8ea2b898284ebc..ec6994728f70666ab6dfb4e158210b49515363e1 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -176,21 +176,9 @@ pub fn set(&self, value: T) { } } -impl RefCell { - /// Returns a copy of the contained value. - /// - /// # Failure - /// - /// Fails if the value is currently mutably borrowed. - #[inline] - pub fn get(&self) -> T { - (*self.borrow()).clone() - } -} - impl Clone for RefCell { fn clone(&self) -> RefCell { - RefCell::new(self.get()) + RefCell::new(self.borrow().clone()) } } @@ -216,7 +204,7 @@ fn drop(&mut self) { impl<'b, T> Deref for Ref<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { - unsafe{ &*self.parent.value.get() } + unsafe { &*self.parent.value.get() } } } @@ -236,14 +224,14 @@ fn drop(&mut self) { impl<'b, T> Deref for RefMut<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { - unsafe{ &*self.parent.value.get() } + unsafe { &*self.parent.value.get() } } } impl<'b, T> DerefMut for RefMut<'b, T> { #[inline] fn deref_mut<'a>(&'a mut self) -> &'a mut T { - unsafe{ &mut *self.parent.value.get() } + unsafe { &mut *self.parent.value.get() } } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index be1c87ba7886ccb2e96264ae60cce78855ec1046..ce2c1378fc1a2ceb3579a8beb0cbe72f7e0eaa96 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -651,7 +651,8 @@ struct R { impl ::ops::Drop for R { fn drop(&mut self) { let ii = &*self.i; - ii.set(ii.get() + 1); + let i = ii.borrow().clone(); + ii.set(i + 1); } } @@ -667,7 +668,7 @@ fn R(i: Rc>) -> R { let opt = Some(x); let _y = opt.unwrap(); } - assert_eq!(i.get(), 1); + assert_eq!(*i.borrow(), 1); } #[test] diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index e7e0bf1bd60fadc3496bab69ecd5d21218521e92..e61510f2ef2d8e8136fa284c8d9cf516705e8751 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -21,5 +21,5 @@ // the unused ty param is necessary so this gets monomorphized pub fn request(req: &header_map) { - let _x = (**((**req.get(&~"METHOD")).clone()).get().get(0)).clone(); + let _x = (**((**req.get(&~"METHOD")).clone()).borrow().clone().get(0)).clone(); }