Skip to content

Commit bd45ac8

Browse files
committed
Inline non_custom_build_and_non_transitive_deps
Signed-off-by: hi-rustin <[email protected]>
1 parent 81c2cd5 commit bd45ac8

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn compute_deps(
242242
}
243243

244244
let id = unit.pkg.package_id();
245-
let filtered_deps = non_custom_build_and_non_transitive_deps(unit, state, unit_for);
245+
let filtered_deps = state.deps(unit, unit_for);
246246

247247
let mut ret = Vec::new();
248248
let mut dev_deps = Vec::new();
@@ -349,37 +349,6 @@ fn compute_deps(
349349
Ok(ret)
350350
}
351351

352-
/// Returns non-custom and non-transitive dependencies.
353-
fn non_custom_build_and_non_transitive_deps<'a>(
354-
unit: &Unit,
355-
state: &'a State<'_, '_>,
356-
unit_for: UnitFor,
357-
) -> Vec<(PackageId, &'a HashSet<Dependency>)> {
358-
state.deps(unit, unit_for, &|dep| {
359-
// If this target is a build command, then we only want build
360-
// dependencies, otherwise we want everything *other than* build
361-
// dependencies.
362-
if unit.target.is_custom_build() != dep.is_build() {
363-
return false;
364-
}
365-
366-
// If this dependency is **not** a transitive dependency, then it
367-
// only applies to test/example targets.
368-
if !dep.is_transitive()
369-
&& !unit.target.is_test()
370-
&& !unit.target.is_example()
371-
&& !unit.mode.is_doc_scrape()
372-
&& !unit.mode.is_any_test()
373-
{
374-
return false;
375-
}
376-
377-
// If we've gotten past all that, then this dependency is
378-
// actually used!
379-
true
380-
})
381-
}
382-
383352
/// Returns the dependencies needed to run a build script.
384353
///
385354
/// The `unit` provided must represent an execution of a build script, and
@@ -431,7 +400,7 @@ fn compute_deps_doc(
431400
state: &mut State<'_, '_>,
432401
unit_for: UnitFor,
433402
) -> CargoResult<Vec<UnitDep>> {
434-
let deps = non_custom_build_and_non_transitive_deps(unit, state, unit_for);
403+
let deps = state.deps(unit, unit_for);
435404

436405
// To document a library, we depend on dependencies actually being
437406
// built. If we're documenting *all* libraries, then we also depend on
@@ -839,22 +808,32 @@ impl<'a, 'cfg> State<'a, 'cfg> {
839808
}
840809

841810
/// Returns a filtered set of dependencies for the given unit.
842-
fn deps(
843-
&self,
844-
unit: &Unit,
845-
unit_for: UnitFor,
846-
filter: &dyn Fn(&Dependency) -> bool,
847-
) -> Vec<(PackageId, &HashSet<Dependency>)> {
811+
fn deps(&self, unit: &Unit, unit_for: UnitFor) -> Vec<(PackageId, &HashSet<Dependency>)> {
848812
let pkg_id = unit.pkg.package_id();
849813
let kind = unit.kind;
850814
self.resolve()
851815
.deps(pkg_id)
852816
.filter(|&(_id, deps)| {
853817
assert!(!deps.is_empty());
854818
deps.iter().any(|dep| {
855-
if !filter(dep) {
819+
// If this target is a build command, then we only want build
820+
// dependencies, otherwise we want everything *other than* build
821+
// dependencies.
822+
if unit.target.is_custom_build() != dep.is_build() {
823+
return false;
824+
}
825+
826+
// If this dependency is **not** a transitive dependency, then it
827+
// only applies to test/example targets.
828+
if !dep.is_transitive()
829+
&& !unit.target.is_test()
830+
&& !unit.target.is_example()
831+
&& !unit.mode.is_doc_scrape()
832+
&& !unit.mode.is_any_test()
833+
{
856834
return false;
857835
}
836+
858837
// If this dependency is only available for certain platforms,
859838
// make sure we're only enabling it for that platform.
860839
if !self.target_data.dep_platform_activated(dep, kind) {
@@ -870,6 +849,8 @@ impl<'a, 'cfg> State<'a, 'cfg> {
870849
}
871850
}
872851

852+
// If we've gotten past all that, then this dependency is
853+
// actually used!
873854
true
874855
})
875856
})

0 commit comments

Comments
 (0)