Skip to content

Commit 0d32aa6

Browse files
committed
---
yaml --- r: 214814 b: refs/heads/beta c: f65ba38 h: refs/heads/master v: v3
1 parent 296a4c2 commit 0d32aa6

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
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: b529a7837bcbaee4a5e9f61ee659c94af7e41f60
26+
refs/heads/beta: f65ba38cc4d69089575580807b262a029b53c0e2
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 8c0aa6d64ebab528f7eb182812007155d6044972
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/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)