First example of Arg::default_value_if uses the wrong predicate
Author: pikselCreated May 14, 2023Updated Aug 25, 2026
LabelsC-bugA-docsS-blocked
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Rust Version
rustc 1.69.0 (84c898d65 2023-04-16)
Clap Version
4.2.2 (also confirmed present in master)
Minimal reproducible code
Not applicable.
Steps to reproduce the bug with the above code
- Read the examples in docs for
Arg::default_value_if. - Even though the docs says "using the same test", the predicate is changed in the second example (probably because otherwise it would not pass the assertion).
Actual Behaviour
.default_value_if("flag", ArgPredicate::IsPresent, Some("default")))The predicate used in the first example doesn't actually do anything, as it sets the default value regardless of whether the flag is passed.
Expected Behaviour
Should use the same predicate as the second example:
.default_value_if("flag", "true", Some("default")))Additional Context
No response
Debug Output
No response
Source: clap-rs/clap