Warn when an edition 2021 crate is in a virtual workspace with default resolver

Edition 2021 updates the default resolver to version "2", but developers
using virtual workspaces commonly don't get this update because the
virtual workspace defaults to version "1". Warn when this situation
occurs so those developers can explicitly configure their workspace and
will be more likely to know that they will need to update it in the
future.
This commit is contained in:
Wim Looman 2022-07-28 17:42:20 +02:00
parent 6d3a912ab8
commit 2e2b3c1f1e
No known key found for this signature in database
GPG Key ID: C6F5748C6DD1607B
2 changed files with 53 additions and 1 deletions

View File

@ -15,7 +15,7 @@ use crate::core::features::Features;
use crate::core::registry::PackageRegistry;
use crate::core::resolver::features::CliFeatures;
use crate::core::resolver::ResolveBehavior;
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec};
use crate::core::{Dependency, Edition, FeatureValue, PackageId, PackageIdSpec};
use crate::core::{EitherManifest, Package, SourceId, VirtualManifest};
use crate::ops;
use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
@ -993,6 +993,23 @@ impl<'cfg> Workspace<'cfg> {
}
}
}
if let MaybePackage::Virtual(vm) = self.root_maybe() {
if vm.resolve_behavior().is_none() {
if self
.members()
.filter(|p| p.manifest_path() != root_manifest)
.any(|p| p.manifest().edition() >= Edition::Edition2021)
{
self.config.shell().warn(
"\
some crates are on edition 2021 which defaults to `resolver = \"2\"`,\n\
\x20 but a virtual workspace defaults to `resolver = \"1\"`\n\
\x20 specify the desired resolver version explicitly at the workspace root\
",
)?;
}
}
}
}
Ok(())
}

View File

@ -1406,6 +1406,41 @@ workspace: [..]/foo/Cargo.toml
.run();
}
#[cargo_test]
fn edition_2021_workspace_member() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a"]
"#,
)
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2021"
"#,
)
.file("a/src/lib.rs", "")
.build();
p.cargo("check")
.with_stderr(
"\
warning: some crates are on edition 2021 which defaults to `resolver = \"2\"`,
but a virtual workspace defaults to `resolver = \"1\"`
specify the desired resolver version explicitly at the workspace root
[CHECKING] a v0.1.0 [..]
[FINISHED] [..]
",
)
.run();
}
#[cargo_test]
fn resolver_ws_root_and_member() {
// Check when specified in both ws root and member.