Skip to content

Commit

Permalink
Emit a single warning detailing all inconsistent resolvers in the wor…
Browse files Browse the repository at this point in the history
…kspace
  • Loading branch information
Nemo157 committed Jul 28, 2022
1 parent 0026431 commit 79f3229
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
67 changes: 42 additions & 25 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,39 +980,56 @@ impl<'cfg> Workspace<'cfg> {
if !manifest.patch().is_empty() {
emit_warning("patch")?;
}
if manifest.defaulted_resolve_behavior() != self.resolve_behavior {
let package_reason = manifest
.resolve_behavior()
.is_none()
.then(|| format!(r#" implied by edition = "{}""#, manifest.edition()))
.unwrap_or_default();
let workspace_reason = match self.root_maybe() {
}
let mut inconsistent_resolvers: Vec<_> = self
.members()
.filter(|p| p.manifest_path() != root_manifest)
.filter(|p| p.manifest().defaulted_resolve_behavior() != self.resolve_behavior)
.map(|pkg| {
format!(
r#"package: {} expects resolver = "{}"{}"#,
pkg.manifest_path().display(),
pkg.manifest()
.defaulted_resolve_behavior()
.to_manifest()
.unwrap_or_else(|| "1".into()),
pkg.manifest()
.resolve_behavior()
.is_none()
.then(|| format!(
r#" implied by edition = "{}""#,
pkg.manifest().edition()
))
.unwrap_or_default()
)
})
.collect();
if !inconsistent_resolvers.is_empty() {
inconsistent_resolvers.insert(
0,
"expected resolver for package(s) are overridden by the workspace root:".into(),
);
inconsistent_resolvers.push(format!(
r#"workspace: {} sets resolver = "{}"{}"#,
root_manifest.display(),
self.resolve_behavior
.to_manifest()
.unwrap_or_else(|| "1".into()),
match self.root_maybe() {
MaybePackage::Package(p) => {
p.manifest().resolve_behavior().is_none().then(|| {
format!(r#" implied by edition = "{}""#, manifest.edition())
format!(r#" implied by edition = "{}""#, p.manifest().edition())
})
}
MaybePackage::Virtual(vm) => {
vm.resolve_behavior().is_none().then(|| " (default)".into())
}
}
.unwrap_or_default();
let msg = format!(
"expected resolver for package is overridden by the workspace root:\n\
package: {} expects resolver = \"{}\"{package_reason}\n\
workspace: {} sets resolver = \"{}\"{workspace_reason}",
pkg.manifest_path().display(),
manifest
.defaulted_resolve_behavior()
.to_manifest()
.unwrap_or_else(|| "1".into()),
root_manifest.display(),
self.resolve_behavior
.to_manifest()
.unwrap_or_else(|| "1".into()),
);
self.config.shell().warn(&msg)?;
}
.unwrap_or_default(),
));
self.config
.shell()
.warn(inconsistent_resolvers.join("\n"))?;
}
}
Ok(())
Expand Down
20 changes: 17 additions & 3 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ fn resolver_ws_member() {
p.cargo("check")
.with_stderr(
"\
warning: expected resolver for package is overridden by the workspace root:
warning: expected resolver for package(s) are overridden by the workspace root:
package: [..]/foo/a/Cargo.toml expects resolver = \"2\"
workspace: [..]/foo/Cargo.toml sets resolver = \"1\" (default)
[CHECKING] a v0.1.0 [..]
Expand Down Expand Up @@ -1442,7 +1442,7 @@ fn implicit_resolver_ws_member() {
"Cargo.toml",
r#"
[workspace]
members = ["a"]
members = ["a", "b"]
"#,
)
.file(
Expand All @@ -1455,15 +1455,29 @@ fn implicit_resolver_ws_member() {
"#,
)
.file("a/src/lib.rs", "")
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.1.0"
resolver = "2"
[dependencies]
a = { path = "../a" } # to force build message order
"#,
)
.file("b/src/lib.rs", "")
.build();

p.cargo("check")
.with_stderr(
"\
warning: expected resolver for package is overridden by the workspace root:
warning: expected resolver for package(s) are overridden by the workspace root:
package: [..]/foo/a/Cargo.toml expects resolver = \"2\" implied by edition = \"2021\"
package: [..]/foo/b/Cargo.toml expects resolver = \"2\"
workspace: [..]/foo/Cargo.toml sets resolver = \"1\" (default)
[CHECKING] a v0.1.0 [..]
[CHECKING] b v0.1.0 [..]
[FINISHED] [..]
",
)
Expand Down

0 comments on commit 79f3229

Please sign in to comment.