From 9949fa8a6645e03d646e014b2b67acc26668e1ad Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 21 Jun 2025 16:17:00 -0700 Subject: [PATCH] Include package ID in warnings to identify affected crate --- src/cargo/core/compiler/mod.rs | 22 +++++++++++++++------- tests/testsuite/hints.rs | 4 ++-- tests/testsuite/profiles.rs | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 8915f16f8..085b1541b 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1141,6 +1141,14 @@ fn build_base_args( let hints = unit.pkg.hints().cloned().unwrap_or_default(); let test = unit.mode.is_any_test(); + let warn = |msg: &str| { + bcx.gctx.shell().warn(format!( + "{}@{}: {msg}", + unit.pkg.package_id().name(), + unit.pkg.package_id().version() + )) + }; + cmd.arg("--crate-name").arg(&unit.target.crate_name()); let edition = unit.target.edition(); @@ -1331,7 +1339,7 @@ fn build_base_args( None => None, Some(toml::Value::Boolean(b)) => Some(b), Some(v) => { - bcx.gctx.shell().warn(format!( + warn(&format!( "ignoring unsupported value type ({}) for 'hints.mostly-unused', which expects a boolean", v.type_str() ))?; @@ -1346,13 +1354,13 @@ fn build_base_args( cmd.arg("-Zhint-mostly-unused"); } else { if profile_hint_mostly_unused.is_some() { - bcx.gctx - .shell() - .warn("ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it")?; + warn( + "ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it", + )?; } else if pkg_hint_mostly_unused.is_some() { - bcx.gctx - .shell() - .warn("ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it")?; + 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 6cbfedacb..defe314b7 100644 --- a/tests/testsuite/hints.rs +++ b/tests/testsuite/hints.rs @@ -96,7 +96,7 @@ fn hint_unknown_type_warn() { [LOCKING] 1 package to latest compatible version [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) -[WARNING] ignoring unsupported value type (integer) 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) @@ -146,7 +146,7 @@ fn hints_mostly_unused_warn_without_gate() { [LOCKING] 1 package to latest compatible version [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) -[WARNING] 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) diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 3dd4dc522..61cc8d218 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -904,7 +904,7 @@ fn profile_hint_mostly_unused_warn_without_gate() { [LOCKING] 1 package to latest compatible version [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) -[WARNING] ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it +[WARNING] bar@1.0.0: ignoring 'hint-mostly-unused' profile option, 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)