Skip to content

Commit 30165e0

Browse files
committed
auto merge of #13052 : sfackler/rust/clean-refcell, r=alexcrichton
These are superfluous now that we have fixed rvalue lifetimes and Deref. I'd also like to kill off `get` and `set`, but that'll be a large change so I want to make sure that we actually want to do that first.
2 parents 092afdb + 1d98fe1 commit 30165e0

File tree

5 files changed

+23
-90
lines changed

5 files changed

+23
-90
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

+12-75
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@ use ty::Unsafe;
2222
/// A mutable memory location that admits only `Pod` data.
2323
pub struct Cell<T> {
2424
priv value: Unsafe<T>,
25-
priv marker1: marker::InvariantType<T>,
26-
priv marker2: marker::NoFreeze,
27-
priv marker3: marker::NoShare,
25+
priv marker1: marker::NoFreeze,
26+
priv marker2: marker::NoShare,
2827
}
2928

3029
impl<T:Pod> Cell<T> {
3130
/// Creates a new `Cell` containing the given value.
3231
pub fn new(value: T) -> Cell<T> {
3332
Cell {
34-
value: Unsafe{value: value, marker1: marker::InvariantType::<T>},
35-
marker1: marker::InvariantType::<T>,
36-
marker2: marker::NoFreeze,
37-
marker3: marker::NoShare,
33+
value: Unsafe::new(value),
34+
marker1: marker::NoFreeze,
35+
marker2: marker::NoShare,
3836
}
3937
}
4038

@@ -75,10 +73,9 @@ impl<T: fmt::Show> fmt::Show for Cell<T> {
7573
pub struct RefCell<T> {
7674
priv value: Unsafe<T>,
7775
priv borrow: BorrowFlag,
78-
priv marker1: marker::InvariantType<T>,
79-
priv marker2: marker::NoFreeze,
80-
priv marker3: marker::NoPod,
81-
priv marker4: marker::NoShare,
76+
priv marker1: marker::NoFreeze,
77+
priv marker2: marker::NoPod,
78+
priv marker3: marker::NoShare,
8279
}
8380

8481
// Values [1, MAX-1] represent the number of `Ref` active
@@ -91,11 +88,10 @@ impl<T> RefCell<T> {
9188
/// Create a new `RefCell` containing `value`
9289
pub fn new(value: T) -> RefCell<T> {
9390
RefCell {
94-
marker1: marker::InvariantType::<T>,
95-
marker2: marker::NoFreeze,
96-
marker3: marker::NoPod,
97-
marker4: marker::NoShare,
98-
value: Unsafe{value: value, marker1: marker::InvariantType::<T>},
91+
marker1: marker::NoFreeze,
92+
marker2: marker::NoPod,
93+
marker3: marker::NoShare,
94+
value: Unsafe::new(value),
9995
borrow: UNUSED,
10096
}
10197
}
@@ -173,28 +169,6 @@ impl<T> RefCell<T> {
173169
}
174170
}
175171

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-
198172
/// Sets the value, replacing what was there.
199173
///
200174
/// # Failure
@@ -372,43 +346,6 @@ mod test {
372346
assert!(x.try_borrow_mut().is_none());
373347
}
374348

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-
412349
#[test]
413350
#[should_fail]
414351
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
@@ -229,10 +229,8 @@ mod tests {
229229
fn test_clone() {
230230
let x = Rc::new(RefCell::new(5));
231231
let y = x.clone();
232-
x.deref().with_mut(|inner| {
233-
*inner = 20;
234-
});
235-
assert_eq!(y.deref().with(|v| *v), 20);
232+
*x.borrow_mut() = 20;
233+
assert_eq!(*y.borrow(), 20);
236234
}
237235

238236
#[test]

0 commit comments

Comments
 (0)