Skip to content

Commit 181875c

Browse files
committed
Remove RefCell::{with, with_mut}
These are superfluous now that we have fixed rvalue lifetimes and Deref.
1 parent 6eae7df commit 181875c

File tree

5 files changed

+11
-74
lines changed

5 files changed

+11
-74
lines changed

src/librustc/driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ pub fn phase_3_run_analysis_passes(sess: Session,
313313
time(time_passes, "looking for entry point", (),
314314
|_| middle::entry::find_entry_point(&sess, krate, &ast_map));
315315

316-
sess.macro_registrar_fn.with_mut(|r| *r =
316+
*sess.macro_registrar_fn.borrow_mut() =
317317
time(time_passes, "looking for macro registrar", (), |_|
318318
syntax::ext::registrar::find_macro_registrar(
319-
sess.diagnostic(), krate)));
319+
sess.diagnostic(), krate));
320320

321321
let freevars = time(time_passes, "freevar finding", (), |_|
322322
freevars::annotate_freevars(def_map, krate));

src/librustc/metadata/cstore.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ impl CStore {
135135
}
136136

137137
pub fn reset(&self) {
138-
self.metas.with_mut(|s| s.clear());
139-
self.extern_mod_crate_map.with_mut(|s| s.clear());
140-
self.used_crate_sources.with_mut(|s| s.clear());
141-
self.used_libraries.with_mut(|s| s.clear());
142-
self.used_link_args.with_mut(|s| s.clear());
138+
self.metas.borrow_mut().clear();
139+
self.extern_mod_crate_map.borrow_mut().clear();
140+
self.used_crate_sources.borrow_mut().clear();
141+
self.used_libraries.borrow_mut().clear();
142+
self.used_link_args.borrow_mut().clear();
143143
}
144144

145145
// This method is used when generating the command line to pass through to

src/libstd/cell.rs

-59
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,6 @@ impl<T> RefCell<T> {
173173
}
174174
}
175175

176-
/// Immutably borrows the wrapped value and applies `blk` to it.
177-
///
178-
/// # Failure
179-
///
180-
/// Fails if the value is currently mutably borrowed.
181-
#[inline]
182-
pub fn with<U>(&self, blk: |&T| -> U) -> U {
183-
let ptr = self.borrow();
184-
blk(ptr.get())
185-
}
186-
187-
/// Mutably borrows the wrapped value and applies `blk` to it.
188-
///
189-
/// # Failure
190-
///
191-
/// Fails if the value is currently borrowed.
192-
#[inline]
193-
pub fn with_mut<U>(&self, blk: |&mut T| -> U) -> U {
194-
let mut ptr = self.borrow_mut();
195-
blk(ptr.get())
196-
}
197-
198176
/// Sets the value, replacing what was there.
199177
///
200178
/// # Failure
@@ -372,43 +350,6 @@ mod test {
372350
assert!(x.try_borrow_mut().is_none());
373351
}
374352

375-
#[test]
376-
fn with_ok() {
377-
let x = RefCell::new(0);
378-
assert_eq!(1, x.with(|x| *x+1));
379-
}
380-
381-
#[test]
382-
#[should_fail]
383-
fn mut_borrow_with() {
384-
let x = RefCell::new(0);
385-
let _b1 = x.borrow_mut();
386-
x.with(|x| *x+1);
387-
}
388-
389-
#[test]
390-
fn borrow_with() {
391-
let x = RefCell::new(0);
392-
let _b1 = x.borrow();
393-
assert_eq!(1, x.with(|x| *x+1));
394-
}
395-
396-
#[test]
397-
fn with_mut_ok() {
398-
let x = RefCell::new(0);
399-
x.with_mut(|x| *x += 1);
400-
let b = x.borrow();
401-
assert_eq!(1, *b.get());
402-
}
403-
404-
#[test]
405-
#[should_fail]
406-
fn borrow_with_mut() {
407-
let x = RefCell::new(0);
408-
let _b = x.borrow();
409-
x.with_mut(|x| *x += 1);
410-
}
411-
412353
#[test]
413354
#[should_fail]
414355
fn discard_doesnt_unborrow() {

src/libstd/gc.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ mod tests {
8787
fn test_clone() {
8888
let x = Gc::new(RefCell::new(5));
8989
let y = x.clone();
90-
x.borrow().with_mut(|inner| {
91-
*inner = 20;
92-
});
93-
assert_eq!(y.borrow().with(|x| *x), 20);
90+
*x.borrow().borrow_mut() = 20;
91+
assert_eq!(*y.borrow().borrow(), 20);
9492
}
9593

9694
#[test]

src/libstd/rc.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ mod tests {
198198
fn test_clone() {
199199
let x = Rc::new(RefCell::new(5));
200200
let y = x.clone();
201-
x.deref().with_mut(|inner| {
202-
*inner = 20;
203-
});
204-
assert_eq!(y.deref().with(|v| *v), 20);
201+
*x.borrow_mut() = 20;
202+
assert_eq!(*y.borrow(), 20);
205203
}
206204

207205
#[test]

0 commit comments

Comments
 (0)