Skip to content

Commit f9224f0

Browse files
committed
---
yaml --- r: 209389 b: refs/heads/auto c: f65ba38 h: refs/heads/master i: 209387: 84f953e v: v3
1 parent d8d4dbd commit f9224f0

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
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: b529a7837bcbaee4a5e9f61ee659c94af7e41f60
13+
refs/heads/auto: f65ba38cc4d69089575580807b262a029b53c0e2
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

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