-
-
Notifications
You must be signed in to change notification settings - Fork 358
Support parsing #![feature(default_field_values)]
#1851
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
Conversation
3939194 to
6671f48
Compare
- RFC: rust-lang/rfcs#3681 - Tracking issue: rust-lang/rust#132162 - Feature gate: `#![feature(default_field_values)]` ```rust struct Pet { name: Option<String>, age: i128 = 42, // ^^^^ } ``` Fix dtolnay#1774.
6671f48 to
8303beb
Compare
dtolnay
left a comment
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.
Thanks!
| /// Default value: `field_name: i32 = 1` | ||
| /// | ||
| /// `#![feature(default_field_values)]` | ||
| pub default: Option<(Token![=], Expr)>, |
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 field cannot be added until 3.x, and even then, not unless the default_field_values feature is closer to stabilization.
For now please send a different PR that parses structs containing field default values as syn::Item::Verbatim instead. I'll close this PR to keep this version of the implementation for 3.x.
|
In the spirit of not blocking this language feature on v3.x, I wonder: Maybe it'd be possible to hackily smuggle it as an // Parse
let eq_token;
let value;
let field = Field {
attrs: vec![
Attribute {
pound_token: Token![#] { span: fake_span!() },
style: AttrStyle::Outer,
bracket_token: Bracket { span: fake_span!() },
meta: Meta::NameValue(MetaNameValue {
path: fake_path!("__syn_internal_default"),
eq_token,
value,
}),
},
],
vis,
mutability,
ident,
colon_token,
ty,
}I get that that nobody likes this solution, and that it has issues with the serialization and deserialization logic becoming more complex and people possibly accidentally using the fake attribute in unintended ways. But it'd be somewhat more workable than Another option: Add WDYT? |
Adapted from dtolnay#1851. Co-Authored-By: =?UTF-8?q?Esteban=20K=C3=BCber?= <esteban@kuber.com.ar>
#![feature(default_field_values)]Fix #1774.