Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly call source.provide instead of going through dyn error #184

Merged
merged 1 commit into from Sep 4, 2022

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Sep 4, 2022

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 to dyn Error + … (such as Box<dyn Error> would do).

None of those cases require the thiserror-generated provide method to actually go through dyn Error. We can directly call the provide method, which will do the deref'ing and then call provide from either the type's std::error::Error impl or from dyn 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>).

@dtolnay dtolnay merged commit 76c5568 into master Sep 4, 2022
16 checks passed
@dtolnay dtolnay deleted the provide branch Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant