From e44bde554d0c6be5d333f8ccdfc250b9592538e9 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 12 Jul 2025 12:37:53 -0700 Subject: [PATCH] Respect capped lints for dependencies --- src/cargo/core/compiler/mod.rs | 12 ++++++++++-- tests/testsuite/hints.rs | 2 -- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 085b1541b..fa8239edf 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1148,6 +1148,13 @@ fn build_base_args( unit.pkg.package_id().version() )) }; + let unit_capped_warn = |msg: &str| { + if unit.show_warnings(bcx.gctx) { + warn(msg) + } else { + Ok(()) + } + }; cmd.arg("--crate-name").arg(&unit.target.crate_name()); @@ -1339,7 +1346,7 @@ fn build_base_args( None => None, Some(toml::Value::Boolean(b)) => Some(b), Some(v) => { - warn(&format!( + unit_capped_warn(&format!( "ignoring unsupported value type ({}) for 'hints.mostly-unused', which expects a boolean", v.type_str() ))?; @@ -1354,11 +1361,12 @@ fn build_base_args( cmd.arg("-Zhint-mostly-unused"); } else { if profile_hint_mostly_unused.is_some() { + // Profiles come from the top-level unit, so we don't use `unit_capped_warn` here. warn( "ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it", )?; } else if pkg_hint_mostly_unused.is_some() { - warn( + unit_capped_warn( "ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it", )?; } diff --git a/tests/testsuite/hints.rs b/tests/testsuite/hints.rs index 04b912a03..ef4d84a14 100644 --- a/tests/testsuite/hints.rs +++ b/tests/testsuite/hints.rs @@ -124,7 +124,6 @@ fn hint_unknown_type_warn() { [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) [WARNING] foo@0.0.1: ignoring unsupported value type (string) for 'hints.mostly-unused', which expects a boolean -[WARNING] bar@1.0.0: ignoring unsupported value type (integer) for 'hints.mostly-unused', which expects a boolean [CHECKING] bar v1.0.0 [RUNNING] `rustc --crate-name bar [..]` [CHECKING] foo v0.0.1 ([ROOT]/foo) @@ -178,7 +177,6 @@ fn hints_mostly_unused_warn_without_gate() { [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) [WARNING] foo@0.0.1: ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it -[WARNING] bar@1.0.0: ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it [CHECKING] bar v1.0.0 [RUNNING] `rustc --crate-name bar [..]` [CHECKING] foo v0.0.1 ([ROOT]/foo)