Skip to content

Commit f6cb58c

Browse files
committed
auto merge of #19149 : alexcrichton/rust/issue-19091, r=aturon
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]: rust-lang/rfcs#430 [breaking-change] cc #19091
2 parents 0c1d853 + f1f6c12 commit f6cb58c

File tree

14 files changed

+84
-24
lines changed

14 files changed

+84
-24
lines changed

src/libcollections/vec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1248,14 +1248,18 @@ pub struct MoveItems<T> {
12481248
impl<T> MoveItems<T> {
12491249
#[inline]
12501250
/// Drops all items that have not yet been moved and returns the empty vector.
1251-
pub fn unwrap(mut self) -> Vec<T> {
1251+
pub fn into_inner(mut self) -> Vec<T> {
12521252
unsafe {
12531253
for _x in self { }
12541254
let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self;
12551255
mem::forget(self);
12561256
Vec { ptr: allocation, cap: cap, len: 0 }
12571257
}
12581258
}
1259+
1260+
/// Deprecated, use into_inner() instead
1261+
#[deprecated = "renamed to into_inner()"]
1262+
pub fn unwrap(self) -> Vec<T> { self.into_inner() }
12591263
}
12601264

12611265
impl<T> Iterator<T> for MoveItems<T> {

src/libcore/cell.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,19 @@ impl<T> RefCell<T> {
256256
}
257257

258258
/// Consumes the `RefCell`, returning the wrapped value.
259-
#[unstable = "may be renamed, depending on global conventions"]
260-
pub fn unwrap(self) -> T {
259+
#[unstable = "recently renamed per RFC 430"]
260+
pub fn into_inner(self) -> T {
261261
// Since this function takes `self` (the `RefCell`) by value, the
262262
// compiler statically verifies that it is not currently borrowed.
263263
// Therefore the following assertion is just a `debug_assert!`.
264264
debug_assert!(self.borrow.get() == UNUSED);
265-
unsafe{self.value.unwrap()}
265+
unsafe { self.value.into_inner() }
266266
}
267267

268+
/// Deprecated, use into_inner() instead
269+
#[deprecated = "renamed to into_inner()"]
270+
pub fn unwrap(self) -> T { self.into_inner() }
271+
268272
/// Attempts to immutably borrow the wrapped value.
269273
///
270274
/// The borrow lasts until the returned `Ref` exits scope. Multiple
@@ -518,5 +522,9 @@ impl<T> UnsafeCell<T> {
518522
#[inline]
519523
#[unstable = "conventions around the name `unwrap` are still under \
520524
development"]
521-
pub unsafe fn unwrap(self) -> T { self.value }
525+
pub unsafe fn into_inner(self) -> T { self.value }
526+
527+
/// Deprecated, use into_inner() instead
528+
#[deprecated = "renamed to into_inner()"]
529+
pub unsafe fn unwrap(self) -> T { self.into_inner() }
522530
}

src/librustc/lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,5 +827,5 @@ pub fn check_crate(tcx: &ty::ctxt,
827827
}
828828

829829
tcx.sess.abort_if_errors();
830-
*tcx.node_lint_levels.borrow_mut() = cx.node_levels.unwrap();
830+
*tcx.node_lint_levels.borrow_mut() = cx.node_levels.into_inner();
831831
}

src/librustc_llvm/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
21482148
pub fn build_string(f: |RustStringRef|) -> Option<String> {
21492149
let mut buf = RefCell::new(Vec::new());
21502150
f(&mut buf as RustStringRepr as RustStringRef);
2151-
String::from_utf8(buf.unwrap()).ok()
2151+
String::from_utf8(buf.into_inner()).ok()
21522152
}
21532153

21542154
pub unsafe fn twine_to_string(tr: TwineRef) -> String {

src/librustc_trans/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ fn run_work_multithreaded(sess: &Session,
899899

900900
let mut panicked = false;
901901
for future in futures.into_iter() {
902-
match future.unwrap() {
902+
match future.into_inner() {
903903
Ok(()) => {},
904904
Err(_) => {
905905
panicked = true;

src/librustrt/c_str.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,15 @@ impl CString {
254254
///
255255
/// Prefer `.as_ptr()` when just retrieving a pointer to the
256256
/// string data, as that does not relinquish ownership.
257-
pub unsafe fn unwrap(mut self) -> *const libc::c_char {
257+
pub unsafe fn into_inner(mut self) -> *const libc::c_char {
258258
self.owns_buffer_ = false;
259259
self.buf
260260
}
261261

262+
/// Deprecated, use into_inner() instead
263+
#[deprecated = "renamed to into_inner()"]
264+
pub unsafe fn unwrap(self) -> *const libc::c_char { self.into_inner() }
265+
262266
/// Return the number of bytes in the CString (not including the NUL
263267
/// terminator).
264268
#[inline]

src/libstd/c_vec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ impl<T> CVec<T> {
138138
/// Note that if you want to access the underlying pointer without
139139
/// cancelling the destructor, you can simply call `transmute` on the return
140140
/// value of `get(0)`.
141-
pub unsafe fn unwrap(mut self) -> *mut T {
141+
pub unsafe fn into_inner(mut self) -> *mut T {
142142
self.dtor = None;
143143
self.base
144144
}
145145

146+
/// Deprecated, use into_inner() instead
147+
#[deprecated = "renamed to into_inner()"]
148+
pub unsafe fn unwrap(self) -> *mut T { self.into_inner() }
149+
146150
/// Returns the number of items in this vector.
147151
pub fn len(&self) -> uint { self.len }
148152

src/libstd/io/buffered.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ impl<R: Reader> BufferedReader<R> {
8383
/// Unwraps this `BufferedReader`, returning the underlying reader.
8484
///
8585
/// Note that any leftover data in the internal buffer is lost.
86-
pub fn unwrap(self) -> R { self.inner }
86+
pub fn into_inner(self) -> R { self.inner }
87+
88+
/// Deprecated, use into_inner() instead
89+
#[deprecated = "renamed to into_inner()"]
90+
pub fn unwrap(self) -> R { self.into_inner() }
8791
}
8892

8993
impl<R: Reader> Buffer for BufferedReader<R> {
@@ -180,11 +184,15 @@ impl<W: Writer> BufferedWriter<W> {
180184
/// Unwraps this `BufferedWriter`, returning the underlying writer.
181185
///
182186
/// The buffer is flushed before returning the writer.
183-
pub fn unwrap(mut self) -> W {
187+
pub fn into_inner(mut self) -> W {
184188
// FIXME(#12628): is panicking the right thing to do if flushing panicks?
185189
self.flush_buf().unwrap();
186190
self.inner.take().unwrap()
187191
}
192+
193+
/// Deprecated, use into_inner() instead
194+
#[deprecated = "renamed to into_inner()"]
195+
pub fn unwrap(self) -> W { self.into_inner() }
188196
}
189197

190198
impl<W: Writer> Writer for BufferedWriter<W> {
@@ -244,7 +252,11 @@ impl<W: Writer> LineBufferedWriter<W> {
244252
/// Unwraps this `LineBufferedWriter`, returning the underlying writer.
245253
///
246254
/// The internal buffer is flushed before returning the writer.
247-
pub fn unwrap(self) -> W { self.inner.unwrap() }
255+
pub fn into_inner(self) -> W { self.inner.into_inner() }
256+
257+
/// Deprecated, use into_inner() instead
258+
#[deprecated = "renamed to into_inner()"]
259+
pub fn unwrap(self) -> W { self.into_inner() }
248260
}
249261

250262
impl<W: Writer> Writer for LineBufferedWriter<W> {
@@ -341,10 +353,14 @@ impl<S: Stream> BufferedStream<S> {
341353
///
342354
/// The internal buffer is flushed before returning the stream. Any leftover
343355
/// data in the read buffer is lost.
344-
pub fn unwrap(self) -> S {
356+
pub fn into_inner(self) -> S {
345357
let InternalBufferedWriter(w) = self.inner.inner;
346-
w.unwrap()
358+
w.into_inner()
347359
}
360+
361+
/// Deprecated, use into_inner() instead
362+
#[deprecated = "renamed to into_inner()"]
363+
pub fn unwrap(self) -> S { self.into_inner() }
348364
}
349365

350366
impl<S: Stream> Buffer for BufferedStream<S> {

src/libstd/io/mem.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Writer for Vec<u8> {
6262
/// let mut w = MemWriter::new();
6363
/// w.write(&[0, 1, 2]);
6464
///
65-
/// assert_eq!(w.unwrap(), vec!(0, 1, 2));
65+
/// assert_eq!(w.into_inner(), vec!(0, 1, 2));
6666
/// ```
6767
#[deprecated = "use the Vec<u8> Writer implementation directly"]
6868
#[deriving(Clone)]
@@ -95,7 +95,11 @@ impl MemWriter {
9595

9696
/// Unwraps this `MemWriter`, returning the underlying buffer
9797
#[inline]
98-
pub fn unwrap(self) -> Vec<u8> { self.buf }
98+
pub fn into_inner(self) -> Vec<u8> { self.buf }
99+
100+
/// Deprecated, use into_inner() instead
101+
#[deprecated = "renamed to into_inner()"]
102+
pub fn unwrap(self) -> Vec<u8> { self.into_inner() }
99103
}
100104

101105
impl Writer for MemWriter {
@@ -150,7 +154,11 @@ impl MemReader {
150154

151155
/// Unwraps this `MemReader`, returning the underlying buffer
152156
#[inline]
153-
pub fn unwrap(self) -> Vec<u8> { self.buf }
157+
pub fn into_inner(self) -> Vec<u8> { self.buf }
158+
159+
/// Deprecated, use into_inner() instead
160+
#[deprecated = "renamed to into_inner()"]
161+
pub fn unwrap(self) -> Vec<u8> { self.into_inner() }
154162
}
155163

156164
impl Reader for MemReader {

src/libstd/io/tempfile.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ impl TempDir {
7373
/// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper.
7474
/// This discards the wrapper so that the automatic deletion of the
7575
/// temporary directory is prevented.
76-
pub fn unwrap(self) -> Path {
76+
pub fn into_inner(self) -> Path {
7777
let mut tmpdir = self;
7878
tmpdir.path.take().unwrap()
7979
}
8080

81+
/// Deprecated, use into_inner() instead
82+
#[deprecated = "renamed to into_inner()"]
83+
pub fn unwrap(self) -> Path { self.into_inner() }
84+
8185
/// Access the wrapped `std::path::Path` to the temporary directory.
8286
pub fn path<'a>(&'a self) -> &'a Path {
8387
self.path.as_ref().unwrap()

src/libstd/io/util.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ impl<R: Reader> LimitReader<R> {
2828
}
2929

3030
/// Consumes the `LimitReader`, returning the underlying `Reader`.
31-
pub fn unwrap(self) -> R { self.inner }
31+
pub fn into_inner(self) -> R { self.inner }
32+
33+
/// Deprecated, use into_inner() instead
34+
#[deprecated = "renamed to into_inner"]
35+
pub fn unwrap(self) -> R { self.into_inner() }
3236

3337
/// Returns the number of bytes that can be read before the `LimitReader`
3438
/// will return EOF.
@@ -207,10 +211,14 @@ impl<R: Reader, W: Writer> TeeReader<R, W> {
207211

208212
/// Consumes the `TeeReader`, returning the underlying `Reader` and
209213
/// `Writer`.
210-
pub fn unwrap(self) -> (R, W) {
214+
pub fn into_inner(self) -> (R, W) {
211215
let TeeReader { reader, writer } = self;
212216
(reader, writer)
213217
}
218+
219+
/// Deprecated, use into_inner() instead
220+
#[deprecated = "renamed to into_inner"]
221+
pub fn unwrap(self) -> (R, W) { self.into_inner() }
214222
}
215223

216224
impl<R: Reader, W: Writer> Reader for TeeReader<R, W> {

src/libstd/sync/future.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<A:Clone> Future<A> {
5454

5555
impl<A> Future<A> {
5656
/// Gets the value from this future, forcing evaluation.
57-
pub fn unwrap(mut self) -> A {
57+
pub fn into_inner(mut self) -> A {
5858
self.get_ref();
5959
let state = replace(&mut self.state, Evaluating);
6060
match state {
@@ -63,6 +63,10 @@ impl<A> Future<A> {
6363
}
6464
}
6565

66+
/// Deprecated, use into_inner() instead
67+
#[deprecated = "renamed to into_inner()"]
68+
pub fn unwrap(self) -> A { self.into_inner() }
69+
6670
pub fn get_ref<'a>(&'a mut self) -> &'a A {
6771
/*!
6872
* Executes the future's closure and then returns a reference

src/libstd/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl TaskBuilder {
197197
/// completes or panics. Equivalent to `.try_future(f).unwrap()`.
198198
#[unstable = "Error type may change."]
199199
pub fn try<T:Send>(self, f: proc():Send -> T) -> Result<T, Box<Any + Send>> {
200-
self.try_future(f).unwrap()
200+
self.try_future(f).into_inner()
201201
}
202202
}
203203

src/libtest/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ pub fn run_test(opts: &TestOpts,
10591059
let result_future = task.try_future(testfn);
10601060

10611061
let stdout = reader.read_to_end().unwrap().into_iter().collect();
1062-
let task_result = result_future.unwrap();
1062+
let task_result = result_future.into_inner();
10631063
let test_result = calc_result(&desc, task_result.is_ok());
10641064
monitor_ch.send((desc.clone(), test_result, stdout));
10651065
})

0 commit comments

Comments
 (0)