Skip to content

Commit

Permalink
Auto merge of #10910 - Nemo157:lint-different-resolver-10112, r=epage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 26, 2023
2 parents b9b5a45 + 3dec6f2 commit d08c587
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = ["crates/*"]

[workspace.lints.rust]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = ["crates/*"]

[workspace.lints.rust]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"crates/*",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"crates/*",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"crates/*",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"crates/*",
]
Expand Down
35 changes: 35 additions & 0 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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]
fn resolver_ws_root_and_member() {
// Check when specified in both ws root and member.
Expand Down

0 comments on commit d08c587

Please sign in to comment.