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

Improved compiler errors when feature flags are missing #123

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ranger-ross
Copy link

This PR adds improved compiler errors when features flags are not enabled.

For example:
Given this following struct,

#[derive(Validate)]
struct User<'a> {
    #[garde(email)]
    email: &'a str,
}

without the email feature flag enabled, the following error message is output.

error: Validation rule `email` not found. Did you forget to add the `email` feature flag?
  --> src/main.rs:23:13
   |
23 |     #[garde(email)]
   |             ^^^^^

See original issue here #9

@ranger-ross ranger-ross changed the title Improved errors messages when feature flags are missing Improved compiler errors when feature flags are missing Jul 27, 2024
garde_derive/src/syntax.rs Outdated Show resolved Hide resolved
garde/Cargo.toml Show resolved Hide resolved
@jprochazk
Copy link
Owner

There's also the question of how to test this. It doesn't seem like trybuild exposes the ability to change the feature set used to compile a specific file. Do you have any ideas?

@ranger-ross
Copy link
Author

There's also the question of how to test this. It doesn't seem like trybuild exposes the ability to change the feature set used to compile a specific file. Do you have any ideas?

I also have this problem in actix-web-validation and I have not found a nice solution 😅

I think one way would be to use trybuild in combination with #[cfg_attr(not(feature = "foo"), ignore)] added to the tests to enable/disable tests depending on the enabled features flags. But this requires running cargo test multiple times with different --feature <flag> combinations, which I don't love 🙁

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.

2 participants