-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Run debug_asserts during compile time for derives #2740
Comments
Yes, this would not be possible with I was thinking maybe we could if It looks like we do have a debug_assert for this case, unless there is a corner we are missing. |
I wonder how frequently people use use clap::Clap;
#[derive(Clap)]
struct Opts {
#[clap(long, requires("foo", allow_missing))]
bar: i32
} to opt-out of the compile-time check for the field existing. |
I'm not familiar with the structure of clap - is |
It happens at runtime with debug builds. You could have your CI run |
Yeah, I just wrote a test that calls |
Thats understandable |
requires
and friends validate at compile-time in the new derive macro?
Note: #3133 is a subset of this issue. |
Due to the challenge of Our options
On top of this, this requires us to duplicate our debug asserts. We have added a If there are any concerns with us closing this, let us know! |
Please complete the following tasks
Clap Version
3.0.0-beta.4
Describe your use case
Consider the following app:
That app has a bug - the
foo
argument doesn't exist - but you don't have any way of finding out about it unless you actually run the application! In the real world, outside of the realm of contrived example code, this happened at $work where one parallel branch renamed an argument, while another added a new argument that required the old name - and since we didn't (previously, we do now) have a test covering option parsing, this went uncaught until we actually tried to run the binary.Describe the solution you'd like
I was thinking it'd be awesome if
#[derive(Clap)]
could detect usages ofrequires
(and other things that reference the name of another argument) and emit a compilation error if they reference arguments that don't exist. This might get a little hairy in the presence of#[clap(flatten)]
et al, though, and I'm not super familiar with the internals of derive macros so the information may well just not be available at this pointAlternatives, if applicable
Maybe if it's not feasible to do this inside the macro itself (or not desired, because of the weird interaction with
#[clap(flatten)]
we could instead have some sort of custom clippy lint that detects this?Additional Context
No response
The text was updated successfully, but these errors were encountered: