@@ -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 {
0 commit comments