Directly call source.provide instead of going through dyn error #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From https://github.com/dtolnay/thiserror/blob/1.0.33/src/aserror.rs, the
.as_dyn_error()
method exists if the #[source] has a std::error::Error impl, or derefs to something with a std::error::Error impl, or derefs todyn Error + …
(such asBox<dyn Error>
would do).None of those cases require the thiserror-generated
provide
method to actually go throughdyn Error
. We can directly call theprovide
method, which will do the deref'ing and then callprovide
from either the type's std::error::Error impl or fromdyn Error
's vtable.This wasn't possible prior to #182 because
.backtrace()
couldn't have been called directly the same way, since anyhow::Error has a backtrace method with a different signature than std::error::Error's backtrace method (-> &Backtrace
vs-> Option<&Backtrace>
).