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

use thiserror prevents re-use in piggy-back proc-macros #167

Closed
drahnr opened this issue Feb 24, 2022 · 3 comments
Closed

use thiserror prevents re-use in piggy-back proc-macros #167

drahnr opened this issue Feb 24, 2022 · 3 comments

Comments

@drahnr
Copy link

drahnr commented Feb 24, 2022

First of all, ❤ thank you for all your work!

I recently started to create a proc-macro to piggy-back on thiserror to determine the fatality and convenient splitting of those error types ( https://github.com/drahnr/fatality ). Under the hood it generates #[derive(fatality::thiserror::Error)] annotated types, and as long as thiserror is part of the manifest in a compatible version with the re-export of fatality, everything works just fine.
As a matter of fact, I don't want the user to have to deal with this, thiserror is an impl detail that they should not be concerned with drahnr/fatality#3 .

The root cause is the assumption of having an import of thiserror in a few places in the code that generates statements like use thiserror::private::AsDynError; which are the root of the issue at hand.

Would you accept a patch to make the base of that use statement adjustable?

@dtolnay
Copy link
Owner

dtolnay commented May 19, 2022

I would prefer not to build a workaround for this into this crate. If you are motivated to get this working, I would recommend thinking about an RFC that lets macro-generated code refer hygienically to a specific crate.

@dtolnay dtolnay closed this as completed May 19, 2022
@dtolnay
Copy link
Owner

dtolnay commented Dec 20, 2024

Something along the lines of rust-lang/rust#54363 (comment) would be my preferred approach, if you'd like to work on that.

@alexkirsz
Copy link

We're facing the same issue as OP. For now, we're doing use ::macro_crate::__private::thiserror;, which works well enough for our use case but pollutes the namespace.

For serde, we're using the crate attribute to specify a custom path.

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

No branches or pull requests

3 participants