Skip to content

Commit 3961957

Browse files
committed
std: Remove RefCell::set()
1 parent 7bcfe2e commit 3961957

File tree

10 files changed

+39
-53
lines changed

10 files changed

+39
-53
lines changed

src/librustc/driver/driver.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
212212
let time_passes = sess.time_passes();
213213

214214
sess.building_library.set(session::building_library(&sess.opts, &krate));
215-
sess.crate_types.set(session::collect_crate_types(sess,
216-
krate.attrs
217-
.as_slice()));
215+
*sess.crate_types.borrow_mut() = session::collect_crate_types(sess, krate.attrs.as_slice());
218216

219217
time(time_passes, "gated feature checking", (), |_|
220218
front::feature_gate::check_crate(sess, &krate));

src/librustc/middle/entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
123123

124124
fn configure_main(this: &mut EntryContext) {
125125
if this.start_fn.is_some() {
126-
this.session.entry_fn.set(this.start_fn);
126+
*this.session.entry_fn.borrow_mut() = this.start_fn;
127127
this.session.entry_type.set(Some(session::EntryStart));
128128
} else if this.attr_main_fn.is_some() {
129-
this.session.entry_fn.set(this.attr_main_fn);
129+
*this.session.entry_fn.borrow_mut() = this.attr_main_fn;
130130
this.session.entry_type.set(Some(session::EntryMain));
131131
} else if this.main_fn.is_some() {
132-
this.session.entry_fn.set(this.main_fn);
132+
*this.session.entry_fn.borrow_mut() = this.main_fn;
133133
this.session.entry_type.set(Some(session::EntryMain));
134134
} else {
135135
if !this.session.building_library.get() {

src/librustc/middle/resolve.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -553,20 +553,20 @@ impl NameBindings {
553553
let type_def = self.type_def.borrow().clone();
554554
match type_def {
555555
None => {
556-
self.type_def.set(Some(TypeNsDef {
556+
*self.type_def.borrow_mut() = Some(TypeNsDef {
557557
is_public: is_public,
558558
module_def: Some(module_),
559559
type_def: None,
560560
type_span: Some(sp)
561-
}));
561+
});
562562
}
563563
Some(type_def) => {
564-
self.type_def.set(Some(TypeNsDef {
564+
*self.type_def.borrow_mut() = Some(TypeNsDef {
565565
is_public: is_public,
566566
module_def: Some(module_),
567567
type_span: Some(sp),
568568
type_def: type_def.type_def
569-
}));
569+
});
570570
}
571571
}
572572
}
@@ -584,12 +584,12 @@ impl NameBindings {
584584
None => {
585585
let module = @Module::new(parent_link, def_id, kind,
586586
external, is_public);
587-
self.type_def.set(Some(TypeNsDef {
587+
*self.type_def.borrow_mut() = Some(TypeNsDef {
588588
is_public: is_public,
589589
module_def: Some(module),
590590
type_def: None,
591591
type_span: None,
592-
}))
592+
});
593593
}
594594
Some(type_def) => {
595595
match type_def.module_def {
@@ -599,12 +599,12 @@ impl NameBindings {
599599
kind,
600600
external,
601601
is_public);
602-
self.type_def.set(Some(TypeNsDef {
602+
*self.type_def.borrow_mut() = Some(TypeNsDef {
603603
is_public: is_public,
604604
module_def: Some(module),
605605
type_def: type_def.type_def,
606606
type_span: None,
607-
}))
607+
});
608608
}
609609
Some(module_def) => module_def.kind.set(kind),
610610
}
@@ -618,31 +618,31 @@ impl NameBindings {
618618
let type_def = self.type_def.borrow().clone();
619619
match type_def {
620620
None => {
621-
self.type_def.set(Some(TypeNsDef {
621+
*self.type_def.borrow_mut() = Some(TypeNsDef {
622622
module_def: None,
623623
type_def: Some(def),
624624
type_span: Some(sp),
625625
is_public: is_public,
626-
}));
626+
});
627627
}
628628
Some(type_def) => {
629-
self.type_def.set(Some(TypeNsDef {
629+
*self.type_def.borrow_mut() = Some(TypeNsDef {
630630
type_def: Some(def),
631631
type_span: Some(sp),
632632
module_def: type_def.module_def,
633633
is_public: is_public,
634-
}));
634+
});
635635
}
636636
}
637637
}
638638

639639
/// Records a value definition.
640640
fn define_value(&self, def: Def, sp: Span, is_public: bool) {
641-
self.value_def.set(Some(ValueNsDef {
641+
*self.value_def.borrow_mut() = Some(ValueNsDef {
642642
def: def,
643643
value_span: Some(sp),
644644
is_public: is_public,
645-
}));
645+
});
646646
}
647647

648648
/// Returns the module node if applicable.
@@ -2417,8 +2417,8 @@ impl<'a> Resolver<'a> {
24172417
match value_result {
24182418
BoundResult(target_module, name_bindings) => {
24192419
debug!("(resolving single import) found value target");
2420-
import_resolution.value_target.set(
2421-
Some(Target::new(target_module, name_bindings)));
2420+
*import_resolution.value_target.borrow_mut() =
2421+
Some(Target::new(target_module, name_bindings));
24222422
import_resolution.value_id.set(directive.id);
24232423
value_used_public = name_bindings.defined_in_public_namespace(ValueNS);
24242424
}
@@ -2431,8 +2431,8 @@ impl<'a> Resolver<'a> {
24312431
BoundResult(target_module, name_bindings) => {
24322432
debug!("(resolving single import) found type target: {:?}",
24332433
{ name_bindings.type_def.borrow().clone().unwrap().type_def });
2434-
import_resolution.type_target.set(
2435-
Some(Target::new(target_module, name_bindings)));
2434+
*import_resolution.type_target.borrow_mut() =
2435+
Some(Target::new(target_module, name_bindings));
24362436
import_resolution.type_id.set(directive.id);
24372437
type_used_public = name_bindings.defined_in_public_namespace(TypeNS);
24382438
}
@@ -2537,10 +2537,10 @@ impl<'a> Resolver<'a> {
25372537
// Simple: just copy the old import resolution.
25382538
let new_import_resolution =
25392539
@ImportResolution::new(id, is_public);
2540-
new_import_resolution.value_target.set(
2541-
get(&target_import_resolution.value_target));
2542-
new_import_resolution.type_target.set(
2543-
get(&target_import_resolution.type_target));
2540+
*new_import_resolution.value_target.borrow_mut() =
2541+
get(&target_import_resolution.value_target);
2542+
*new_import_resolution.type_target.borrow_mut() =
2543+
get(&target_import_resolution.type_target);
25442544

25452545
import_resolutions.insert
25462546
(*ident, new_import_resolution);
@@ -2554,17 +2554,15 @@ impl<'a> Resolver<'a> {
25542554
// Continue.
25552555
}
25562556
Some(value_target) => {
2557-
dest_import_resolution.value_target.set(
2558-
Some(value_target));
2557+
*dest_import_resolution.value_target.borrow_mut() = Some(value_target);
25592558
}
25602559
}
25612560
match *target_import_resolution.type_target.borrow() {
25622561
None => {
25632562
// Continue.
25642563
}
25652564
Some(type_target) => {
2566-
dest_import_resolution.type_target.set(
2567-
Some(type_target));
2565+
*dest_import_resolution.type_target.borrow_mut() = Some(type_target);
25682566
}
25692567
}
25702568
dest_import_resolution.is_public.set(is_public);
@@ -2636,14 +2634,14 @@ impl<'a> Resolver<'a> {
26362634
// Merge the child item into the import resolution.
26372635
if name_bindings.defined_in_public_namespace(ValueNS) {
26382636
debug!("(resolving glob import) ... for value target");
2639-
dest_import_resolution.value_target.set(
2640-
Some(Target::new(containing_module, name_bindings)));
2637+
*dest_import_resolution.value_target.borrow_mut() =
2638+
Some(Target::new(containing_module, name_bindings));
26412639
dest_import_resolution.value_id.set(id);
26422640
}
26432641
if name_bindings.defined_in_public_namespace(TypeNS) {
26442642
debug!("(resolving glob import) ... for type target");
2645-
dest_import_resolution.type_target.set(
2646-
Some(Target::new(containing_module, name_bindings)));
2643+
*dest_import_resolution.type_target.borrow_mut() =
2644+
Some(Target::new(containing_module, name_bindings));
26472645
dest_import_resolution.type_id.set(id);
26482646
}
26492647
dest_import_resolution.is_public.set(is_public);

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ pub fn init_function<'a>(
12091209
param_substs: Option<@param_substs>) {
12101210
let entry_bcx = fcx.new_temp_block("entry-block");
12111211

1212-
fcx.entry_bcx.set(Some(entry_bcx));
1212+
*fcx.entry_bcx.borrow_mut() = Some(entry_bcx);
12131213

12141214
// Use a dummy instruction as the insertion point for all allocas.
12151215
// This is later removed in FunctionContext::cleanup.

src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'a> FunctionContext<'a> {
322322
.unwrap());
323323
}
324324
// Remove the cycle between fcx and bcx, so memory can be freed
325-
self.entry_bcx.set(None);
325+
*self.entry_bcx.borrow_mut() = None;
326326
}
327327

328328
pub fn get_llreturn(&self) -> BasicBlockRef {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3333,7 +3333,7 @@ pub fn check_block_with_expected(fcx: &FnCtxt,
33333333
};
33343334
});
33353335

3336-
fcx.ps.set(prev);
3336+
*fcx.ps.borrow_mut() = prev;
33373337
}
33383338

33393339
pub fn check_const(ccx: &CrateCtxt,

src/libstd/cell.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,6 @@ impl<T> RefCell<T> {
164164
None => fail!("RefCell<T> already borrowed")
165165
}
166166
}
167-
168-
/// Sets the value, replacing what was there.
169-
///
170-
/// # Failure
171-
///
172-
/// Fails if the value is currently borrowed.
173-
#[inline]
174-
pub fn set(&self, value: T) {
175-
*self.borrow_mut() = value;
176-
}
177167
}
178168

179169
impl<T: Clone> Clone for RefCell<T> {

src/libstd/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ mod tests {
652652
fn drop(&mut self) {
653653
let ii = &*self.i;
654654
let i = ii.borrow().clone();
655-
ii.set(i + 1);
655+
*ii.borrow_mut() = i + 1;
656656
}
657657
}
658658

src/test/run-pass/cycle-collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum taggy {
1919

2020
fn f() {
2121
let a_box = @RefCell::new(nil);
22-
a_box.set(cons(a_box));
22+
*a_box.borrow_mut() = cons(a_box);
2323
}
2424

2525
pub fn main() {

src/test/run-pass/issue-980.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Pointy {
2323

2424
pub fn main() {
2525
let m = @RefCell::new(Pointy { x : no_pointy });
26-
m.set(Pointy {
26+
*m.borrow_mut() = Pointy {
2727
x: yes_pointy(m)
28-
});
28+
};
2929
}

0 commit comments

Comments
 (0)