-
Notifications
You must be signed in to change notification settings - Fork 764
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
Update to the proc_macro2 crate and rewritten syn
#980
Conversation
Note that this is a PR against the |
cc @mystor as well Some things I've learned as part of this transition:
Curious what y'all think of those points! |
I haven't had the time to read the actual patch yet, so I'm just commenting based on your comment. For point 2, I think in many cases we could probably get away with the That being said, we should definitely persue better ergonomics for I filed dtolnay/syn#177 for point 3. |
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.
I added some comments to the changes, mostly with an eye to how we can make syn
better. I don't know anything about serde
's codebase, so I can't comment on the correctness of the new code, but it looks like a fairly straightforward transformation, so I think it should be good.
serde_derive/Cargo.toml
Outdated
serde_derive_internals = { version = "=0.15.1", default-features = false, path = "../serde_derive_internals" } | ||
syn = { version = "0.11", features = ["visit"] } | ||
syn = { git = 'https://github.com/dtolnay/syn', features = ["visit"] } | ||
synom = { git = 'https://github.com/dtolnay/syn', default-features = false } |
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.
I don't love that we have to import synom
explicitly here, when we used to only need to import syn. I don't feel like it's a good idea to re-export proc-macro2
, but for most users synom
should be an implementation detail.
Can we re-export the important bits from syn? I feel like Span
, tokens
and Delimited
should probably all be re-exported under syn
's root.
serde_derive/src/bound.rs
Outdated
} | ||
}, | ||
) | ||
.collect(), | ||
.collect::<Vec<_>>() |
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.
It would be great to have FromIterator
implemented on Delimited
. While it feels overkill to have every Vec
method or trait, that one at least feels useful.
for predicate in predicates { | ||
if generics.where_clause.where_token.is_none() { | ||
generics.where_clause.where_token = Some(tokens::Where::default()); | ||
} |
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.
This is really gross. Could we make our ToTokens
implementation detect that we need a Where
token and just make one for us in this situation implicitly?
serde_derive/src/bound.rs
Outdated
@@ -101,15 +113,16 @@ where | |||
} | |||
impl visit::Visitor for FindTyParams { | |||
fn visit_path(&mut self, path: &syn::Path) { | |||
if let Some(seg) = path.segments.last() { | |||
if path.segments.len() > 0 { | |||
let seg = *path.segments.get(path.segments.len() - 1).item(); |
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.
first[_mut]
and last[_mut]
also seem worthwhile to add to Delimited
.
|
||
for lifetime_def in generics.lifetimes.iter_mut().map(|m| m.into_item()) { | ||
if lifetime_def.colon_token.is_none() { | ||
lifetime_def.colon_token = Some(tokens::Colon::default()); |
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.
We'd also need to make the colon token be automatically added :-/
serde_derive/src/de.rs
Outdated
@@ -163,7 +173,10 @@ fn needs_deserialize_bound(attrs: &attr::Field) -> bool { | |||
// Fields with a `default` attribute (not `default=...`), and fields with a | |||
// `skip_deserializing` attribute that do not also have `default=...`. | |||
fn requires_default(attrs: &attr::Field) -> bool { | |||
attrs.default() == &attr::Default::Default | |||
match *attrs.default() { | |||
attr::Default::Default => true, |
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.
The extra-traits change feels unrelated to me, but I suppose you're doing it to try to save on compile time? It feels a bit like it should be done in a separate patch to me.
serde_derive_internals/Cargo.toml
Outdated
|
||
[badges] | ||
travis-ci = { repository = "serde-rs/serde" } | ||
|
||
[features] | ||
extra-traits = ["syn/extra-traits"] |
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.
extra-traits is listed twice, both as a required and optional feature. I think it should only be listed in one of those two places.
Great, this is enough to convince me that things are still usable. I don't think we need to polish this further right now. I responded in dtolnay/syn#123 (comment) but I think we can go ahead and publish the current syn/synom/quote under different names and address some of the points here over the next couple weeks. |
@dtolnay do you have a preference on coordination of merging this? Would you prefer to only merge the update into Would you otherwise want to merge this into the |
Apart from dtolnay/syn#177 I believe I've addressed the issues mentioned here |
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.
Let's keep this on the proc-macro2 branch.
No description provided.