Github Refactor feature handling, and improve error messages. by ehuss · Pull Re...
source link: https://github.com/rust-lang/cargo/pull/9290
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
This changes the way feature strings are handled with an eye towards fixing some improper handling and to improve error messages. The key change is to stop treating all features as free-form strings and instead try to handle them as typed values. This helps avoid needing to deal with parsing different feature syntax (like dep:
or foo/bar
) or forgetting to handle it properly.
Overview of refactoring changes:
RequestedFeatures
changed to an enum to differentiate between features coming from the command-line, and those that are from a dependency.- Moved parsing of CLI features to an earlier stage (now stored in
CompileOptions
), and ensures that they are properly handled asFeatureValue
instead of strings. - Pushed some feature validation earlier. For example,
DetailedTomlDependency
now validates things so you can see the location for the errantCargo.toml
(previously some validation was deep in the resolver, which provided poor errors).
This is a pretty large PR, but at the core it is just changing RequestedFeatures
and then dealing with the fallout from that. Hopefully this is an improvement overall.
List of user-visible changes:
- Fix handling in resolver V2 of
--features bar?/feat
and--features dep:bar
- Better error handling for
bar/feat
anddep:bar
in dependency declarations. - Feature keys in the
[features]
table can no longer contain slashes. - Fixed a minor issue with
cargo tree -e features --all-features -Z namespaced-features
- Fixed a panic with
cargo tree
involving-Z weak-dep-features
I did a small amount of benchmarking, and I wasn't able to record much of a difference.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK