Skip to content

Commit cb250b7

Browse files
committed
Auto merge of #27370 - alexcrichton:stabilize-easy, r=brson
The following APIs were all marked with a `#[stable]` tag: * process::Child::id * error::Error::is * error::Error::downcast * error::Error::downcast_ref * error::Error::downcast_mut * io::Error::get_ref * io::Error::get_mut * io::Error::into_inner * hash::Hash::hash_slice * hash::Hasher::write_{i,u}{8,16,32,64,size}
2 parents dc966ef + 76db37e commit cb250b7

File tree

4 files changed

+111
-31
lines changed

4 files changed

+111
-31
lines changed

src/libcore/hash/mod.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ pub trait Hash {
9191
fn hash<H: Hasher>(&self, state: &mut H);
9292

9393
/// Feeds a slice of this type into the state provided.
94-
#[unstable(feature = "hash_slice",
95-
reason = "module was recently redesigned")]
94+
#[stable(feature = "hash_slice", since = "1.3.0")]
9695
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H) where Self: Sized {
9796
for piece in data {
9897
piece.hash(state);
@@ -113,29 +112,29 @@ pub trait Hasher {
113112

114113
/// Write a single `u8` into this hasher
115114
#[inline]
116-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
115+
#[stable(feature = "hasher_write", since = "1.3.0")]
117116
fn write_u8(&mut self, i: u8) { self.write(&[i]) }
118117
/// Write a single `u16` into this hasher.
119118
#[inline]
120-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
119+
#[stable(feature = "hasher_write", since = "1.3.0")]
121120
fn write_u16(&mut self, i: u16) {
122121
self.write(&unsafe { mem::transmute::<_, [u8; 2]>(i) })
123122
}
124123
/// Write a single `u32` into this hasher.
125124
#[inline]
126-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
125+
#[stable(feature = "hasher_write", since = "1.3.0")]
127126
fn write_u32(&mut self, i: u32) {
128127
self.write(&unsafe { mem::transmute::<_, [u8; 4]>(i) })
129128
}
130129
/// Write a single `u64` into this hasher.
131130
#[inline]
132-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
131+
#[stable(feature = "hasher_write", since = "1.3.0")]
133132
fn write_u64(&mut self, i: u64) {
134133
self.write(&unsafe { mem::transmute::<_, [u8; 8]>(i) })
135134
}
136135
/// Write a single `usize` into this hasher.
137136
#[inline]
138-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
137+
#[stable(feature = "hasher_write", since = "1.3.0")]
139138
fn write_usize(&mut self, i: usize) {
140139
if cfg!(target_pointer_width = "32") {
141140
self.write_u32(i as u32)
@@ -146,23 +145,23 @@ pub trait Hasher {
146145

147146
/// Write a single `i8` into this hasher.
148147
#[inline]
149-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
148+
#[stable(feature = "hasher_write", since = "1.3.0")]
150149
fn write_i8(&mut self, i: i8) { self.write_u8(i as u8) }
151150
/// Write a single `i16` into this hasher.
152151
#[inline]
153-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
152+
#[stable(feature = "hasher_write", since = "1.3.0")]
154153
fn write_i16(&mut self, i: i16) { self.write_u16(i as u16) }
155154
/// Write a single `i32` into this hasher.
156155
#[inline]
157-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
156+
#[stable(feature = "hasher_write", since = "1.3.0")]
158157
fn write_i32(&mut self, i: i32) { self.write_u32(i as u32) }
159158
/// Write a single `i64` into this hasher.
160159
#[inline]
161-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
160+
#[stable(feature = "hasher_write", since = "1.3.0")]
162161
fn write_i64(&mut self, i: i64) { self.write_u64(i as u64) }
163162
/// Write a single `isize` into this hasher.
164163
#[inline]
165-
#[unstable(feature = "hasher_write", reason = "module was recently redesigned")]
164+
#[stable(feature = "hasher_write", since = "1.3.0")]
166165
fn write_isize(&mut self, i: isize) { self.write_usize(i as usize) }
167166
}
168167

src/libstd/error.rs

+93-9
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Error for string::FromUtf16Error {
168168
// copied from any.rs
169169
impl Error + 'static {
170170
/// Returns true if the boxed type is the same as `T`
171-
#[unstable(feature = "error_downcast", reason = "recently added")]
171+
#[stable(feature = "error_downcast", since = "1.3.0")]
172172
#[inline]
173173
pub fn is<T: Error + 'static>(&self) -> bool {
174174
// Get TypeId of the type this function is instantiated with
@@ -183,7 +183,7 @@ impl Error + 'static {
183183

184184
/// Returns some reference to the boxed value if it is of type `T`, or
185185
/// `None` if it isn't.
186-
#[unstable(feature = "error_downcast", reason = "recently added")]
186+
#[stable(feature = "error_downcast", since = "1.3.0")]
187187
#[inline]
188188
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
189189
if self.is::<T>() {
@@ -201,7 +201,7 @@ impl Error + 'static {
201201

202202
/// Returns some mutable reference to the boxed value if it is of type `T`, or
203203
/// `None` if it isn't.
204-
#[unstable(feature = "error_downcast", reason = "recently added")]
204+
#[stable(feature = "error_downcast", since = "1.3.0")]
205205
#[inline]
206206
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
207207
if self.is::<T>() {
@@ -220,21 +220,44 @@ impl Error + 'static {
220220

221221
impl Error + 'static + Send {
222222
/// Forwards to the method defined on the type `Any`.
223-
#[unstable(feature = "error_downcast", reason = "recently added")]
223+
#[stable(feature = "error_downcast", since = "1.3.0")]
224224
#[inline]
225225
pub fn is<T: Error + 'static>(&self) -> bool {
226226
<Error + 'static>::is::<T>(self)
227227
}
228228

229229
/// Forwards to the method defined on the type `Any`.
230-
#[unstable(feature = "error_downcast", reason = "recently added")]
230+
#[stable(feature = "error_downcast", since = "1.3.0")]
231231
#[inline]
232232
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
233233
<Error + 'static>::downcast_ref::<T>(self)
234234
}
235235

236236
/// Forwards to the method defined on the type `Any`.
237-
#[unstable(feature = "error_downcast", reason = "recently added")]
237+
#[stable(feature = "error_downcast", since = "1.3.0")]
238+
#[inline]
239+
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
240+
<Error + 'static>::downcast_mut::<T>(self)
241+
}
242+
}
243+
244+
impl Error + 'static + Send + Sync {
245+
/// Forwards to the method defined on the type `Any`.
246+
#[stable(feature = "error_downcast", since = "1.3.0")]
247+
#[inline]
248+
pub fn is<T: Error + 'static>(&self) -> bool {
249+
<Error + 'static>::is::<T>(self)
250+
}
251+
252+
/// Forwards to the method defined on the type `Any`.
253+
#[stable(feature = "error_downcast", since = "1.3.0")]
254+
#[inline]
255+
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
256+
<Error + 'static>::downcast_ref::<T>(self)
257+
}
258+
259+
/// Forwards to the method defined on the type `Any`.
260+
#[stable(feature = "error_downcast", since = "1.3.0")]
238261
#[inline]
239262
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
240263
<Error + 'static>::downcast_mut::<T>(self)
@@ -243,7 +266,7 @@ impl Error + 'static + Send {
243266

244267
impl Error {
245268
#[inline]
246-
#[unstable(feature = "error_downcast", reason = "recently added")]
269+
#[stable(feature = "error_downcast", since = "1.3.0")]
247270
/// Attempt to downcast the box to a concrete type.
248271
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Error>> {
249272
if self.is::<T>() {
@@ -264,13 +287,74 @@ impl Error {
264287

265288
impl Error + Send {
266289
#[inline]
267-
#[unstable(feature = "error_downcast", reason = "recently added")]
290+
#[stable(feature = "error_downcast", since = "1.3.0")]
268291
/// Attempt to downcast the box to a concrete type.
269-
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Error + Send>> {
292+
pub fn downcast<T: Error + 'static>(self: Box<Self>)
293+
-> Result<Box<T>, Box<Error + Send>> {
270294
let err: Box<Error> = self;
271295
<Error>::downcast(err).map_err(|s| unsafe {
272296
// reapply the Send marker
273297
transmute::<Box<Error>, Box<Error + Send>>(s)
274298
})
275299
}
276300
}
301+
302+
impl Error + Send + Sync {
303+
#[inline]
304+
#[stable(feature = "error_downcast", since = "1.3.0")]
305+
/// Attempt to downcast the box to a concrete type.
306+
pub fn downcast<T: Error + 'static>(self: Box<Self>)
307+
-> Result<Box<T>, Box<Self>> {
308+
let err: Box<Error> = self;
309+
<Error>::downcast(err).map_err(|s| unsafe {
310+
// reapply the Send+Sync marker
311+
transmute::<Box<Error>, Box<Error + Send + Sync>>(s)
312+
})
313+
}
314+
}
315+
316+
#[cfg(test)]
317+
mod tests {
318+
use prelude::v1::*;
319+
use super::Error;
320+
use fmt;
321+
322+
#[derive(Debug, PartialEq)]
323+
struct A;
324+
#[derive(Debug, PartialEq)]
325+
struct B;
326+
327+
impl fmt::Display for A {
328+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
329+
write!(f, "A")
330+
}
331+
}
332+
impl fmt::Display for B {
333+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
334+
write!(f, "B")
335+
}
336+
}
337+
338+
impl Error for A {
339+
fn description(&self) -> &str { "A-desc" }
340+
}
341+
impl Error for B {
342+
fn description(&self) -> &str { "A-desc" }
343+
}
344+
345+
#[test]
346+
fn downcasting() {
347+
let mut a = A;
348+
let mut a = &mut a as &mut (Error + 'static);
349+
assert_eq!(a.downcast_ref::<A>(), Some(&A));
350+
assert_eq!(a.downcast_ref::<B>(), None);
351+
assert_eq!(a.downcast_mut::<A>(), Some(&mut A));
352+
assert_eq!(a.downcast_mut::<B>(), None);
353+
354+
let a: Box<Error> = Box::new(A);
355+
match a.downcast::<B>() {
356+
Ok(..) => panic!("expected error"),
357+
Err(e) => assert_eq!(*e.downcast::<A>().unwrap(), A),
358+
}
359+
}
360+
}

src/libstd/io/error.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ impl Error {
219219
///
220220
/// If this `Error` was constructed via `new` then this function will
221221
/// return `Some`, otherwise it will return `None`.
222-
#[unstable(feature = "io_error_inner",
223-
reason = "recently added and requires UFCS to downcast")]
222+
#[stable(feature = "io_error_inner", since = "1.3.0")]
224223
pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
225224
match self.repr {
226225
Repr::Os(..) => None,
@@ -233,8 +232,7 @@ impl Error {
233232
///
234233
/// If this `Error` was constructed via `new` then this function will
235234
/// return `Some`, otherwise it will return `None`.
236-
#[unstable(feature = "io_error_inner",
237-
reason = "recently added and requires UFCS to downcast")]
235+
#[stable(feature = "io_error_inner", since = "1.3.0")]
238236
pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
239237
match self.repr {
240238
Repr::Os(..) => None,
@@ -246,8 +244,7 @@ impl Error {
246244
///
247245
/// If this `Error` was constructed via `new` then this function will
248246
/// return `Some`, otherwise it will return `None`.
249-
#[unstable(feature = "io_error_inner",
250-
reason = "recently added and requires UFCS to downcast")]
247+
#[stable(feature = "io_error_inner", since = "1.3.0")]
251248
pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> {
252249
match self.repr {
253250
Repr::Os(..) => None,
@@ -349,10 +346,10 @@ mod test {
349346
// we have to call all of these UFCS style right now since method
350347
// resolution won't implicitly drop the Send+Sync bounds
351348
let mut err = Error::new(ErrorKind::Other, TestError);
352-
assert!(error::Error::is::<TestError>(err.get_ref().unwrap()));
349+
assert!(err.get_ref().unwrap().is::<TestError>());
353350
assert_eq!("asdf", err.get_ref().unwrap().description());
354-
assert!(error::Error::is::<TestError>(err.get_mut().unwrap()));
351+
assert!(err.get_mut().unwrap().is::<TestError>());
355352
let extracted = err.into_inner().unwrap();
356-
error::Error::downcast::<TestError>(extracted).unwrap();
353+
extracted.downcast::<TestError>().unwrap();
357354
}
358355
}

src/libstd/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl Child {
505505
}
506506

507507
/// Returns the OS-assigned process identifier associated with this child.
508-
#[unstable(feature = "process_id", reason = "api recently added")]
508+
#[stable(feature = "process_id", since = "1.3.0")]
509509
pub fn id(&self) -> u32 {
510510
self.handle.id()
511511
}

0 commit comments

Comments
 (0)