Include path to manifest in workspace warnings.

This commit is contained in:
Eric Huss 2018-11-07 10:43:19 -08:00
parent 237f86e267
commit 6ad7794027
3 changed files with 39 additions and 2 deletions

View File

@ -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)?
}
}
}

View File

@ -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 [..]
",

View File

@ -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();
}