mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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.
This commit is contained in:
parent
6d3a912ab8
commit
2e2b3c1f1e
@ -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};
|
||||
@ -993,6 +993,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(())
|
||||
}
|
||||
|
@ -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\"`
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user