@@ -22,7 +22,7 @@ use crate::core::dependency::DepKind;
22
22
use crate :: core:: profiles:: { Profile , Profiles , UnitFor } ;
23
23
use crate :: core:: resolver:: features:: { FeaturesFor , ResolvedFeatures } ;
24
24
use crate :: core:: resolver:: Resolve ;
25
- use crate :: core:: { Package , PackageId , PackageSet , Target , Workspace } ;
25
+ use crate :: core:: { Dependency , Package , PackageId , PackageSet , Target , Workspace } ;
26
26
use crate :: ops:: resolve_all_features;
27
27
use crate :: util:: interning:: InternedString ;
28
28
use crate :: util:: Config ;
@@ -223,50 +223,33 @@ fn compute_deps(
223
223
}
224
224
225
225
let id = unit. pkg . package_id ( ) ;
226
- let filtered_deps = state. resolve ( ) . deps ( id) . filter ( |& ( _id, deps) | {
227
- assert ! ( !deps. is_empty( ) ) ;
228
- deps. iter ( ) . any ( |dep| {
229
- // If this target is a build command, then we only want build
230
- // dependencies, otherwise we want everything *other than* build
231
- // dependencies.
232
- if unit. target . is_custom_build ( ) != dep. is_build ( ) {
233
- return false ;
234
- }
235
-
236
- // If this dependency is **not** a transitive dependency, then it
237
- // only applies to test/example targets.
238
- if !dep. is_transitive ( )
239
- && !unit. target . is_test ( )
240
- && !unit. target . is_example ( )
241
- && !unit. mode . is_any_test ( )
242
- {
243
- return false ;
244
- }
245
-
246
- // If this dependency is only available for certain platforms,
247
- // make sure we're only enabling it for that platform.
248
- if !state. target_data . dep_platform_activated ( dep, unit. kind ) {
249
- return false ;
250
- }
251
-
252
- // If this is an optional dependency, and the new feature resolver
253
- // did not enable it, don't include it.
254
- if dep. is_optional ( ) {
255
- let features_for = unit_for. map_to_features_for ( ) ;
226
+ let filtered_deps = state
227
+ . deps ( unit, unit_for)
228
+ . into_iter ( )
229
+ . filter ( |& ( _id, deps) | {
230
+ deps. iter ( ) . any ( |dep| {
231
+ // If this target is a build command, then we only want build
232
+ // dependencies, otherwise we want everything *other than* build
233
+ // dependencies.
234
+ if unit. target . is_custom_build ( ) != dep. is_build ( ) {
235
+ return false ;
236
+ }
256
237
257
- let feats = state. activated_features ( id, features_for) ;
258
- if !feats. contains ( & dep. name_in_toml ( ) ) {
238
+ // If this dependency is **not** a transitive dependency, then it
239
+ // only applies to test/example targets.
240
+ if !dep. is_transitive ( )
241
+ && !unit. target . is_test ( )
242
+ && !unit. target . is_example ( )
243
+ && !unit. mode . is_any_test ( )
244
+ {
259
245
return false ;
260
246
}
261
- }
262
247
263
- // If we've gotten past all that, then this dependency is
264
- // actually used!
265
- true
266
- } )
267
- } ) ;
268
- // Separate line to avoid rustfmt indentation. Must collect due to `state` capture.
269
- let filtered_deps: Vec < _ > = filtered_deps. collect ( ) ;
248
+ // If we've gotten past all that, then this dependency is
249
+ // actually used!
250
+ true
251
+ } )
252
+ } ) ;
270
253
271
254
let mut ret = Vec :: new ( ) ;
272
255
for ( id, _) in filtered_deps {
@@ -410,16 +393,10 @@ fn compute_deps_custom_build(
410
393
411
394
/// Returns the dependencies necessary to document a package.
412
395
fn compute_deps_doc ( unit : & Unit , state : & mut State < ' _ , ' _ > ) -> CargoResult < Vec < UnitDep > > {
413
- let target_data = state. target_data ;
414
396
let deps = state
415
- . resolve ( )
416
- . deps ( unit. pkg . package_id ( ) )
417
- . filter ( |& ( _id, deps) | {
418
- deps. iter ( ) . any ( |dep| match dep. kind ( ) {
419
- DepKind :: Normal => target_data. dep_platform_activated ( dep, unit. kind ) ,
420
- _ => false ,
421
- } )
422
- } ) ;
397
+ . deps ( unit, UnitFor :: new_normal ( ) )
398
+ . into_iter ( )
399
+ . filter ( |& ( _id, deps) | deps. iter ( ) . any ( |dep| dep. kind ( ) == DepKind :: Normal ) ) ;
423
400
424
401
// To document a library, we depend on dependencies actually being
425
402
// built. If we're documenting *all* libraries, then we also depend on
@@ -741,4 +718,36 @@ impl<'a, 'cfg> State<'a, 'cfg> {
741
718
. get_one ( id)
742
719
. unwrap_or_else ( |_| panic ! ( "expected {} to be downloaded" , id) )
743
720
}
721
+
722
+ /// Returns a filtered set of dependencies for the given unit.
723
+ fn deps ( & self , unit : & Unit , unit_for : UnitFor ) -> Vec < ( PackageId , & HashSet < Dependency > ) > {
724
+ let pkg_id = unit. pkg . package_id ( ) ;
725
+ let kind = unit. kind ;
726
+ self . resolve ( )
727
+ . deps ( pkg_id)
728
+ . filter ( |& ( _id, deps) | {
729
+ assert ! ( !deps. is_empty( ) ) ;
730
+ deps. iter ( ) . any ( |dep| {
731
+ // If this dependency is only available for certain platforms,
732
+ // make sure we're only enabling it for that platform.
733
+ if !self . target_data . dep_platform_activated ( dep, kind) {
734
+ return false ;
735
+ }
736
+
737
+ // If this is an optional dependency, and the new feature resolver
738
+ // did not enable it, don't include it.
739
+ if dep. is_optional ( ) {
740
+ let features_for = unit_for. map_to_features_for ( ) ;
741
+
742
+ let feats = self . activated_features ( pkg_id, features_for) ;
743
+ if !feats. contains ( & dep. name_in_toml ( ) ) {
744
+ return false ;
745
+ }
746
+ }
747
+
748
+ true
749
+ } )
750
+ } )
751
+ . collect ( )
752
+ }
744
753
}
0 commit comments