Skip to content

Commit eae2652

Browse files
committed
auto merge of #13301 : erickt/rust/remove-refcell-get, r=huonw
`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.
2 parents 46e6194 + 1b6997d commit eae2652

File tree

22 files changed

+105
-118
lines changed

22 files changed

+105
-118
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/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
9090
fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
9191
self.cx.path.borrow_mut().push(i.ident);
9292
debug!("current path: {}",
93-
ast_util::path_name_i(self.cx.path.get().as_slice()));
93+
ast_util::path_name_i(self.cx.path.borrow().as_slice()));
9494

9595
if is_test_fn(&self.cx, i) || is_bench_fn(&self.cx, i) {
9696
match i.node {
@@ -104,7 +104,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
104104
debug!("this is a test function");
105105
let test = Test {
106106
span: i.span,
107-
path: self.cx.path.get(),
107+
path: self.cx.path.borrow().clone(),
108108
bench: is_bench_fn(&self.cx, i),
109109
ignore: is_ignored(&self.cx, i),
110110
should_fail: should_fail(i)

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
13451345
}
13461346

13471347
ebml_w.end_tag();
1348-
return /*bad*/(*index).get();
1348+
return /*bad*/index.borrow().clone();
13491349
}
13501350

13511351

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

13661366
let mut buckets_frozen = Vec::new();
13671367
for bucket in buckets.iter() {
1368-
buckets_frozen.push(@/*bad*/(**bucket).get());
1368+
buckets_frozen.push(@/*bad*/bucket.borrow().clone());
13691369
}
13701370
return buckets_frozen;
13711371
}

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
270270
}
271271

272272
// Seed entry point
273-
match tcx.sess.entry_fn.get() {
273+
match *tcx.sess.entry_fn.borrow() {
274274
Some((id, _)) => worklist.push(id),
275275
None => ()
276276
}

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() {

0 commit comments

Comments
 (0)