diff --git a/src/cargo/core/compiler/job_queue/job_state.rs b/src/cargo/core/compiler/job_queue/job_state.rs index 06be9193820..19d0f8e9772 100644 --- a/src/cargo/core/compiler/job_queue/job_state.rs +++ b/src/cargo/core/compiler/job_queue/job_state.rs @@ -8,6 +8,7 @@ use crate::core::compiler::future_incompat::FutureBreakageItem; use crate::core::compiler::locking::LockKey; use crate::core::compiler::timings::SectionTiming; use crate::util::Queue; +use crate::util::context::WarningHandling; use crate::{CargoResult, core::compiler::locking::LockManager}; use super::{Artifact, DiagDedupe, Job, JobId, Message}; @@ -51,6 +52,8 @@ pub struct JobState<'a, 'gctx> { /// Manages locks for build units when fine grain locking is enabled. lock_manager: Arc, + warning_handling: WarningHandling, + // Historical versions of Cargo made use of the `'a` argument here, so to // leave the door open to future refactorings keep it here. _marker: marker::PhantomData<&'a ()>, @@ -63,6 +66,7 @@ impl<'a, 'gctx> JobState<'a, 'gctx> { output: Option<&'a DiagDedupe<'gctx>>, rmeta_required: bool, lock_manager: Arc, + warning_handling: WarningHandling, ) -> Self { Self { id, @@ -70,6 +74,7 @@ impl<'a, 'gctx> JobState<'a, 'gctx> { output, rmeta_required: Cell::new(rmeta_required), lock_manager, + warning_handling, _marker: marker::PhantomData, } } @@ -106,7 +111,9 @@ impl<'a, 'gctx> JobState<'a, 'gctx> { lint: bool, fixable: bool, ) -> CargoResult<()> { - if let Some(dedupe) = self.output { + if level == "warning" && self.warning_handling == WarningHandling::Allow { + tracing::warn!("{diag}"); + } else if let Some(dedupe) = self.output { let emitted = dedupe.emit_diag(&diag)?; if level == "warning" { self.messages.push(Message::WarningCount { diff --git a/src/cargo/core/compiler/job_queue/mod.rs b/src/cargo/core/compiler/job_queue/mod.rs index 7cdab7e2bd6..d459243b67a 100644 --- a/src/cargo/core/compiler/job_queue/mod.rs +++ b/src/cargo/core/compiler/job_queue/mod.rs @@ -988,9 +988,17 @@ impl<'gctx> DrainState<'gctx> { let is_fresh = job.freshness().is_fresh(); let rmeta_required = build_runner.rmeta_required(unit); let lock_manager = build_runner.lock_manager.clone(); + let warning_handling = build_runner.bcx.gctx.warning_handling().unwrap_or_default(); let doit = move |diag_dedupe| { - let state = JobState::new(id, messages, diag_dedupe, rmeta_required, lock_manager); + let state = JobState::new( + id, + messages, + diag_dedupe, + rmeta_required, + lock_manager, + warning_handling, + ); state.run_to_finish(job); }; diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index a6b6df8ba06..6a9ddc47119 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -105,7 +105,6 @@ use crate::core::profiles::{PanicStrategy, Profile, StripInner}; use crate::core::{Feature, PackageId, Target}; use crate::lints::get_key_value; use crate::util::OnceExt; -use crate::util::context::WarningHandling; use crate::util::errors::{CargoResult, VerboseError}; use crate::util::interning::InternedString; use crate::util::machine_message::{self, Message}; @@ -2026,8 +2025,7 @@ impl OutputOptions { drop(fs::remove_file(&path)); let cache_cell = Some((path, OnceCell::new())); - let show_diagnostics = - build_runner.bcx.gctx.warning_handling().unwrap_or_default() != WarningHandling::Allow; + let show_diagnostics = true; let format = build_runner.bcx.build_config.message_format; @@ -2045,9 +2043,7 @@ impl OutputOptions { // We always replay the output cache, // since it might contain future-incompat-report messages - let show_diagnostics = unit.show_warnings(build_runner.bcx.gctx) - && build_runner.bcx.gctx.warning_handling().unwrap_or_default() - != WarningHandling::Allow; + let show_diagnostics = unit.show_warnings(build_runner.bcx.gctx); let format = build_runner.bcx.build_config.message_format; diff --git a/tests/testsuite/warning_override.rs b/tests/testsuite/warning_override.rs index c741b3d6b92..35b25daea10 100644 --- a/tests/testsuite/warning_override.rs +++ b/tests/testsuite/warning_override.rs @@ -40,6 +40,26 @@ fn requires_nightly() { .run(); } +#[cargo_test] +fn always_show_error_diags() { + let p = make_project_with_rustc_warning(); + p.cargo("check") + .masquerade_as_nightly_cargo(&["warnings"]) + .env("RUSTFLAGS", "-Dunused_variables") + .arg("-Zwarnings") + .arg("--config") + .arg("build.warnings='allow'") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[ERROR] unused variable: `x` +... +[ERROR] could not compile `foo` (bin "foo") due to 1 previous error + +"#]]) + .with_status(101) + .run(); +} + #[cargo_test] fn clippy() { let p = project()