Skip to content

Commit

Permalink
Warn when an edition 2021 crate is in a virtual workspace with defaul…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
Nemo157 committed Aug 10, 2022
1 parent 1fcbca8 commit 1ed5869
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -994,6 +994,23 @@ impl<'cfg> Workspace<'cfg> {
}
}
}
if let MaybePackage::Virtual(vm) = self.root_maybe() {
if vm.resolve_behavior().is_none() {
if self
.members()
.filter(|p| p.manifest_path() != root_manifest)
.any(|p| p.manifest().edition() >= Edition::Edition2021)
{
self.config.shell().warn(
"\
some crates are on edition 2021 which defaults to `resolver = \"2\"`,\n\
\x20 but a virtual workspace defaults to `resolver = \"1\"`\n\
\x20 specify the desired resolver version explicitly at the workspace root\
",
)?;
}
}
}
}
Ok(())
}
Expand Down
35 changes: 35 additions & 0 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,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\"`
specify the desired resolver version explicitly at the workspace root
[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 1ed5869

Please sign in to comment.