Skip to content

Fix cargo tree -p output with feature-unification=workspace#16584

Open
terror wants to merge 4 commits intorust-lang:masterfrom
terror:tree-workspace-output
Open

Fix cargo tree -p output with feature-unification=workspace#16584
terror wants to merge 4 commits intorust-lang:masterfrom
terror:tree-workspace-output

Conversation

@terror
Copy link
Contributor

@terror terror commented Feb 3, 2026

Resolves #16583

When using feature-unification=workspace, running cargo tree -p <package> incorrectly displayed trees for all workspace members instead of just the requested package.

@rustbot rustbot added Command-tree S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 3, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 3, 2026

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@terror terror changed the title Fix cargo tree -p to respect package filter with feature-unification=workspace Fix cargo tree -p output with feature-unification=workspace Feb 3, 2026
@terror terror force-pushed the tree-workspace-output branch from 84de652 to d526e1e Compare February 3, 2026 03:16

entry_ids
.into_iter()
.filter(|id| requested_ids.contains(id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I need to dig into is why this filtering happens rather than just returning requested_ids

let root_specs = if opts.invert.is_empty() {
specs
let root_ids = if opts.invert.is_empty() {
let entry_ids = ws_resolve.targeted_resolve.specs_to_ids(&specs)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug with the specs that is returned? Are there other places that are negatively impacted by this behavior?

Copy link
Contributor Author

@terror terror Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaict, this appears specific to tree root selection; resolve_ws_with_opts behavior is intentional for workspace feature resolution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you go into detail on why you feel that way? Feature resolution has already happened by the end of the function. Why would a caller need specs unrelated to their use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies if I'm not making myself clear enough, I'm still getting up to speed with this area of the codebase 😅

My understanding here is that in this function specs is the user request, while each SpecsAndResolvedFeatures entry can have a different specs scope depending on feature-unification mode. I renamed that loop binding to entry_specs to make that distinction explicit.

We'll then build the graph with the feature resolution scope for that entry, but roots should still respect the users choice of packages (i.e. -p), so I compute requested_ids from outer specs and intersect with entry_ids from entry_specs.

So in the end resolve_ws_with_opts behavior is intentional here, with the core issue being how tree interpreted it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is talking about cargo tree but not compilation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, because this PR (and underlying issue) is scoped to cargo tree. Compilation is doing something similar however.

What I'm trying to establish as common understanding here is that cargo tree used specs derived from resolve_ws_with_opts as display roots, which works in some modes, but with feature-unification=workspace those specs are intentionally broader (workspace-wide), so it over-printed roots (the issue at hand here).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. What I'm looking at with this is where is the correct place to resolve this problem. Is resolve_ws_with_opts upholding its promises as an abstraction? If it is, then yes, this is on cargo trees side. If not, then we should fix resolve_ws_with_opts. From my high level inspection, this looks like resolve_ws_with_opts is not behaving correctly and cargo tree is correctly doing what it is told. If that is not the case, I want to understand why.

@terror terror force-pushed the tree-workspace-output branch from d526e1e to e1613f8 Compare February 12, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Command-tree S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo tree output with feature-unification with workspace shows other workspace members

4 participants