Skip to content

Commit 1f730be

Browse files
committed
Auto merge of #6277 - ehuss:ws-warn-path, r=alexcrichton
Include path to manifest in workspace warnings. It can be confusing because almost all of the warnings give no indication which package issued the warning. Closes #6168
2 parents 237f86e + 6ad7794 commit 1f730be

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/cargo/core/workspace.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ impl<'cfg> Workspace<'cfg> {
741741
MaybePackage::Package(pkg) => pkg.manifest().warnings().warnings(),
742742
MaybePackage::Virtual(vm) => vm.warnings().warnings(),
743743
};
744+
let path = path.join("Cargo.toml");
744745
for warning in warnings {
745746
if warning.is_critical {
746747
let err = format_err!("{}", warning.message);
@@ -750,7 +751,14 @@ impl<'cfg> Workspace<'cfg> {
750751
);
751752
return Err(err.context(cx).into());
752753
} else {
753-
self.config.shell().warn(&warning.message)?
754+
let msg = if self.root_manifest.is_none() {
755+
warning.message.to_string()
756+
} else {
757+
// In a workspace, it can be confusing where a warning
758+
// originated, so include the path.
759+
format!("{}: {}", path.display(), warning.message)
760+
};
761+
self.config.shell().warn(msg)?
754762
}
755763
}
756764
}

tests/testsuite/bad_config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn unused_keys_in_virtual_manifest() {
734734
p.cargo("build --all")
735735
.with_stderr(
736736
"\
737-
warning: unused manifest key: workspace.bulid
737+
[WARNING] [..]/foo/Cargo.toml: unused manifest key: workspace.bulid
738738
[COMPILING] bar [..]
739739
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
740740
",

tests/testsuite/workspaces.rs

+29
Original file line numberDiff line numberDiff line change
@@ -1969,3 +1969,32 @@ workspace: [..]/foo/Cargo.toml
19691969
.run();
19701970
}
19711971
}
1972+
1973+
#[test]
1974+
fn ws_warn_path() {
1975+
// Warnings include path to manifest.
1976+
let p = project()
1977+
.file(
1978+
"Cargo.toml",
1979+
r#"
1980+
[workspace]
1981+
members = ["a"]
1982+
"#,
1983+
)
1984+
.file(
1985+
"a/Cargo.toml",
1986+
r#"
1987+
cargo-features = ["edition"]
1988+
[package]
1989+
name = "foo"
1990+
version = "0.1.0"
1991+
"#,
1992+
)
1993+
.file("a/src/lib.rs", "")
1994+
.build();
1995+
1996+
p.cargo("check")
1997+
.with_status(0)
1998+
.with_stderr_contains("[WARNING] [..]/foo/a/Cargo.toml: the cargo feature `edition`[..]")
1999+
.run();
2000+
}

0 commit comments

Comments
 (0)