Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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