Is this a bug? No, but it *feels* like a bug


C depends on a B which depends on A. One of B's features requires logic from one of A's features. If C only depends on B and not A then C won't compile unless B also includes A's features in its own definition of the feature that C is including.

I would have intuitively expected cargo magic to know that anything depending on B's feature also requires A's feature. Of course, it can't, so B must be explicit, but it caught me and and some of my team members out :-).

That's really hard to follow so here is a repo demonstrating it.

How is this different to expecting cargo magically knowing the correct features of any dependency?

For example, X depends on Y and its code depends on Y/foo.

1 Like

exactly - it can't.

It's obvious when you realise, my point was a few of us were caught assuming the wrong thing ("it dependencies...transitive dependencies are figured out by cargo...brain switches off"). :slight_smile:

From b-needs-a/Cargo.toml:

tests = ["arbtest/derive",
    # needs to export this because A/arbitrary is a compile time dependency otherwise `D` will fail

That's not an "export", you aren't exporting anything. That just means "the feature tests of this crate needs the feature tests of the a crate" and hence cargo automatically enables a's tests feature if b-needs-a's tests feature is enabled.

That kinda assumes you declare those dependencies. Not declaring you need a crate's feature is like not declaring this dependency. The ony difference is that cargo can only check this when you use b-needs-a's tests feature, while crate dependencies are always needed and hence always checked.

1 Like

Optimally what I think should happen (but doesn't) is that B doesn't build with broken dependency declarations like this, regardless of which features you actually select when building B.

I think it's technically feasible, at least for the usual kind of features that simply enable certain types or functions.


Yes, we are in violent agreement :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.