Skip to content

Commit 90299c2

Browse files
committed
Do what the machine tells me to do
1 parent 6644f39 commit 90299c2

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

Cargo.lock.ci

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ homepage = "https://rust-lang-nursery.github.io/failure/"
66
license = "MIT OR Apache-2.0"
77
name = "failure"
88
repository = "https://github.com/rust-lang-nursery/failure"
9-
version = "0.1.5"
9+
version = "0.1.6"
1010

1111
[dependencies.failure_derive]
1212
optional = true
13-
version = "0.1.5"
13+
version = "0.1.6"
1414
path = "./failure_derive"
1515

1616
[dependencies.backtrace]

src/as_fail.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ use Fail;
88
/// custom cause.
99
pub trait AsFail {
1010
/// Converts a reference to `Self` into a dynamic trait object of `Fail`.
11-
fn as_fail(&self) -> &Fail;
11+
fn as_fail(&self) -> &dyn Fail;
1212
}
1313

1414
impl<T> AsFail for T
1515
where
1616
T: Fail,
1717
{
18-
fn as_fail(&self) -> &Fail {
18+
fn as_fail(&self) -> &dyn Fail {
1919
self
2020
}
2121
}
2222

23-
impl AsFail for Fail {
24-
fn as_fail(&self) -> &Fail {
23+
impl AsFail for dyn Fail {
24+
fn as_fail(&self) -> &dyn Fail {
2525
self
2626
}
2727
}
@@ -30,7 +30,7 @@ with_std! {
3030
use error::Error;
3131

3232
impl AsFail for Error {
33-
fn as_fail(&self) -> &Fail {
33+
fn as_fail(&self) -> &dyn Fail {
3434
self.as_fail()
3535
}
3636
}

src/box_std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22
use std::fmt;
33
use Fail;
44

5-
pub struct BoxStd(pub Box<Error + Send + Sync + 'static>);
5+
pub struct BoxStd(pub Box<dyn Error + Send + Sync + 'static>);
66

77
impl fmt::Display for BoxStd {
88
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

src/compat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ with_std! {
3939
}
4040
}
4141

42-
impl From<Error> for Box<StdError> {
43-
fn from(error: Error) -> Box<StdError> {
42+
impl From<Error> for Box<dyn StdError> {
43+
fn from(error: Error) -> Box<dyn StdError> {
4444
Box::new(Compat { error })
4545
}
4646
}
4747

48-
impl From<Error> for Box<StdError + Send + Sync> {
49-
fn from(error: Error) -> Box<StdError + Send + Sync> {
48+
impl From<Error> for Box<dyn StdError + Send + Sync> {
49+
fn from(error: Error) -> Box<dyn StdError + Send + Sync> {
5050
Box::new(Compat { error })
5151
}
5252
}

src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ with_std! {
112112
self.failure.as_cause().and_then(|x| x.name())
113113
}
114114

115-
fn cause(&self) -> Option<&Fail> {
115+
fn cause(&self) -> Option<&dyn Fail> {
116116
self.failure.as_cause()
117117
}
118118

@@ -146,7 +146,7 @@ with_std! {
146146
}
147147
}
148148

149-
fn as_cause(&self) -> Option<&Fail> {
149+
fn as_cause(&self) -> Option<&dyn Fail> {
150150
match *self {
151151
Either::This(_) => None,
152152
Either::That(ref error) => Some(error.as_fail())

src/error/error_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Fail;
44
use backtrace::Backtrace;
55

66
pub(crate) struct ErrorImpl {
7-
inner: Box<Inner<Fail>>,
7+
inner: Box<Inner<dyn Fail>>,
88
}
99

1010
struct Inner<F: ?Sized + Fail> {
@@ -25,11 +25,11 @@ impl<F: Fail> From<F> for ErrorImpl {
2525
}
2626

2727
impl ErrorImpl {
28-
pub(crate) fn failure(&self) -> &Fail {
28+
pub(crate) fn failure(&self) -> &dyn Fail {
2929
&self.inner.failure
3030
}
3131

32-
pub(crate) fn failure_mut(&mut self) -> &mut Fail {
32+
pub(crate) fn failure_mut(&mut self) -> &mut dyn Fail {
3333
&mut self.inner.failure
3434
}
3535

src/error/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ impl Error {
6060
/// }
6161
/// ```
6262
#[cfg(feature = "std")]
63-
pub fn from_boxed_compat(err: Box<StdError + Sync + Send + 'static>) -> Error {
63+
pub fn from_boxed_compat(err: Box<dyn StdError + Sync + Send + 'static>) -> Error {
6464
Error::from(BoxStd(err))
6565
}
6666

6767
/// Return a reference to the underlying failure that this `Error`
6868
/// contains.
69-
pub fn as_fail(&self) -> &Fail {
69+
pub fn as_fail(&self) -> &dyn Fail {
7070
self.imp.failure()
7171
}
7272

@@ -82,7 +82,7 @@ impl Error {
8282
/// This method has been deprecated in favor of the [Error::as_fail] method,
8383
/// which does the same thing.
8484
#[deprecated(since = "0.1.2", note = "please use 'as_fail()' method instead")]
85-
pub fn cause(&self) -> &Fail {
85+
pub fn cause(&self) -> &dyn Fail {
8686
self.as_fail()
8787
}
8888

@@ -133,7 +133,7 @@ impl Error {
133133

134134
/// Returns the "root cause" of this error - the last value in the
135135
/// cause chain which does not return an underlying `cause`.
136-
pub fn find_root_cause(&self) -> &Fail {
136+
pub fn find_root_cause(&self) -> &dyn Fail {
137137
self.as_fail().find_root_cause()
138138
}
139139

@@ -173,7 +173,7 @@ impl Error {
173173

174174
/// Deprecated alias to `find_root_cause`.
175175
#[deprecated(since = "0.1.2", note = "please use the 'find_root_cause()' method instead")]
176-
pub fn root_cause(&self) -> &Fail {
176+
pub fn root_cause(&self) -> &dyn Fail {
177177
::find_root_cause(self.as_fail())
178178
}
179179

@@ -201,8 +201,8 @@ impl Debug for Error {
201201
}
202202
}
203203

204-
impl AsRef<Fail> for Error {
205-
fn as_ref(&self) -> &Fail {
204+
impl AsRef<dyn Fail> for Error {
205+
fn as_ref(&self) -> &dyn Fail {
206206
self.as_fail()
207207
}
208208
}

src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub trait Fail: Display + Debug + Send + Sync + 'static {
126126
/// `Some` when it can return a **different** failure. Users may loop
127127
/// over the cause chain, and returning `self` would result in an infinite
128128
/// loop.
129-
fn cause(&self) -> Option<&Fail> {
129+
fn cause(&self) -> Option<&dyn Fail> {
130130
None
131131
}
132132

@@ -186,7 +186,7 @@ pub trait Fail: Display + Debug + Send + Sync + 'static {
186186
since = "0.1.2",
187187
note = "please use the 'find_root_cause()' method instead"
188188
)]
189-
fn root_cause(&self) -> &Fail
189+
fn root_cause(&self) -> &dyn Fail
190190
where
191191
Self: Sized,
192192
{
@@ -199,13 +199,13 @@ pub trait Fail: Display + Debug + Send + Sync + 'static {
199199
}
200200
}
201201

202-
impl Fail {
202+
impl dyn Fail {
203203
/// Attempts to downcast this failure to a concrete type by reference.
204204
///
205205
/// If the underlying error is not of type `T`, this will return `None`.
206206
pub fn downcast_ref<T: Fail>(&self) -> Option<&T> {
207207
if self.__private_get_type_id__() == TypeId::of::<T>() {
208-
unsafe { Some(&*(self as *const Fail as *const T)) }
208+
unsafe { Some(&*(self as *const dyn Fail as *const T)) }
209209
} else {
210210
None
211211
}
@@ -217,7 +217,7 @@ impl Fail {
217217
/// If the underlying error is not of type `T`, this will return `None`.
218218
pub fn downcast_mut<T: Fail>(&mut self) -> Option<&mut T> {
219219
if self.__private_get_type_id__() == TypeId::of::<T>() {
220-
unsafe { Some(&mut *(self as *mut Fail as *mut T)) }
220+
unsafe { Some(&mut *(self as *mut dyn Fail as *mut T)) }
221221
} else {
222222
None
223223
}
@@ -231,7 +231,7 @@ impl Fail {
231231
///
232232
/// This is equivalent to iterating over `iter_causes()` and taking
233233
/// the last item.
234-
pub fn find_root_cause(&self) -> &Fail {
234+
pub fn find_root_cause(&self) -> &dyn Fail {
235235
find_root_cause(self)
236236
}
237237

@@ -258,7 +258,7 @@ impl Fail {
258258
since = "0.1.2",
259259
note = "please use the 'find_root_cause()' method instead"
260260
)]
261-
pub fn root_cause(&self) -> &Fail {
261+
pub fn root_cause(&self) -> &dyn Fail {
262262
find_root_cause(self)
263263
}
264264

@@ -273,8 +273,8 @@ impl Fail {
273273
impl<E: StdError + Send + Sync + 'static> Fail for E {}
274274

275275
#[cfg(feature = "std")]
276-
impl Fail for Box<Fail> {
277-
fn cause(&self) -> Option<&Fail> {
276+
impl Fail for Box<dyn Fail> {
277+
fn cause(&self) -> Option<&dyn Fail> {
278278
(**self).cause()
279279
}
280280

@@ -285,20 +285,20 @@ impl Fail for Box<Fail> {
285285

286286
/// A iterator over the causes of a `Fail`
287287
pub struct Causes<'f> {
288-
fail: Option<&'f Fail>,
288+
fail: Option<&'f dyn Fail>,
289289
}
290290

291291
impl<'f> Iterator for Causes<'f> {
292-
type Item = &'f Fail;
293-
fn next(&mut self) -> Option<&'f Fail> {
292+
type Item = &'f dyn Fail;
293+
fn next(&mut self) -> Option<&'f dyn Fail> {
294294
self.fail.map(|fail| {
295295
self.fail = fail.cause();
296296
fail
297297
})
298298
}
299299
}
300300

301-
fn find_root_cause(mut fail: &Fail) -> &Fail {
301+
fn find_root_cause(mut fail: &dyn Fail) -> &dyn Fail {
302302
while let Some(cause) = fail.cause() {
303303
fail = cause;
304304
}

tests/fail_compat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fn return_failure() -> Result<(), failure::Error> {
1212
Err(err.into())
1313
}
1414

15-
fn return_error() -> Result<(), Box<std::error::Error>> {
15+
fn return_error() -> Result<(), Box<dyn std::error::Error>> {
1616
return_failure()?;
1717
Ok(())
1818
}
1919

20-
fn return_error_send_sync() -> Result<(), Box<std::error::Error + Send + Sync>> {
20+
fn return_error_send_sync() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2121
return_failure()?;
2222
Ok(())
2323
}

0 commit comments

Comments
 (0)