Skip to content

Commit d526e1e

Browse files
committed
Fix cargo tree -p output with feature-unification=workspace
1 parent 956fdae commit d526e1e

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/cargo/ops/tree/mod.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
149149
// `FeatureResolver` will need to be taught what "all" means.
150150
let requested_kinds = CompileKind::from_requested_targets(ws.gctx(), &requested_targets)?;
151151
let mut target_data = RustcTargetData::new(ws, &requested_kinds)?;
152-
let specs = opts.packages.to_package_id_specs(ws)?;
152+
let requested_specs = opts.packages.to_package_id_specs(ws)?;
153153
let has_dev = if opts
154154
.edge_kinds
155155
.contains(&EdgeKind::Dep(DepKind::Development))
@@ -169,7 +169,7 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
169169
&mut target_data,
170170
&requested_kinds,
171171
&opts.cli_features,
172-
&specs,
172+
&requested_specs,
173173
has_dev,
174174
force_all,
175175
dry_run,
@@ -198,15 +198,29 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
198198
opts,
199199
)?;
200200

201-
let root_specs = if opts.invert.is_empty() {
202-
specs
201+
let root_ids = if opts.invert.is_empty() {
202+
let entry_ids = ws_resolve.targeted_resolve.specs_to_ids(&specs)?;
203+
204+
let requested_ids = ws_resolve
205+
.targeted_resolve
206+
.specs_to_ids(&requested_specs)?
207+
.into_iter()
208+
.collect::<HashSet<_>>();
209+
210+
entry_ids
211+
.into_iter()
212+
.filter(|id| requested_ids.contains(id))
213+
.collect()
203214
} else {
204-
opts.invert
215+
let invert_specs = opts
216+
.invert
205217
.iter()
206218
.map(|p| PackageIdSpec::parse(p))
207-
.collect::<Result<Vec<PackageIdSpec>, _>>()?
219+
.collect::<Result<Vec<PackageIdSpec>, _>>()?;
220+
221+
ws_resolve.targeted_resolve.specs_to_ids(&invert_specs)?
208222
};
209-
let root_ids = ws_resolve.targeted_resolve.specs_to_ids(&root_specs)?;
223+
210224
let root_indexes = graph.indexes_from_ids(&root_ids);
211225

212226
let root_indexes = if opts.duplicates {

tests/testsuite/feature_unification.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ b v0.1.0 ([ROOT]/foo/b)
835835
└── outside feature "default"
836836
└── outside v0.1.0
837837
838+
"#]])
839+
.run();
840+
841+
p.cargo("tree -p a")
842+
.arg("-Zfeature-unification")
843+
.masquerade_as_nightly_cargo(&["feature-unification"])
844+
.env("CARGO_RESOLVER_FEATURE_UNIFICATION", "workspace")
845+
.with_stdout_data(str![[r#"
846+
a v0.1.0 ([ROOT]/foo/a)
847+
├── common v0.1.0 ([ROOT]/foo/common)
848+
└── outside v0.1.0
849+
838850
"#]])
839851
.run();
840852
}

0 commit comments

Comments
 (0)