Skip to content

Commit d08c587

Browse files
committed
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
2 parents b9b5a45 + 3dec6f2 commit d08c587

File tree

8 files changed

+60
-1
lines changed

8 files changed

+60
-1
lines changed

src/cargo/core/workspace.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::core::features::Features;
1515
use crate::core::registry::PackageRegistry;
1616
use crate::core::resolver::features::CliFeatures;
1717
use crate::core::resolver::ResolveBehavior;
18-
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec};
18+
use crate::core::{Dependency, Edition, FeatureValue, PackageId, PackageIdSpec};
1919
use crate::core::{EitherManifest, Package, SourceId, VirtualManifest};
2020
use crate::ops;
2121
use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
@@ -993,6 +993,24 @@ impl<'cfg> Workspace<'cfg> {
993993
}
994994
}
995995
}
996+
if let MaybePackage::Virtual(vm) = self.root_maybe() {
997+
if vm.resolve_behavior().is_none() {
998+
if let Some(edition) = self
999+
.members()
1000+
.filter(|p| p.manifest_path() != root_manifest)
1001+
.map(|p| p.manifest().edition())
1002+
.filter(|&e| e >= Edition::Edition2021)
1003+
.max()
1004+
{
1005+
let resolver = edition.default_resolve_behavior().to_manifest();
1006+
self.config.shell().warn(format_args!("some crates are on edition {edition} which defaults to `resolver = \"{resolver}\"`, but virtual workspaces default to `resolver = \"1\"`"))?;
1007+
self.config.shell().note(
1008+
"to keep the current resolver, specify `workspace.resolver = \"1\"` in the workspace root's manifest",
1009+
)?;
1010+
self.config.shell().note(format_args!("to use the edition {edition} resolver, specify `workspace.resolver = \"{resolver}\"` in the workspace root's manifest"))?;
1011+
}
1012+
}
1013+
}
9961014
}
9971015
Ok(())
9981016
}

tests/testsuite/cargo_new/inherit_workspace_lints/in/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = ["crates/*"]
34

45
[workspace.lints.rust]

tests/testsuite/cargo_new/inherit_workspace_lints/out/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = ["crates/*"]
34

45
[workspace.lints.rust]

tests/testsuite/cargo_new/inherit_workspace_package_table.in/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"crates/*",
45
]

tests/testsuite/cargo_new/inherit_workspace_package_table/out/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"crates/*",
45
]

tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"crates/*",
45
]

tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"crates/*",
45
]

tests/testsuite/features2.rs

+35
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,41 @@ workspace: [..]/foo/Cargo.toml
14061406
.run();
14071407
}
14081408

1409+
#[cargo_test]
1410+
fn edition_2021_workspace_member() {
1411+
let p = project()
1412+
.file(
1413+
"Cargo.toml",
1414+
r#"
1415+
[workspace]
1416+
members = ["a"]
1417+
"#,
1418+
)
1419+
.file(
1420+
"a/Cargo.toml",
1421+
r#"
1422+
[package]
1423+
name = "a"
1424+
version = "0.1.0"
1425+
edition = "2021"
1426+
"#,
1427+
)
1428+
.file("a/src/lib.rs", "")
1429+
.build();
1430+
1431+
p.cargo("check")
1432+
.with_stderr(
1433+
"\
1434+
warning: some crates are on edition 2021 which defaults to `resolver = \"2\"`, but virtual workspaces default to `resolver = \"1\"`
1435+
note: to keep the current resolver, specify `workspace.resolver = \"1\"` in the workspace root's manifest
1436+
note: to use the edition 2021 resolver, specify `workspace.resolver = \"2\"` in the workspace root's manifest
1437+
[CHECKING] a v0.1.0 [..]
1438+
[FINISHED] [..]
1439+
",
1440+
)
1441+
.run();
1442+
}
1443+
14091444
#[cargo_test]
14101445
fn resolver_ws_root_and_member() {
14111446
// Check when specified in both ws root and member.

0 commit comments

Comments
 (0)