Auto merge of #10910 - Nemo157:lint-different-resolver-10112, r=epage

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.

Fixes #10112
This commit is contained in:
bors 2023-05-26 19:57:28 +00:00
commit d08c587469
8 changed files with 60 additions and 1 deletions

View File

@ -15,7 +15,7 @@ use crate::core::features::Features;
use crate::core::registry::PackageRegistry; use crate::core::registry::PackageRegistry;
use crate::core::resolver::features::CliFeatures; use crate::core::resolver::features::CliFeatures;
use crate::core::resolver::ResolveBehavior; 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::core::{EitherManifest, Package, SourceId, VirtualManifest};
use crate::ops; use crate::ops;
use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY}; use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
@ -993,6 +993,24 @@ impl<'cfg> Workspace<'cfg> {
} }
} }
} }
if let MaybePackage::Virtual(vm) = self.root_maybe() {
if vm.resolve_behavior().is_none() {
if let Some(edition) = self
.members()
.filter(|p| p.manifest_path() != root_manifest)
.map(|p| p.manifest().edition())
.filter(|&e| e >= Edition::Edition2021)
.max()
{
let resolver = edition.default_resolve_behavior().to_manifest();
self.config.shell().warn(format_args!("some crates are on edition {edition} which defaults to `resolver = \"{resolver}\"`, but virtual workspaces default to `resolver = \"1\"`"))?;
self.config.shell().note(
"to keep the current resolver, specify `workspace.resolver = \"1\"` in the workspace root's manifest",
)?;
self.config.shell().note(format_args!("to use the edition {edition} resolver, specify `workspace.resolver = \"{resolver}\"` in the workspace root's manifest"))?;
}
}
}
} }
Ok(()) Ok(())
} }

View File

@ -1,4 +1,5 @@
[workspace] [workspace]
resolver = "2"
members = ["crates/*"] members = ["crates/*"]
[workspace.lints.rust] [workspace.lints.rust]

View File

@ -1,4 +1,5 @@
[workspace] [workspace]
resolver = "2"
members = ["crates/*"] members = ["crates/*"]
[workspace.lints.rust] [workspace.lints.rust]

View File

@ -1,4 +1,5 @@
[workspace] [workspace]
resolver = "2"
members = [ members = [
"crates/*", "crates/*",
] ]

View File

@ -1,4 +1,5 @@
[workspace] [workspace]
resolver = "2"
members = [ members = [
"crates/*", "crates/*",
] ]

View File

@ -1,4 +1,5 @@
[workspace] [workspace]
resolver = "2"
members = [ members = [
"crates/*", "crates/*",
] ]

View File

@ -1,4 +1,5 @@
[workspace] [workspace]
resolver = "2"
members = [ members = [
"crates/*", "crates/*",
] ]

View File

@ -1406,6 +1406,41 @@ workspace: [..]/foo/Cargo.toml
.run(); .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 virtual workspaces default to `resolver = \"1\"`
note: to keep the current resolver, specify `workspace.resolver = \"1\"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = \"2\"` in the workspace root's manifest
[CHECKING] a v0.1.0 [..]
[FINISHED] [..]
",
)
.run();
}
#[cargo_test] #[cargo_test]
fn resolver_ws_root_and_member() { fn resolver_ws_root_and_member() {
// Check when specified in both ws root and member. // Check when specified in both ws root and member.