]> git.lizzy.rs Git - rust.git/commitdiff
Remove RefCell::{with, with_mut}
authorSteven Fackler <sfackler@gmail.com>
Fri, 21 Mar 2014 02:55:52 +0000 (19:55 -0700)
committerSteven Fackler <sfackler@gmail.com>
Fri, 21 Mar 2014 02:55:52 +0000 (19:55 -0700)
These are superfluous now that we have fixed rvalue lifetimes and Deref.

src/librustc/driver/driver.rs
src/librustc/metadata/cstore.rs
src/libstd/cell.rs
src/libstd/gc.rs
src/libstd/rc.rs

index ae9cd37fe69286f21abf4b1ec4022bde323b0f64..4676ada1727eb3206d2c2fbd3c8fda5e462ba087 100644 (file)
@@ -313,10 +313,10 @@ pub fn phase_3_run_analysis_passes(sess: Session,
     time(time_passes, "looking for entry point", (),
          |_| middle::entry::find_entry_point(&sess, krate, &ast_map));
 
-    sess.macro_registrar_fn.with_mut(|r| *r =
+    *sess.macro_registrar_fn.borrow_mut() =
         time(time_passes, "looking for macro registrar", (), |_|
             syntax::ext::registrar::find_macro_registrar(
-                sess.diagnostic(), krate)));
+                sess.diagnostic(), krate));
 
     let freevars = time(time_passes, "freevar finding", (), |_|
                         freevars::annotate_freevars(def_map, krate));
index c1d3ad76260aef83406962fafc6c684c6cb01f21..f1089891ea5fb464a497c57f287367ceaee22301 100644 (file)
@@ -135,11 +135,11 @@ pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
     }
 
     pub fn reset(&self) {
-        self.metas.with_mut(|s| s.clear());
-        self.extern_mod_crate_map.with_mut(|s| s.clear());
-        self.used_crate_sources.with_mut(|s| s.clear());
-        self.used_libraries.with_mut(|s| s.clear());
-        self.used_link_args.with_mut(|s| s.clear());
+        self.metas.borrow_mut().clear();
+        self.extern_mod_crate_map.borrow_mut().clear();
+        self.used_crate_sources.borrow_mut().clear();
+        self.used_libraries.borrow_mut().clear();
+        self.used_link_args.borrow_mut().clear();
     }
 
     // This method is used when generating the command line to pass through to
index 5733504c0d189b2727cbf4fea9afba14eacec1b3..df1c29ded6e0eb10beadaf0bcff43b5c6855a965 100644 (file)
@@ -173,28 +173,6 @@ pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
         }
     }
 
-    /// Immutably borrows the wrapped value and applies `blk` to it.
-    ///
-    /// # Failure
-    ///
-    /// Fails if the value is currently mutably borrowed.
-    #[inline]
-    pub fn with<U>(&self, blk: |&T| -> U) -> U {
-        let ptr = self.borrow();
-        blk(ptr.get())
-    }
-
-    /// Mutably borrows the wrapped value and applies `blk` to it.
-    ///
-    /// # Failure
-    ///
-    /// Fails if the value is currently borrowed.
-    #[inline]
-    pub fn with_mut<U>(&self, blk: |&mut T| -> U) -> U {
-        let mut ptr = self.borrow_mut();
-        blk(ptr.get())
-    }
-
     /// Sets the value, replacing what was there.
     ///
     /// # Failure
@@ -372,43 +350,6 @@ fn double_borrow_single_release_no_borrow_mut() {
         assert!(x.try_borrow_mut().is_none());
     }
 
-    #[test]
-    fn with_ok() {
-        let x = RefCell::new(0);
-        assert_eq!(1, x.with(|x| *x+1));
-    }
-
-    #[test]
-    #[should_fail]
-    fn mut_borrow_with() {
-        let x = RefCell::new(0);
-        let _b1 = x.borrow_mut();
-        x.with(|x| *x+1);
-    }
-
-    #[test]
-    fn borrow_with() {
-        let x = RefCell::new(0);
-        let _b1 = x.borrow();
-        assert_eq!(1, x.with(|x| *x+1));
-    }
-
-    #[test]
-    fn with_mut_ok() {
-        let x = RefCell::new(0);
-        x.with_mut(|x| *x += 1);
-        let b = x.borrow();
-        assert_eq!(1, *b.get());
-    }
-
-    #[test]
-    #[should_fail]
-    fn borrow_with_mut() {
-        let x = RefCell::new(0);
-        let _b = x.borrow();
-        x.with_mut(|x| *x += 1);
-    }
-
     #[test]
     #[should_fail]
     fn discard_doesnt_unborrow() {
index 907a2d21b695d0e431687984991a8e3875be2455..7fb23d77f3c6cb94b90c257a5e37ba0249e3f4e0 100644 (file)
@@ -87,10 +87,8 @@ mod tests {
     fn test_clone() {
         let x = Gc::new(RefCell::new(5));
         let y = x.clone();
-        x.borrow().with_mut(|inner| {
-            *inner = 20;
-        });
-        assert_eq!(y.borrow().with(|x| *x), 20);
+        *x.borrow().borrow_mut() = 20;
+        assert_eq!(*y.borrow().borrow(), 20);
     }
 
     #[test]
index 605cbd3f28a12fba59272d1f8d8ec3914841055d..c41e3b01f4732d583da6881ca84ed39eec7d2a37 100644 (file)
@@ -198,10 +198,8 @@ mod tests {
     fn test_clone() {
         let x = Rc::new(RefCell::new(5));
         let y = x.clone();
-        x.deref().with_mut(|inner| {
-            *inner = 20;
-        });
-        assert_eq!(y.deref().with(|v| *v), 20);
+        *x.borrow_mut() = 20;
+        assert_eq!(*y.borrow(), 20);
     }
 
     #[test]