Skip to content

Support default field values #6053

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

DJMcNab
Copy link

@DJMcNab DJMcNab commented Jun 30, 2025

This uses my fork of syn defined at dtolnay/syn#1870, and is intended to validate that. This PR is not necessarily intended to merged/reviewed, as things stand. In particular, if the syn PR is never merged, this won't be the right solution.

#[derive(Parser)]
struct Opt {
    arg: i32 = 42,
    //       ^^^^
}

Some notes:

  • Supporting default field values is frustratingly involved, because of how the support has to be hacked into syn 2.0. See the suggestion in Support parsing #![feature(default_field_values)] dtolnay/syn#1851 (comment) of the only way to move this forward. This will need to filter through the ecosystem if approved, which this PR is part of.
  • Testing the use of this feature in CI is hard because it requires nightly
  • There are some pretty nasty hacks in here; obviously those can be cleaned up before landing.

The test can be ran with:

RUSTFLAGS="--cfg=nightly" cargo +nightly test --test default_field_values --features derive --features help --features usage

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.

1 participant