From 12aa62cab1954e7158928c7bded1afcec4f440d9 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 2 Dec 2025 00:01:38 -0500 Subject: [PATCH 1/2] test(lints): show lint error number This wasn't shown because AlreadyPrintedError was skipped. --- .../lints/blanket_hint_mostly_unused.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/testsuite/lints/blanket_hint_mostly_unused.rs b/tests/testsuite/lints/blanket_hint_mostly_unused.rs index 18e55a8447b..2422d3e6395 100644 --- a/tests/testsuite/lints/blanket_hint_mostly_unused.rs +++ b/tests/testsuite/lints/blanket_hint_mostly_unused.rs @@ -165,3 +165,45 @@ authors = [] "#]]) .run(); } + +#[cargo_test(nightly, reason = "-Zhint-mostly-unused is unstable")] +fn deny() { + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.0.1" +edition = "2015" + +[profile.dev] +hint-mostly-unused = true + +[lints.cargo] +blanket_hint_mostly_unused = "deny" +"#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + p.cargo("check -Zprofile-hint-mostly-unused -v -Zcargo-lints") + .masquerade_as_nightly_cargo(&["profile-hint-mostly-unused", "cargo-lints"]) + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] `hint-mostly-unused` is being blanket applied to all dependencies + --> Cargo.toml:7:10 + | +7 | [profile.dev] + | ^^^ +8 | hint-mostly-unused = true + | ------------------------- + | + = [NOTE] `cargo::blanket_hint_mostly_unused` is set to `deny` in `[lints]` +[HELP] scope `hint-mostly-unused` to specific packages with a lot of unused object code + | +7 | [profile.dev.package.] + | +++++++++++++++++++ + +"#]]) + .run(); +} From a594f32cdcf1ff44d9216ea9b8fa92d0f706416a Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 2 Dec 2025 00:03:35 -0500 Subject: [PATCH 2/2] fix(lints): plural form correctly --- src/cargo/core/workspace.rs | 6 ++---- tests/testsuite/lints/blanket_hint_mostly_unused.rs | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 8035ad74265..6fd76e42e9e 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1348,10 +1348,8 @@ impl<'gctx> Workspace<'gctx> { } if error_count > 0 { - Err(crate::util::errors::AlreadyPrintedError::new(anyhow!( - "encountered {error_count} errors(s) while running lints" - )) - .into()) + let plural = if error_count == 1 { "" } else { "s" }; + bail!("encountered {error_count} error{plural} while running lints") } else { Ok(()) } diff --git a/tests/testsuite/lints/blanket_hint_mostly_unused.rs b/tests/testsuite/lints/blanket_hint_mostly_unused.rs index 2422d3e6395..70cc099c19c 100644 --- a/tests/testsuite/lints/blanket_hint_mostly_unused.rs +++ b/tests/testsuite/lints/blanket_hint_mostly_unused.rs @@ -203,6 +203,7 @@ blanket_hint_mostly_unused = "deny" | 7 | [profile.dev.package.] | +++++++++++++++++++ +[ERROR] encountered 1 error while running lints "#]]) .run();