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

Report when a cfg(feature) refers to a feature which doesn't exist on a crate #11559

Closed
illicitonion opened this issue Jan 11, 2023 · 2 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@illicitonion
Copy link
Contributor

Problem

I have a crate with a feature.

I have CI which runs cargo test with that feature enabled.

I also have some tests which are specific to that feature, which are gated behind a cfg(feature) attribute.

However, there was a typo in the cfg(feature) attribute, which meant that the feature-specific tests were never actually enabled.

Ideally, I would have gotten a compile-time error telling me "You have a cfg(feature) which doesn't exist for your crate" (or just a standard unreachable code diagnostic). But at least a warning would be useful.

Proposed Solution

Provide an error, or at least warning, when a cfg(feature) attribute is used which Cargo doesn't treat as a feature for the crate being compiled.

Notes

I filed this against Cargo because it has the knowledge of the known features of a crate, but it's really a rustc feature request at core - I imagine this either looks like cargo supplying a known feature universe to rustc, or rustc reporting encountered features back to cargo.

@illicitonion illicitonion added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jan 11, 2023
@ehuss
Copy link
Contributor

ehuss commented Jan 11, 2023

There is an unstable feature called check-cfg which validates cfg expressions. Perhaps you could give it a try and see if it works with your project? Having people test nightly features (even if just once) is helpful since it can be difficult to get real-world testing.

@illicitonion
Copy link
Contributor Author

I tested it out and #10554 would indeed have prevented my issue - thanks for the pointer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants