@@ -235,33 +235,28 @@ fn compute_deps(
235
235
}
236
236
237
237
let id = unit. pkg . package_id ( ) ;
238
- let filtered_deps = state
239
- . deps ( unit, unit_for)
240
- . into_iter ( )
241
- . filter ( |& ( _id, deps) | {
242
- deps. iter ( ) . any ( |dep| {
243
- // If this target is a build command, then we only want build
244
- // dependencies, otherwise we want everything *other than* build
245
- // dependencies.
246
- if unit. target . is_custom_build ( ) != dep. is_build ( ) {
247
- return false ;
248
- }
238
+ let filtered_deps = state. deps ( unit, unit_for, & |dep| {
239
+ // If this target is a build command, then we only want build
240
+ // dependencies, otherwise we want everything *other than* build
241
+ // dependencies.
242
+ if unit. target . is_custom_build ( ) != dep. is_build ( ) {
243
+ return false ;
244
+ }
249
245
250
- // If this dependency is **not** a transitive dependency, then it
251
- // only applies to test/example targets.
252
- if !dep. is_transitive ( )
253
- && !unit. target . is_test ( )
254
- && !unit. target . is_example ( )
255
- && !unit. mode . is_any_test ( )
256
- {
257
- return false ;
258
- }
246
+ // If this dependency is **not** a transitive dependency, then it
247
+ // only applies to test/example targets.
248
+ if !dep. is_transitive ( )
249
+ && !unit. target . is_test ( )
250
+ && !unit. target . is_example ( )
251
+ && !unit. mode . is_any_test ( )
252
+ {
253
+ return false ;
254
+ }
259
255
260
- // If we've gotten past all that, then this dependency is
261
- // actually used!
262
- true
263
- } )
264
- } ) ;
256
+ // If we've gotten past all that, then this dependency is
257
+ // actually used!
258
+ true
259
+ } ) ;
265
260
266
261
let mut ret = Vec :: new ( ) ;
267
262
let mut dev_deps = Vec :: new ( ) ;
@@ -419,10 +414,7 @@ fn compute_deps_doc(
419
414
state : & mut State < ' _ , ' _ > ,
420
415
unit_for : UnitFor ,
421
416
) -> CargoResult < Vec < UnitDep > > {
422
- let deps = state
423
- . deps ( unit, unit_for)
424
- . into_iter ( )
425
- . filter ( |& ( _id, deps) | deps. iter ( ) . any ( |dep| dep. kind ( ) == DepKind :: Normal ) ) ;
417
+ let deps = state. deps ( unit, unit_for, & |dep| dep. kind ( ) == DepKind :: Normal ) ;
426
418
427
419
// To document a library, we depend on dependencies actually being
428
420
// built. If we're documenting *all* libraries, then we also depend on
@@ -780,14 +772,22 @@ impl<'a, 'cfg> State<'a, 'cfg> {
780
772
}
781
773
782
774
/// Returns a filtered set of dependencies for the given unit.
783
- fn deps ( & self , unit : & Unit , unit_for : UnitFor ) -> Vec < ( PackageId , & HashSet < Dependency > ) > {
775
+ fn deps (
776
+ & self ,
777
+ unit : & Unit ,
778
+ unit_for : UnitFor ,
779
+ filter : & dyn Fn ( & Dependency ) -> bool ,
780
+ ) -> Vec < ( PackageId , & HashSet < Dependency > ) > {
784
781
let pkg_id = unit. pkg . package_id ( ) ;
785
782
let kind = unit. kind ;
786
783
self . resolve ( )
787
784
. deps ( pkg_id)
788
785
. filter ( |& ( _id, deps) | {
789
786
assert ! ( !deps. is_empty( ) ) ;
790
787
deps. iter ( ) . any ( |dep| {
788
+ if !filter ( dep) {
789
+ return false ;
790
+ }
791
791
// If this dependency is only available for certain platforms,
792
792
// make sure we're only enabling it for that platform.
793
793
if !self . target_data . dep_platform_activated ( dep, kind) {
0 commit comments