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 4 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
22 changes: 21 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,26 @@ 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}\"`,\n\
\x20 but a virtual workspace defaults to `resolver = \"1\"`\n\
\x20 specify the desired resolver version explicitly in the workspace root's manifest\
epage marked this conversation as resolved.
Show resolved Hide resolved
",
))?;
}
}
}
}
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 a virtual workspace defaults to `resolver = \"1\"`
epage marked this conversation as resolved.
Show resolved Hide resolved
specify the desired resolver version explicitly in the workspace root's manifest
epage marked this conversation as resolved.
Show resolved Hide resolved
[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