-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Get diesel_derives2 working with hygiene turned on #1521
Conversation
When `proc_macro2` has the nightly feature enabled, a lot of the rules around hygiene change. Most of the changes needed appear to be due to bugs in Rust (e.g. to access a tuple struct field, the span of the dot has to be resolved specially, but not for a named struct field), but the span changes for table names in particular is definitely required. The change to hygiene rules randomly broke our const workaround (the ability to `use` items defined in an expression like that was potentially unintended to begin with). However, there's no reason it needs to be a const, we can just have it be a module with no additional problems. I've added a few UI tests for the failure cases that are actually affected by this change (there is more work to be done on this, of course). Note that we can't actually run those tests yet, as they require a nightly compiler, and we won't build on nightly until tomorrow. However, I've left the tests in place so that the changes in output can be seen. The error for `table_name` isn't quite there, but due to a bug in Rust it's the best we can do. Right now it looks like this: ``` 1 | #[table_name = "users"] | ^ Use of undeclared type or module `users` ``` instead of like this: ``` 1 | #[table_name = "users"] | ^^^^^^^ Use of undeclared type or module `users` ```
/cc @dtolnay |
Note: Build is going to be red until tomorrow. Nothing I can do about that, but this should be fine to review |
What happens tomorrow? |
rust-lang/rust#47738 will be in tomorrow's nightly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done!
use proc_macro2::{Spacing, TokenNode, TokenTree}; | ||
|
||
// https://github.com/rust-lang/rust/issues/47312 | ||
tokens.append(TokenTree { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote_spanned!
can make this more concise but it is up to you whether you prefer the explicit way or the concise way.
quote_spanned!(call_site=> .)
When
proc_macro2
has the nightly feature enabled, a lot of the rulesaround hygiene change. Most of the changes needed appear to be due to
bugs in Rust (e.g. to access a tuple struct field, the span of the dot has to
be resolved specially, but not for a named struct field), but the span
changes for table names in particular is definitely required.
The change to hygiene rules randomly broke our const workaround (the
ability to
use
items defined in an expression like that waspotentially unintended to begin with). However, there's no reason it
needs to be a const, we can just have it be a module with no additional
problems.
I've added a few UI tests for the failure cases that are actually
affected by this change (there is more work to be done on this, of
course). Note that we can't actually run those tests yet, as they
require a nightly compiler, and we won't build on nightly until
tomorrow. However, I've left the tests in place so that the changes in
output can be seen.
The error for
table_name
isn't quite there, but due to a bug in Rustit's the best we can do. Right now it looks like this:
instead of like this: