Open meithecatte opened 4 months ago
To confirm, this isn't just about feature unification which would make it a duplicate of #4463 but of finding ways to improve the reporting to help catch problems covered up by feature unification, right?
Increasing the interactions between rustc and cargo to help report this is reminiscent of
I believe to do this we'd need the rmeta to track what cfg's were applied to an item and its path and Cargo would need to tell rustc what cfg's would apply to an extern item without unification present.
cfg
and is present doesn't mean the item would not be present without the cfg
as a different implementation could be usedMaybe I'm missing something but I have the feeling this would be a lot of work to implement, potentially slow things down, and be inaccurate to the point that it couldn't be a rustc lint but a clippy nursery lint.
There are also third party solutions like cargo hack to more exhaustively catch problems like this. I wonder if continuing to recommend those is the best path forward.
Problem
Due to the way dependency features get consolidated across the packages that happen to be being built at the same time,
cargo check --all
can mask problems where insufficient features are specified for a dependency by one of the packages in a workspace.For the purposes of demonstration, I use a dependency (
dep
) within the workspace, but I originally observed this issue with a dependency from crates.io.Steps
Run the following command in an empty directory:
This creates the following files:
Cargo.toml
src/lib.rs
user1/Cargo.toml
user2/Cargo.toml
user*/src/main.rs
Run
cargo check --all
and note that it executes successfully. Conclude that all the packages in the workspace compile correctly.Run
cargo check -p user1
and have your expectations subverted –user1
only works becauseuser2
requested theopt
feature fromdep
.Possible Solution(s)
I am honestly unsure whether it's possible to solve this. Ideally
rustc
would track whether the items that are being accessed have actually been requested as features by the crate that's accessing them, or if they're compiled in because of a different consumer. Considering that trait implementations can becfg
'd out, I don't think this is practical.Still, I decided to report this surprising behavior in case someone here has any ideas on this.
Notes
No response
Version