Support parsing #![feature(default_field_values)]#1851
Support parsing #![feature(default_field_values)]#1851estebank wants to merge 1 commit intodtolnay:masterfrom
#![feature(default_field_values)]#1851Conversation
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
| /// Default value: `field_name: i32 = 1` | ||
| /// | ||
| /// `#![feature(default_field_values)]` | ||
| pub default: Option<(Token![=], Expr)>, |
There was a problem hiding this comment.
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.