From 6ad77940272bfd34074411f064a8aab0ff94e300 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 7 Nov 2018 10:43:19 -0800 Subject: [PATCH] Include path to manifest in workspace warnings. --- src/cargo/core/workspace.rs | 10 +++++++++- tests/testsuite/bad_config.rs | 2 +- tests/testsuite/workspaces.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 3fccc4ee0..e09bdf112 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -741,6 +741,7 @@ impl<'cfg> Workspace<'cfg> { MaybePackage::Package(pkg) => pkg.manifest().warnings().warnings(), MaybePackage::Virtual(vm) => vm.warnings().warnings(), }; + let path = path.join("Cargo.toml"); for warning in warnings { if warning.is_critical { let err = format_err!("{}", warning.message); @@ -750,7 +751,14 @@ impl<'cfg> Workspace<'cfg> { ); return Err(err.context(cx).into()); } else { - self.config.shell().warn(&warning.message)? + let msg = if self.root_manifest.is_none() { + warning.message.to_string() + } else { + // In a workspace, it can be confusing where a warning + // originated, so include the path. + format!("{}: {}", path.display(), warning.message) + }; + self.config.shell().warn(msg)? } } } diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index bcef70300..8036d32d7 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -734,7 +734,7 @@ fn unused_keys_in_virtual_manifest() { p.cargo("build --all") .with_stderr( "\ -warning: unused manifest key: workspace.bulid +[WARNING] [..]/foo/Cargo.toml: unused manifest key: workspace.bulid [COMPILING] bar [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 88398174d..fb3d64ac5 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -1969,3 +1969,32 @@ workspace: [..]/foo/Cargo.toml .run(); } } + +#[test] +fn ws_warn_path() { + // Warnings include path to manifest. + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["a"] + "#, + ) + .file( + "a/Cargo.toml", + r#" + cargo-features = ["edition"] + [package] + name = "foo" + version = "0.1.0" + "#, + ) + .file("a/src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(0) + .with_stderr_contains("[WARNING] [..]/foo/a/Cargo.toml: the cargo feature `edition`[..]") + .run(); +}