Skip to content

Commit

Permalink
auto merge of #13301 : erickt/rust/remove-refcell-get, r=huonw
Browse files Browse the repository at this point in the history
`RefCell::get` can be a bit surprising, because it actually clones the wrapped value. This removes `RefCell::get` and replaces all the users with `RefCell::borrow()` when it can, and `RefCell::borrow().clone()` when it can't. It removes `RefCell::set` for consistency. This closes #13182.

It also fixes an infinite loop in a test when debugging is on.
  • Loading branch information
bors committed Apr 4, 2014
2 parents 46e6194 + 1b6997d commit eae2652
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 118 deletions.
4 changes: 1 addition & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
let time_passes = sess.time_passes();

sess.building_library.set(session::building_library(&sess.opts, &krate));
sess.crate_types.set(session::collect_crate_types(sess,
krate.attrs
.as_slice()));
*sess.crate_types.borrow_mut() = session::collect_crate_types(sess, krate.attrs.as_slice());

time(time_passes, "gated feature checking", (), |_|
front::feature_gate::check_crate(sess, &krate));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
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 {
Expand All @@ -104,7 +104,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
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)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
}

ebml_w.end_tag();
return /*bad*/(*index).get();
return /*bad*/index.borrow().clone();
}


Expand All @@ -1365,7 +1365,7 @@ fn create_index<T:Clone + Hash + 'static>(

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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ()
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {

fn configure_main(this: &mut EntryContext) {
if this.start_fn.is_some() {
this.session.entry_fn.set(this.start_fn);
*this.session.entry_fn.borrow_mut() = this.start_fn;
this.session.entry_type.set(Some(session::EntryStart));
} else if this.attr_main_fn.is_some() {
this.session.entry_fn.set(this.attr_main_fn);
*this.session.entry_fn.borrow_mut() = this.attr_main_fn;
this.session.entry_type.set(Some(session::EntryMain));
} else if this.main_fn.is_some() {
this.session.entry_fn.set(this.main_fn);
*this.session.entry_fn.borrow_mut() = this.main_fn;
this.session.entry_type.set(Some(session::EntryMain));
} else {
if !this.session.building_library.get() {
Expand Down
Loading

0 comments on commit eae2652

Please sign in to comment.