]> git.lizzy.rs Git - rust.git/commitdiff
Rename unwrap functions to into_inner
authorAlex Crichton <alex@alexcrichton.com>
Thu, 20 Nov 2014 17:23:43 +0000 (09:23 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 23 Nov 2014 23:26:53 +0000 (15:26 -0800)
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename
non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all
`unwrap` methods are retained as `#[deprecated]` for the near future. To update
code rename `unwrap` method calls to `into_inner`.

[rfc]: https://github.com/rust-lang/rfcs/pull/430
[breaking-change]

Closes #13159
cc #19091

14 files changed:
src/libcollections/vec.rs
src/libcore/cell.rs
src/librustc/lint/context.rs
src/librustc_llvm/lib.rs
src/librustc_trans/back/write.rs
src/librustrt/c_str.rs
src/libstd/c_vec.rs
src/libstd/io/buffered.rs
src/libstd/io/mem.rs
src/libstd/io/tempfile.rs
src/libstd/io/util.rs
src/libstd/sync/future.rs
src/libstd/task.rs
src/libtest/lib.rs

index acb91f3edcf6310c000c72d3f44f057eed26bc1e..a3291e01942f1325a555e44d839f3cd0ddca0116 100644 (file)
@@ -1248,7 +1248,7 @@ pub struct MoveItems<T> {
 impl<T> MoveItems<T> {
     #[inline]
     /// Drops all items that have not yet been moved and returns the empty vector.
-    pub fn unwrap(mut self) -> Vec<T> {
+    pub fn into_inner(mut self) -> Vec<T> {
         unsafe {
             for _x in self { }
             let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self;
@@ -1256,6 +1256,10 @@ pub fn unwrap(mut self) -> Vec<T> {
             Vec { ptr: allocation, cap: cap, len: 0 }
         }
     }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> Vec<T> { self.into_inner() }
 }
 
 impl<T> Iterator<T> for MoveItems<T> {
index c4d0bec83eaa76661e7386c0db00a98602ff25ec..587bb4cb110e1af178643297f81d058533bba548 100644 (file)
@@ -256,15 +256,19 @@ pub fn new(value: T) -> RefCell<T> {
     }
 
     /// Consumes the `RefCell`, returning the wrapped value.
-    #[unstable = "may be renamed, depending on global conventions"]
-    pub fn unwrap(self) -> T {
+    #[unstable = "recently renamed per RFC 430"]
+    pub fn into_inner(self) -> T {
         // Since this function takes `self` (the `RefCell`) by value, the
         // compiler statically verifies that it is not currently borrowed.
         // Therefore the following assertion is just a `debug_assert!`.
         debug_assert!(self.borrow.get() == UNUSED);
-        unsafe{self.value.unwrap()}
+        unsafe { self.value.into_inner() }
     }
 
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> T { self.into_inner() }
+
     /// Attempts to immutably borrow the wrapped value.
     ///
     /// The borrow lasts until the returned `Ref` exits scope. Multiple
@@ -518,5 +522,9 @@ pub unsafe fn get(&self) -> *mut T { &self.value as *const T as *mut T }
     #[inline]
     #[unstable = "conventions around the name `unwrap` are still under \
                   development"]
-    pub unsafe fn unwrap(self) -> T { self.value }
+    pub unsafe fn into_inner(self) -> T { self.value }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub unsafe fn unwrap(self) -> T { self.into_inner() }
 }
index 1af65d184ed31b0e79db30fac5b037857914f943..1b2b044b49afec6a3b17c58e6c109945d5d65f36 100644 (file)
@@ -827,5 +827,5 @@ pub fn check_crate(tcx: &ty::ctxt,
     }
 
     tcx.sess.abort_if_errors();
-    *tcx.node_lint_levels.borrow_mut() = cx.node_levels.unwrap();
+    *tcx.node_lint_levels.borrow_mut() = cx.node_levels.into_inner();
 }
index 02235669c0958fbe5ad4c4f1c45723a5cdff64b4..d67d0fa59ae28899c5cec1faa385de71537982be 100644 (file)
@@ -2148,7 +2148,7 @@ pub enum RustString_opaque {}
 pub fn build_string(f: |RustStringRef|) -> Option<String> {
     let mut buf = RefCell::new(Vec::new());
     f(&mut buf as RustStringRepr as RustStringRef);
-    String::from_utf8(buf.unwrap()).ok()
+    String::from_utf8(buf.into_inner()).ok()
 }
 
 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
index 47bba3e4327c1e7c40895884b3099fd982a00e4c..b923bb076c3016a730620651e2c59933cc0218a5 100644 (file)
@@ -899,7 +899,7 @@ fn run_work_multithreaded(sess: &Session,
 
     let mut panicked = false;
     for future in futures.into_iter() {
-        match future.unwrap() {
+        match future.into_inner() {
             Ok(()) => {},
             Err(_) => {
                 panicked = true;
index bfcd290628248000cb42f44404eccb6d424223be..d62b1485db33adc4c015b88616833fe421d4671a 100644 (file)
@@ -254,11 +254,15 @@ pub fn iter<'a>(&'a self) -> CChars<'a> {
     ///
     /// Prefer `.as_ptr()` when just retrieving a pointer to the
     /// string data, as that does not relinquish ownership.
-    pub unsafe fn unwrap(mut self) -> *const libc::c_char {
+    pub unsafe fn into_inner(mut self) -> *const libc::c_char {
         self.owns_buffer_ = false;
         self.buf
     }
 
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub unsafe fn unwrap(self) -> *const libc::c_char { self.into_inner() }
+
     /// Return the number of bytes in the CString (not including the NUL
     /// terminator).
     #[inline]
index 1267d7411cc2e986566a9adf90c04f8c2758404f..1f94d7b4fa6117ae6ccc09e5f87ca53dc3586ff7 100644 (file)
@@ -138,11 +138,15 @@ pub fn get_mut<'a>(&'a mut self, ofs: uint) -> Option<&'a mut T> {
     /// Note that if you want to access the underlying pointer without
     /// cancelling the destructor, you can simply call `transmute` on the return
     /// value of `get(0)`.
-    pub unsafe fn unwrap(mut self) -> *mut T {
+    pub unsafe fn into_inner(mut self) -> *mut T {
         self.dtor = None;
         self.base
     }
 
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub unsafe fn unwrap(self) -> *mut T { self.into_inner() }
+
     /// Returns the number of items in this vector.
     pub fn len(&self) -> uint { self.len }
 
index 25e85f33aa56512ab90bcb70cf52066e7f15439b..148323762c8b8710869cf490f134db410df460b1 100644 (file)
@@ -83,7 +83,11 @@ pub fn get_ref<'a>(&'a self) -> &'a R { &self.inner }
     /// Unwraps this `BufferedReader`, returning the underlying reader.
     ///
     /// Note that any leftover data in the internal buffer is lost.
-    pub fn unwrap(self) -> R { self.inner }
+    pub fn into_inner(self) -> R { self.inner }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> R { self.into_inner() }
 }
 
 impl<R: Reader> Buffer for BufferedReader<R> {
@@ -180,11 +184,15 @@ pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.as_ref().unwrap() }
     /// Unwraps this `BufferedWriter`, returning the underlying writer.
     ///
     /// The buffer is flushed before returning the writer.
-    pub fn unwrap(mut self) -> W {
+    pub fn into_inner(mut self) -> W {
         // FIXME(#12628): is panicking the right thing to do if flushing panicks?
         self.flush_buf().unwrap();
         self.inner.take().unwrap()
     }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> W { self.into_inner() }
 }
 
 impl<W: Writer> Writer for BufferedWriter<W> {
@@ -244,7 +252,11 @@ pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.get_ref() }
     /// Unwraps this `LineBufferedWriter`, returning the underlying writer.
     ///
     /// The internal buffer is flushed before returning the writer.
-    pub fn unwrap(self) -> W { self.inner.unwrap() }
+    pub fn into_inner(self) -> W { self.inner.into_inner() }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> W { self.into_inner() }
 }
 
 impl<W: Writer> Writer for LineBufferedWriter<W> {
@@ -341,10 +353,14 @@ pub fn get_ref<'a>(&'a self) -> &'a S {
     ///
     /// The internal buffer is flushed before returning the stream. Any leftover
     /// data in the read buffer is lost.
-    pub fn unwrap(self) -> S {
+    pub fn into_inner(self) -> S {
         let InternalBufferedWriter(w) = self.inner.inner;
-        w.unwrap()
+        w.into_inner()
     }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> S { self.into_inner() }
 }
 
 impl<S: Stream> Buffer for BufferedStream<S> {
index 21de6c2013d2c8e667cfc61eeffcc84c3f628f5e..f27951f263da2a736e2b5dedf071bb729149874d 100644 (file)
@@ -62,7 +62,7 @@ fn write(&mut self, buf: &[u8]) -> IoResult<()> {
 /// let mut w = MemWriter::new();
 /// w.write(&[0, 1, 2]);
 ///
-/// assert_eq!(w.unwrap(), vec!(0, 1, 2));
+/// assert_eq!(w.into_inner(), vec!(0, 1, 2));
 /// ```
 #[deprecated = "use the Vec<u8> Writer implementation directly"]
 #[deriving(Clone)]
@@ -95,7 +95,11 @@ pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() }
 
     /// Unwraps this `MemWriter`, returning the underlying buffer
     #[inline]
-    pub fn unwrap(self) -> Vec<u8> { self.buf }
+    pub fn into_inner(self) -> Vec<u8> { self.buf }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> Vec<u8> { self.into_inner() }
 }
 
 impl Writer for MemWriter {
@@ -150,7 +154,11 @@ pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() }
 
     /// Unwraps this `MemReader`, returning the underlying buffer
     #[inline]
-    pub fn unwrap(self) -> Vec<u8> { self.buf }
+    pub fn into_inner(self) -> Vec<u8> { self.buf }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> Vec<u8> { self.into_inner() }
 }
 
 impl Reader for MemReader {
index a232231733d8bacd58efddb620f8b89a78c3c647..4788ba79b7fa8451f684d8e614b5c9a90bb6d541 100644 (file)
@@ -73,11 +73,15 @@ pub fn new(suffix: &str) -> IoResult<TempDir> {
     /// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper.
     /// This discards the wrapper so that the automatic deletion of the
     /// temporary directory is prevented.
-    pub fn unwrap(self) -> Path {
+    pub fn into_inner(self) -> Path {
         let mut tmpdir = self;
         tmpdir.path.take().unwrap()
     }
 
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> Path { self.into_inner() }
+
     /// Access the wrapped `std::path::Path` to the temporary directory.
     pub fn path<'a>(&'a self) -> &'a Path {
         self.path.as_ref().unwrap()
index 4d491beb87ba3727b2c9379c3bf1c8ef24fbf0ab..8e0cd6608164a2cee1688e8767d138f6b7d70772 100644 (file)
@@ -28,7 +28,11 @@ pub fn new(r: R, limit: uint) -> LimitReader<R> {
     }
 
     /// Consumes the `LimitReader`, returning the underlying `Reader`.
-    pub fn unwrap(self) -> R { self.inner }
+    pub fn into_inner(self) -> R { self.inner }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner"]
+    pub fn unwrap(self) -> R { self.into_inner() }
 
     /// Returns the number of bytes that can be read before the `LimitReader`
     /// will return EOF.
@@ -207,10 +211,14 @@ pub fn new(r: R, w: W) -> TeeReader<R, W> {
 
     /// Consumes the `TeeReader`, returning the underlying `Reader` and
     /// `Writer`.
-    pub fn unwrap(self) -> (R, W) {
+    pub fn into_inner(self) -> (R, W) {
         let TeeReader { reader, writer } = self;
         (reader, writer)
     }
+
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner"]
+    pub fn unwrap(self) -> (R, W) { self.into_inner() }
 }
 
 impl<R: Reader, W: Writer> Reader for TeeReader<R, W> {
index e37d1f83877967767e80eabd5d4cb9e8de2593be..567f809df7e52d271cfbe3e2fd844260ec1f0937 100644 (file)
@@ -54,7 +54,7 @@ pub fn get(&mut self) -> A {
 
 impl<A> Future<A> {
     /// Gets the value from this future, forcing evaluation.
-    pub fn unwrap(mut self) -> A {
+    pub fn into_inner(mut self) -> A {
         self.get_ref();
         let state = replace(&mut self.state, Evaluating);
         match state {
@@ -63,6 +63,10 @@ pub fn unwrap(mut self) -> A {
         }
     }
 
+    /// Deprecated, use into_inner() instead
+    #[deprecated = "renamed to into_inner()"]
+    pub fn unwrap(self) -> A { self.into_inner() }
+
     pub fn get_ref<'a>(&'a mut self) -> &'a A {
         /*!
         * Executes the future's closure and then returns a reference
index 4f5f47e980c0dbc4bed01abe8303c3b11b447e80..c852b4efbd8a3f85d6dadda38d1f07d77efd5322 100644 (file)
@@ -197,7 +197,7 @@ pub fn try_future<T:Send>(self, f: proc():Send -> T)
     /// completes or panics. Equivalent to `.try_future(f).unwrap()`.
     #[unstable = "Error type may change."]
     pub fn try<T:Send>(self, f: proc():Send -> T) -> Result<T, Box<Any + Send>> {
-        self.try_future(f).unwrap()
+        self.try_future(f).into_inner()
     }
 }
 
index 0ea8ca84ef8bd0f245e5f6525516f0da1d2465ee..9acb12c56d93fef0bccd6aeb415371aacbf51b86 100644 (file)
@@ -1059,7 +1059,7 @@ fn run_test_inner(desc: TestDesc,
             let result_future = task.try_future(testfn);
 
             let stdout = reader.read_to_end().unwrap().into_iter().collect();
-            let task_result = result_future.unwrap();
+            let task_result = result_future.into_inner();
             let test_result = calc_result(&desc, task_result.is_ok());
             monitor_ch.send((desc.clone(), test_result, stdout));
         })