Make "2" the default resolver in the 2021 edition.

This commit is contained in:
Eric Huss 2021-02-17 22:06:58 -08:00
parent 2ae72ff747
commit 37f4ff9a9a
3 changed files with 84 additions and 1 deletions

View file

@ -1132,7 +1132,13 @@ impl TomlManifest {
project.resolver.as_ref(),
me.workspace.as_ref().and_then(|ws| ws.resolver.as_ref()),
) {
(None, None) => None,
(None, None) => {
if edition == Edition::Edition2021 {
Some(ResolveBehavior::V2)
} else {
None
}
}
(Some(s), None) | (None, Some(s)) => Some(ResolveBehavior::from_manifest(s)?),
(Some(_), Some(_)) => {
bail!("cannot specify `resolver` field in both `[workspace]` and `[package]`")

View file

@ -1082,7 +1082,10 @@ This feature is very unstable, and is only intended for early testing and
experimentation. Future nightly releases may introduce changes for the 2021
edition that may break your build.
The 2021 edition will set the default [resolver version] to "2".
[edition]: ../../edition-guide/index.html
[resolver version]: resolver.md#resolver-versions
<script>
(function() {

View file

@ -2324,3 +2324,77 @@ fn doc_proc_macro() {
// so rustdoc can load it).
p.cargo("doc").run();
}
#[cargo_test]
fn edition_2021_default_2() {
// edition = 2021 defaults to v2 resolver.
Package::new("common", "1.0.0")
.feature("f1", &[])
.file("src/lib.rs", "")
.publish();
Package::new("bar", "1.0.0")
.add_dep(
Dependency::new("common", "1.0")
.target("cfg(whatever)")
.enable_features(&["f1"]),
)
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
common = "1.0"
bar = "1.0"
"#,
)
.file("src/lib.rs", "")
.build();
// First without edition.
p.cargo("tree -f")
.arg("{p} feats:{f}")
.with_stdout(
"\
foo v0.1.0 [..]
bar v1.0.0 feats:
common v1.0.0 feats:f1
",
)
.run();
p.change_file(
"Cargo.toml",
r#"
cargo-features = ["edition2021"]
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
common = "1.0"
bar = "1.0"
"#,
);
// Importantly, this does not include `f1` on `common`.
p.cargo("tree -f")
.arg("{p} feats:{f}")
.masquerade_as_nightly_cargo()
.with_stdout(
"\
foo v0.1.0 [..]
bar v1.0.0 feats:
common v1.0.0 feats:
",
)
.run();
}