-
Notifications
You must be signed in to change notification settings - Fork 10
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
Expanded code using edition 2018 instead of 2021 #47
Comments
@Veetaha thank you for this bug report. It seems unlikely to me that the edition of I will investigate this and come back |
edition = "2021"
I have reproduced the given example and can verify that indeed Investigating this, macros apparently have 'edition hygiene' which cause this. |
Changing Also, simply changing |
This limitation applies to any macro crate then 🤔 . That's an interesting semver hazard. I don't think there is a permanent solution to this problem. I also wonder what happens when a 2018 crate uses a 2021 macro. |
There does seem to be a possible solution: I created a dummy macro that just expands to the code it is given: #[proc_macro]
pub fn test_macro(stream: TokenStream) -> TokenStream
{
stream
} Calling this macro instead of So, I think it might be possible to take this into account and make a permanent solution. Question now becomes how to test it. |
Maintaining this crate has really shown me how convoluted and pervasive semver compatibility is. Hazards everywhere. |
Edition hygiene seems to be tracked by spans. The following test macro changes all token spans to be #[proc_macro]
pub fn test_macro(stream: TokenStream) -> TokenStream
{
TokenStream::from_iter(stream.into_iter().map(|mut t| {
t.set_span(Span::call_site());
t
}))
} Using it on the example results in the edition of the macro always being used. |
Fix implemented and awaiting next release. @Veetaha could you try out the latest commit on master to see if it fixes all your problems? I have a test for your specific use case above but have not found any other cases where this happens. |
@Emoun indeed, the patch does fix my problem. I don't have any other use cases though, so let's consider this resolved? Also, thanks for accurately investigating this 😋! |
@Veetaha you're welcome and thanks for testing it for me. I'll see about releasing a new version at some point this week(end). |
I've found out that because this crate uses rust edition 2018, the code that we write inside of
duplicate! {}
macro is also forced to use edition 2018.For example the following code panics with the message
{a}
instead of using the format args interpolation that was added in edition2021
:Also, the compiler warns about this when compiling:
I've stumbled with this behavior and had to think really hard to deduce where the
2018
edition comes from because my crate where I use this macro is of edition2021
🤨.Anyway, I suppose this is a good reason to migration to the new edition.
The text was updated successfully, but these errors were encountered: