diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index f9c0cec873d..325d7434637 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -940,7 +940,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { ret.push(Unit { pkg: dep, target: lib, - profile: self.lib_profile(), + profile: self.lib_or_check_profile(unit, lib), kind: unit.kind.for_target(lib), }); if self.build_config.doc_all { @@ -1055,11 +1055,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } pub fn lib_or_check_profile(&self, unit: &Unit, target: &Target) -> &'a Profile { - if unit.profile.check && !target.is_custom_build() && !target.for_host() { - &self.profiles.check - } else { - self.lib_profile() + if !target.is_custom_build() && !target.for_host() { + if unit.profile.check || (unit.profile.doc && !unit.profile.test) { + return &self.profiles.check + } } + self.lib_profile() } pub fn build_script_profile(&self, _pkg: &PackageId) -> &'a Profile {