-
Notifications
You must be signed in to change notification settings - Fork 68
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
Unresolved type errors inside macro invocation #125
Comments
Hmm, I actually cannot find any non-absolute reference to The compiler still complains though: mod syn {}
#[derive(darling::FromMeta)]
struct Args {} Compiler output with Funnily enough, if the Schrödinger's error; it only appears when you can't look under the hood 🤔 |
Ohhhhhh I think I know the issue. Quoting the Rust reference on path qualifiers:
Darling uses Rust 2015, which means that its proc-macro generated code adheres to the Rust 2015 rules, which also means that Only when pasting the |
If this works properly in 2018 or in the absence of a redeclared root |
To be clear, Darling's generated code is perfectly fine and can't meaningfully be "fixed" as far as I can tell; the unresolved type error comes from a combination of Darling itself using Rust 2015 and the dependent crate having an item called syn in the crate root. Tweaking the syn module in my code to make it work is not a problem at all. Maybe it would also be cool to port Darling to Rust 2018, to get rid of old language edge cases like this one and also because it's just nice to be up to date ^.^ Anyways, thank you for your time, I think this issue can be closed since a fix has been found |
I wish I could. My understanding is that proc macros inherit the edition of their call site, so I can't move |
I could not find any official resources on this question, but according to some testing done by Yandros in the Rust community discord server, proc macros use the edition of the definition site. This also matches the behavior I described above: the Darling-generated code adheres to Rust 2015 rules, even when the derive macro is invoked in a Rust 2018 crate. As far as I can tell from all of this, no user code should break when moving Darling to Rust 2018. |
It seems that Darling's macros refer to items of syn (and potentially other dependencies) with a path of the form
syn::_
. In macros, it is advisable to use absolute paths::syn::_
instead, as they don't clash with local items called "syn".I encountered this issue just now, when trying out Darling for the first time. In my code, I have a custom syn prelude module to shorten paths:
Darling's generated code proceeded to access an item called NestedMeta from "syn", which, due to not being an absolute path, was misinterpreted as the module.
The text was updated successfully, but these errors were encountered: