]> git.proxmox.com Git - cargo.git/blobdiff - src/cargo/core/compiler/unit_dependencies.rs
Document lib before bin.
[cargo.git] / src / cargo / core / compiler / unit_dependencies.rs
index ae8ca69aa4648b22bab88c6daeebf8ac6f4ec937..5d8306fca4d7beab59cae73c40fe72126a35e16c 100644 (file)
@@ -132,7 +132,7 @@ fn calc_deps_of_std(
     // Compute dependencies for the standard library.
     state.is_std = true;
     for roots in std_roots.values() {
-        deps_of_roots(roots, &mut state)?;
+        deps_of_roots(roots, state)?;
     }
     state.is_std = false;
     Ok(Some(std::mem::take(&mut state.unit_dependencies)))
@@ -172,7 +172,7 @@ fn attach_std_deps(
 
 /// Compute all the dependencies of the given root units.
 /// The result is stored in state.unit_dependencies.
-fn deps_of_roots(roots: &[Unit], mut state: &mut State<'_, '_>) -> CargoResult<()> {
+fn deps_of_roots(roots: &[Unit], state: &mut State<'_, '_>) -> CargoResult<()> {
     for unit in roots.iter() {
         // Dependencies of tests/benches should not have `panic` set.
         // We check the global test mode to see if we are running in `cargo
@@ -200,7 +200,7 @@ fn deps_of_roots(roots: &[Unit], mut state: &mut State<'_, '_>) -> CargoResult<(
         } else {
             UnitFor::new_normal()
         };
-        deps_of(unit, &mut state, unit_for)?;
+        deps_of(unit, state, unit_for)?;
     }
 
     Ok(())
@@ -326,7 +326,7 @@ fn compute_deps(
     if unit.target.is_lib() && unit.mode != CompileMode::Doctest {
         return Ok(ret);
     }
-    ret.extend(maybe_lib(unit, state, unit_for)?);
+    ret.extend(maybe_lib(unit, state, unit_for, None)?);
 
     // If any integration tests/benches are being run, make sure that
     // binaries are built as well.
@@ -469,7 +469,10 @@ fn compute_deps_doc(
 
     // If we document a binary/example, we need the library available.
     if unit.target.is_bin() || unit.target.is_example() {
-        ret.extend(maybe_lib(unit, state, unit_for)?);
+        // build the lib
+        ret.extend(maybe_lib(unit, state, unit_for, None)?);
+        // and also the lib docs for intra-doc links
+        ret.extend(maybe_lib(unit, state, unit_for, Some(unit.mode))?);
     }
 
     // Add all units being scraped for examples as a dependency of Doc units.
@@ -497,13 +500,14 @@ fn maybe_lib(
     unit: &Unit,
     state: &mut State<'_, '_>,
     unit_for: UnitFor,
+    force_mode: Option<CompileMode>,
 ) -> CargoResult<Option<UnitDep>> {
     unit.pkg
         .targets()
         .iter()
         .find(|t| t.is_linkable())
         .map(|t| {
-            let mode = check_or_build_mode(unit.mode, t);
+            let mode = force_mode.unwrap_or_else(|| check_or_build_mode(unit.mode, t));
             let dep_unit_for = unit_for.with_dependency(unit, t);
             new_unit_dep(
                 state,