Skip to content

Commit df1cd17

Browse files
committed
---
yaml --- r: 212026 b: refs/heads/tmp c: f65ba38 h: refs/heads/master v: v3
1 parent 065f7a2 commit df1cd17

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: 62e70d35be3fe532c26a400b499c58a18f18dd3a
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: b529a7837bcbaee4a5e9f61ee659c94af7e41f60
35+
refs/heads/tmp: f65ba38cc4d69089575580807b262a029b53c0e2
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: b77d60adb019bb5de05e884a99f3290ec4694137
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/src/libstd/io/error.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Error {
188188
/// If this `Error` was constructed via `new` then this function will
189189
/// return `Some`, otherwise it will return `None`.
190190
#[unstable(feature = "io_error_inner", reason = "recently added")]
191-
pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync)> {
191+
pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
192192
match self.repr {
193193
Repr::Os(..) => None,
194194
Repr::Custom(ref c) => Some(&*c.error),
@@ -201,7 +201,7 @@ impl Error {
201201
/// If this `Error` was constructed via `new` then this function will
202202
/// return `Some`, otherwise it will return `None`.
203203
#[unstable(feature = "io_error_inner", reason = "recently added")]
204-
pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync)> {
204+
pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
205205
match self.repr {
206206
Repr::Os(..) => None,
207207
Repr::Custom(ref mut c) => Some(&mut *c.error),
@@ -264,3 +264,39 @@ fn _assert_error_is_sync_send() {
264264
fn _is_sync_send<T: Sync+Send>() {}
265265
_is_sync_send::<Error>();
266266
}
267+
268+
#[cfg(test)]
269+
mod test {
270+
use prelude::v1::*;
271+
use super::{Error, ErrorKind};
272+
use error;
273+
use error::Error as error_Error;
274+
use fmt;
275+
276+
#[test]
277+
fn test_downcasting() {
278+
#[derive(Debug)]
279+
struct TestError;
280+
281+
impl fmt::Display for TestError {
282+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
283+
Ok(())
284+
}
285+
}
286+
287+
impl error::Error for TestError {
288+
fn description(&self) -> &str {
289+
"asdf"
290+
}
291+
}
292+
293+
// we have to call all of these UFCS style right now since method
294+
// resolution won't implicitly drop the Send+Sync bounds
295+
let mut err = Error::new(ErrorKind::Other, TestError);
296+
assert!(error::Error::is::<TestError>(err.get_ref().unwrap()));
297+
assert_eq!("asdf", err.get_ref().unwrap().description());
298+
assert!(error::Error::is::<TestError>(err.get_mut().unwrap()));
299+
let extracted = err.into_inner().unwrap();
300+
error::Error::downcast::<TestError>(extracted).unwrap();
301+
}
302+
}

0 commit comments

Comments
 (0)