Skip to content

Support default field values#6053

Closed
DJMcNab wants to merge 5 commits intoclap-rs:masterfrom
DJMcNab:default_field_values
Closed

Support default field values#6053
DJMcNab wants to merge 5 commits intoclap-rs:masterfrom
DJMcNab:default_field_values

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

@DJMcNab
Copy link
Author

DJMcNab commented Jan 11, 2026

Closing in favour of #6220

@DJMcNab DJMcNab closed this Jan 11, 2026
@DJMcNab DJMcNab deleted the default_field_values branch January 11, 2026 17:30
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