Skip to content
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

Support parsing #![feature(default_field_values)] #1851

Closed
wants to merge 1 commit into from

Conversation

estebank
Copy link

@estebank estebank commented Mar 6, 2025

#[derive(Default)]
struct Pet {
    name: Option<String>,
    age: i128 = 42,
    //        ^^^^
}

Fix #1774.

@estebank estebank force-pushed the default-field-values branch 2 times, most recently from 3939194 to 6671f48 Compare March 6, 2025 19:24
- 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.
@estebank estebank force-pushed the default-field-values branch from 6671f48 to 8303beb Compare March 6, 2025 19:26
Copy link
Owner

@dtolnay dtolnay left a 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)>,
Copy link
Owner

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.

@dtolnay dtolnay closed this Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse default values in fields
2 participants