-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Check manifest for requiring nonexistent features #7950
Check manifest for requiring nonexistent features #7950
Conversation
r? @ehuss (rust_highfive has picked a reviewer for you, use r? to override) |
This will probably need to be a warning instead of an error, since this will affect a number of existing packages. We can then maybe turn it to an error in the distant future. I think it might be better to take a different approach here. Optional dependencies create implicitly named features which are not defined in the I think to handle this properly, it would be best to put the validation in |
This function quits in the beginning on this condition:
Reading the docs for root_manifest (when it's None) makes me believe that there won't be any validation done if no workspace was declared in Cargo.toml:
@ehuss Wouldn't it lead to the issue persisting for projects with no workspaces if we do the check in this function? |
I think it would be fine to split up the validation function so it was a little clearer (and not nearly 200 lines long). Maybe something like: fn validate(&mut self) -> CargoResult<()> {
if self.root_manifest.is_some() {
// These checks require a VirtualManifest or multiple members.
self.validate_unique_names()?;
self.validate_ws_roots()?;
self.validate_members()?;
self.validate_unused()?;
}
self.validate_required_features()?;
Ok(())
} |
@ehuss What about features with '::' instead of slash? |
Hm, sorry, I think I may have led you astray with how validation should be done. For some reason I was thinking the We want to accurately parse required-features and handle them the same way as Cargo normally interprets them. I'm thinking the right route here is to change how required-features are checked. Currently in There isn't anything that will do that directly, so it will require some new code. Checking will depend on the
To check if the feature is enabled, it should be a little simpler, just calling One drawback to this approach is that it will only validate when you try to build the target, but I think that is fine. Hopefully that's not too confusing. Let me know if you have any questions. |
When trying to solve this as per your first suggestion, I noticed that if you have features listed like this:
...and you call FeatureValue::new() on them they are parsed like:
Meaning that non-existing features (+ the ones with ::) are parsed as Crate, and if they have '/' as CrateFeature. Would it be correct? |
Yes, assuming there isn't an optional dependency by that name. |
I just pushed a draft to get some feedback: is the logic already introduced is correct at least. Still need to wrap my head around:
|
ba930f6
to
003a8e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there will be anything special needed for the crate:
syntax, since FeatureValue
takes care of that.
Warnings are done through Shell.warn
. A shell instance can be obtained through config.shell()
.
☔ The latest upstream changes (presumably #8068) made this pull request unmergeable. Please resolve the merge conflicts. |
7223cab
to
2368654
Compare
Hi @ehuss! I have applied your suggestions to the code. There is one more thing I want to clarify about the behavior for optional dependencies. If you run
This optional dependency is specified in required-features and in [features] sections though, so it should be found. It is not, however, present in the Is there a bug somewhere (in the function, in my manifest, in the resolver) or am I misunderstanding how it is supposed to work and the resulting warning is correct? |
Hm, so the issue here is the the Resolver has already filtered out any optional dependencies that are not enabled, so I think the solution is to use I'd suggest passing I think that should work. Sorry this is ending up to be a bit of a tricky problem, but the PR is looking pretty good to me! |
2368654
to
04a1703
Compare
Co-authored-by: Eric Huss <eric@huss.org>
04a1703
to
19a9579
Compare
@ehuss Thank you, that worked! I had to add
You have a patience of a saint. It was probably 10 times easier to do all of this yourself than to explain the proper solution to me :) As a side note, I had to fix one of the benchmark tests since it generated a new warning and noticed that all of them only run on a nightly compiler. Is there a reason for it or should they be enabled on stable as well? |
Thanks! As for the benchmark tests, benchmarks are not stable so they only work on the nightly compiler. @bors r+ |
📌 Commit 19a9579 has been approved by |
☀️ Test successful - checks-actions |
Update cargo 14 commits in aa6872140ab0fa10f641ab0b981d5330d419e927..974eb438da8ced6e3becda2bbf63d9b643eacdeb 2020-07-23 13:46:27 +0000 to 2020-07-29 16:15:05 +0000 - Fix O0 build scripts by default without `[profile.release]` (rust-lang/cargo#8560) - Emphasize git dependency version locking behavior. (rust-lang/cargo#8561) - Update lock file encodings on changes (rust-lang/cargo#8554) - Fix sporadic lto test failures. (rust-lang/cargo#8559) - build-std: Fix libraries paths following upstream (rust-lang/cargo#8558) - Flag git http errors as maybe spurious (rust-lang/cargo#8553) - Display builtin aliases with `cargo --list` (rust-lang/cargo#8542) - Check manifest for requiring nonexistent features (rust-lang/cargo#7950) - Clarify test name filter usage (rust-lang/cargo#8552) - Revert Cargo Book changes for default edition (rust-lang/cargo#8551) - Prepare for not defaulting to master branch for git deps (rust-lang/cargo#8522) - Include `+` for crates.io feature requirements in the Cargo Book section on features (rust-lang/cargo#8547) - Update termcolor and fwdansi versions (rust-lang/cargo#8540) - Cargo book nitpick in Manifest section (rust-lang/cargo#8543)
Fixes #4854: Examples requiring a nonexistent feature should be an error
Thanks @lukaslueg with his #4874 for the inspiration!