Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cargo/core/compiler/job_queue/job_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -51,6 +52,8 @@ pub struct JobState<'a, 'gctx> {
/// Manages locks for build units when fine grain locking is enabled.
lock_manager: Arc<LockManager>,

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 ()>,
Expand All @@ -63,13 +66,15 @@ impl<'a, 'gctx> JobState<'a, 'gctx> {
output: Option<&'a DiagDedupe<'gctx>>,
rmeta_required: bool,
lock_manager: Arc<LockManager>,
warning_handling: WarningHandling,
) -> Self {
Self {
id,
messages,
output,
rmeta_required: Cell::new(rmeta_required),
lock_manager,
warning_handling,
_marker: marker::PhantomData,
}
}
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion src/cargo/core/compiler/job_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
8 changes: 2 additions & 6 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
20 changes: 20 additions & 0 deletions tests/testsuite/warning_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down