Skip to content

Commit cdc18b9

Browse files
committed
Remove Rc's borrow method to avoid conflicts with RefCell's borrow in Rc<RefCell<T>>.
1 parent 12b2607 commit cdc18b9

File tree

28 files changed

+59
-76
lines changed

28 files changed

+59
-76
lines changed

src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ let x = Rc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
16871687
let y = x.clone(); // a new owner
16881688
let z = x; // this moves `x` into `z`, rather than creating a new owner
16891689

1690-
assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1690+
assert!(*z == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
16911691

16921692
// the variable is mutable, but not the contents of the box
16931693
let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);

src/libarena/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ struct Chunk {
5151
}
5252
impl Chunk {
5353
fn capacity(&self) -> uint {
54-
self.data.borrow().borrow().get().capacity()
54+
self.data.deref().borrow().get().capacity()
5555
}
5656

5757
unsafe fn as_ptr(&self) -> *u8 {
58-
self.data.borrow().borrow().get().as_ptr()
58+
self.data.deref().borrow().get().as_ptr()
5959
}
6060
}
6161

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10811081
ebml_w.tag(c::tag_table_capture_map, |ebml_w| {
10821082
ebml_w.id(id);
10831083
ebml_w.tag(c::tag_table_val, |ebml_w| {
1084-
ebml_w.emit_from_vec(cap_vars.borrow().as_slice(),
1084+
ebml_w.emit_from_vec(cap_vars.deref().as_slice(),
10851085
|ebml_w, cap_var| {
10861086
cap_var.encode(ebml_w);
10871087
})

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ impl<'a> CheckLoanCtxt<'a> {
716716
span: Span) {
717717
let capture_map = self.bccx.capture_map.borrow();
718718
let cap_vars = capture_map.get().get(&closure_id);
719-
for cap_var in cap_vars.borrow().iter() {
719+
for cap_var in cap_vars.deref().iter() {
720720
let var_id = ast_util::def_id_of_def(cap_var.def).node;
721721
let var_path = @LpVar(var_id);
722722
self.check_if_path_is_moved(closure_id, span,

src/librustc/middle/borrowck/gather_loans/gather_moves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn gather_captures(bccx: &BorrowckCtxt,
4949
closure_expr: &ast::Expr) {
5050
let capture_map = bccx.capture_map.borrow();
5151
let captured_vars = capture_map.get().get(&closure_expr.id);
52-
for captured_var in captured_vars.borrow().iter() {
52+
for captured_var in captured_vars.deref().iter() {
5353
match captured_var.mode {
5454
moves::CapMove => {
5555
let cmt = bccx.cat_captured_var(closure_expr.id,

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'a> GatherLoanCtxt<'a> {
406406
closure_expr: &ast::Expr) {
407407
let capture_map = self.bccx.capture_map.borrow();
408408
let captured_vars = capture_map.get().get(&closure_expr.id);
409-
for captured_var in captured_vars.borrow().iter() {
409+
for captured_var in captured_vars.deref().iter() {
410410
match captured_var.mode {
411411
moves::CapCopy | moves::CapMove => { continue; }
412412
moves::CapRef => { }

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
512512
match lit.node {
513513
LitStr(ref s, _) => const_str((*s).clone()),
514514
LitBinary(ref data) => {
515-
const_binary(Rc::new(data.borrow().iter().map(|x| *x).collect()))
515+
const_binary(Rc::new(data.deref().iter().map(|x| *x).collect()))
516516
}
517517
LitChar(n) => const_uint(n as u64),
518518
LitInt(n, _) => const_int(n),

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
298298
}
299299
}
300300
};
301-
let type_param_defs = type_param_defs.borrow();
301+
let type_param_defs = type_param_defs.deref();
302302
if ts.len() != type_param_defs.len() {
303303
// Fail earlier to make debugging easier
304304
fail!("internal error: in kind::check_expr, length \

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: &Expr, this: @IrMaps) {
505505
let capture_map = this.capture_map.borrow();
506506
let cvs = capture_map.get().get(&expr.id);
507507
let mut call_caps = Vec::new();
508-
for cv in cvs.borrow().iter() {
508+
for cv in cvs.deref().iter() {
509509
match moves::moved_variable_node_id_from_def(cv.def) {
510510
Some(rv) => {
511511
let cv_ln = this.add_live_node(FreeVarNode(cv.span));

src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<T:Subst> Subst for Rc<T> {
142142
fn subst_spanned(&self, tcx: ty::ctxt,
143143
substs: &ty::substs,
144144
span: Option<Span>) -> Rc<T> {
145-
Rc::new(self.borrow().subst_spanned(tcx, substs, span))
145+
Rc::new(self.deref().subst_spanned(tcx, substs, span))
146146
}
147147
}
148148

src/librustc/middle/trans/closure.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,21 +397,13 @@ pub fn trans_expr_fn<'a>(
397397
// set an inline hint for all closures
398398
set_inline_hint(llfn);
399399

400-
let cap_vars = {
401-
let capture_map = ccx.maps.capture_map.borrow();
402-
capture_map.get().get_copy(&id)
403-
};
400+
let cap_vars = ccx.maps.capture_map.borrow().get().get_copy(&id);
404401
let ClosureResult {llbox, cdata_ty, bcx} =
405-
build_closure(bcx, cap_vars.borrow().as_slice(), sigil);
402+
build_closure(bcx, cap_vars.deref().as_slice(), sigil);
406403
trans_closure(ccx, decl, body, llfn,
407404
bcx.fcx.param_substs, id,
408405
[], ty::ty_fn_ret(fty),
409-
|bcx| {
410-
load_environment(bcx,
411-
cdata_ty,
412-
cap_vars.borrow().as_slice(),
413-
sigil)
414-
});
406+
|bcx| load_environment(bcx, cdata_ty, cap_vars.deref().as_slice(), sigil));
415407
fill_fn_pair(bcx, dest_addr, llfn, llbox);
416408

417409
bcx

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
7676
ast::LitBool(b) => C_bool(b),
7777
ast::LitNil => C_nil(),
7878
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
79-
ast::LitBinary(ref data) => {
80-
C_binary_slice(cx, data.borrow().as_slice())
81-
}
79+
ast::LitBinary(ref data) => C_binary_slice(cx, data.deref().as_slice()),
8280
}
8381
}
8482

src/librustc/middle/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,13 +1014,13 @@ pub struct Generics {
10141014

10151015
impl Generics {
10161016
pub fn has_type_params(&self) -> bool {
1017-
!self.type_param_defs.borrow().is_empty()
1017+
!self.type_param_defs.deref().is_empty()
10181018
}
10191019
pub fn type_param_defs<'a>(&'a self) -> &'a [TypeParameterDef] {
1020-
self.type_param_defs.borrow().as_slice()
1020+
self.type_param_defs.deref().as_slice()
10211021
}
10221022
pub fn region_param_defs<'a>(&'a self) -> &'a [RegionParameterDef] {
1023-
self.region_param_defs.borrow().as_slice()
1023+
self.region_param_defs.deref().as_slice()
10241024
}
10251025
}
10261026

src/librustc/middle/typeck/check/method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ impl<'a> LookupContext<'a> {
10301030
let m_regions =
10311031
self.fcx.infcx().region_vars_for_defs(
10321032
self.expr.span,
1033-
candidate.method_ty.generics.region_param_defs.borrow().as_slice());
1033+
candidate.method_ty.generics.region_param_defs.deref().as_slice());
10341034
for &r in m_regions.iter() {
10351035
all_regions.push(r);
10361036
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::Item) {
569569
fn_tpt.generics.type_param_defs(),
570570
[],
571571
[],
572-
fn_tpt.generics.region_param_defs.borrow().as_slice(),
572+
fn_tpt.generics.region_param_defs.deref().as_slice(),
573573
body.id);
574574

575575
check_bare_fn(ccx, decl, body, it.id, fn_tpt.ty, param_env);
@@ -3732,7 +3732,7 @@ pub fn instantiate_path(fcx: @FnCtxt,
37323732
nsupplied = num_supplied_regions));
37333733
}
37343734

3735-
fcx.infcx().region_vars_for_defs(span, tpt.generics.region_param_defs.borrow().as_slice())
3735+
fcx.infcx().region_vars_for_defs(span, tpt.generics.region_param_defs.deref().as_slice())
37363736
};
37373737
let regions = ty::NonerasedRegions(regions);
37383738

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,15 +709,13 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
709709
debug!("vtable resolution on parameter bounds for method call {}",
710710
ex.repr(fcx.tcx()));
711711
let type_param_defs = ty::method_call_type_param_defs(cx.tcx, method.origin);
712-
if has_trait_bounds(type_param_defs.borrow().as_slice()) {
712+
if has_trait_bounds(type_param_defs.deref().as_slice()) {
713713
let substs = fcx.method_ty_substs(ex.id);
714714
let vcx = fcx.vtable_context();
715-
let vtbls = lookup_vtables(&vcx,
716-
&location_info_for_expr(ex),
717-
type_param_defs.borrow()
715+
let vtbls = lookup_vtables(&vcx, &location_info_for_expr(ex),
716+
type_param_defs.deref()
718717
.as_slice(),
719-
&substs,
720-
is_early);
718+
&substs, is_early);
721719
if !is_early {
722720
insert_vtables(fcx, ex.id, vtbls);
723721
}
@@ -829,7 +827,7 @@ pub fn resolve_impl(tcx: ty::ctxt,
829827
pub fn trans_resolve_method(tcx: ty::ctxt, id: ast::NodeId,
830828
substs: &ty::substs) -> Option<vtable_res> {
831829
let generics = ty::lookup_item_type(tcx, ast_util::local_def(id)).generics;
832-
let type_param_defs = generics.type_param_defs.borrow();
830+
let type_param_defs = generics.type_param_defs.deref();
833831
if has_trait_bounds(type_param_defs.as_slice()) {
834832
let vcx = VtableContext {
835833
infcx: &infer::new_infer_ctxt(tcx),

src/librustc/middle/typeck/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
342342
let mut new_type_param_defs = Vec::new();
343343
let substd_type_param_defs =
344344
trait_ty_generics.type_param_defs.subst(tcx, &substs);
345-
new_type_param_defs.push_all(substd_type_param_defs.borrow()
345+
new_type_param_defs.push_all(substd_type_param_defs.deref()
346346
.as_slice());
347347

348348
// add in the "self" type parameter
@@ -360,7 +360,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
360360

361361
// add in the type parameters from the method
362362
let substd_type_param_defs = m.generics.type_param_defs.subst(tcx, &substs);
363-
new_type_param_defs.push_all(substd_type_param_defs.borrow()
363+
new_type_param_defs.push_all(substd_type_param_defs.deref()
364364
.as_slice());
365365

366366
debug!("static method {} type_param_defs={} ty={}, substs={}",

src/librustdoc/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ impl ToSource for syntax::codemap::Span {
11921192
fn lit_to_str(lit: &ast::Lit) -> ~str {
11931193
match lit.node {
11941194
ast::LitStr(ref st, _) => st.get().to_owned(),
1195-
ast::LitBinary(ref data) => format!("{:?}", data.borrow().as_slice()),
1195+
ast::LitBinary(ref data) => format!("{:?}", data.deref().as_slice()),
11961196
ast::LitChar(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
11971197
ast::LitInt(i, _t) => i.to_str(),
11981198
ast::LitUint(u, _t) => u.to_str(),

src/librustuv/idle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ mod test {
113113
fn call(&mut self) {
114114
let task = match *self {
115115
MyCallback(ref rc, n) => {
116-
let mut slot = rc.borrow().borrow_mut();
116+
let mut slot = rc.deref().borrow_mut();
117117
match *slot.get() {
118118
(ref mut task, ref mut val) => {
119119
*val = n;
@@ -140,7 +140,7 @@ mod test {
140140
fn sleep(chan: &Chan) -> uint {
141141
let task: ~Task = Local::take();
142142
task.deschedule(1, |task| {
143-
let mut slot = chan.borrow().borrow_mut();
143+
let mut slot = chan.deref().borrow_mut();
144144
match *slot.get() {
145145
(ref mut slot, _) => {
146146
assert!(slot.is_none());
@@ -150,7 +150,7 @@ mod test {
150150
Ok(())
151151
});
152152

153-
let slot = chan.borrow().borrow();
153+
let slot = chan.deref().borrow();
154154
match *slot.get() { (_, n) => n }
155155
}
156156

src/libserialize/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
388388
impl<S:Encoder,T:Encodable<S>> Encodable<S> for Rc<T> {
389389
#[inline]
390390
fn encode(&self, s: &mut S) {
391-
self.borrow().encode(s)
391+
self.deref().encode(s)
392392
}
393393
}
394394

src/libstd/hash/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
use container::Container;
6767
use io::Writer;
6868
use iter::Iterator;
69+
use ops::Deref;
6970
use option::{Option, Some, None};
7071
use rc::Rc;
7172
use str::{Str, StrSlice};
@@ -246,7 +247,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for @T {
246247
impl<S: Writer, T: Hash<S>> Hash<S> for Rc<T> {
247248
#[inline]
248249
fn hash(&self, state: &mut S) {
249-
self.borrow().hash(state);
250+
self.deref().hash(state);
250251
}
251252
}
252253

src/libstd/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ mod tests {
503503
#[unsafe_destructor]
504504
impl ::ops::Drop for R {
505505
fn drop(&mut self) {
506-
let ii = self.i.borrow();
506+
let ii = self.i.deref();
507507
ii.set(ii.get() + 1);
508508
}
509509
}
@@ -520,7 +520,7 @@ mod tests {
520520
let opt = Some(x);
521521
let _y = opt.unwrap();
522522
}
523-
assert_eq!(i.borrow().get(), 1);
523+
assert_eq!(i.deref().get(), 1);
524524
}
525525

526526
#[test]

0 commit comments

Comments
 (0)