← back

+/feature-unification-test

git clone https://git.julia.blue/+/feature-unification-test

Julia RyanInitial commit1382ea7

main
3 folders3 files

files

dep-a/
dep-b/
root/
Cargo.lock1.7 KiB
Cargo.toml186 B
README.md747 B

Feature unification lets you access an API you shouldn't be able to.

This workspace has a root binary which depends on 2 crates, each of which depend on serde but only one of them adds the derive feature.

building the whole workspace (including dep-b) succeeds, and uses a single copy of serde with serde-derive enabled (because dep-a needed it):

cargo b

... but building just dep-b fails because it's using serde::Deserialize without enabling the derive feature

cargo b -p dep-b

this behavior was quite surprising to me. I assumed that even in the face of feature unification there was some way that the compiler was made aware of which features your crate was actually "allowed" to use, but that's not the case.