Skip to content

Commit 0d8cab4

Browse files
committed
Auto merge of #8857 - ehuss:resolver-1, r=alexcrichton
Allow resolver="1" to explicitly use the old resolver behavior. A couple people expressed that it was surprising that it was not possible to explicitly specify the old behavior, so this PR adds the ability to specify `resolver = "1"` to explicitly specify the old feature unification behavior. This is a little more consistent with other options like `edition` which allows an explicit "2015" even though that is the default.
2 parents 2af662e + b1029b7 commit 0d8cab4

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

src/cargo/core/resolver/types.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ pub enum ResolveBehavior {
110110
impl ResolveBehavior {
111111
pub fn from_manifest(resolver: &str) -> CargoResult<ResolveBehavior> {
112112
match resolver {
113+
"1" => Ok(ResolveBehavior::V1),
113114
"2" => Ok(ResolveBehavior::V2),
114115
s => anyhow::bail!(
115-
"`resolver` setting `{}` is not valid, only valid option is \"2\"",
116+
"`resolver` setting `{}` is not valid, valid options are \"1\" or \"2\"",
116117
s
117118
),
118119
}

src/doc/src/reference/unstable.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,9 @@ version = "1.0.0"
661661
resolver = "2"
662662
```
663663

664-
Currently the only allowed value is `"2"`. This declaration enables all of the
665-
new feature behavior of [`-Zfeatures=all`](#features) and
666-
[`-Zpackage-features`](#package-features).
664+
The value `"1"` is the current resolver behavior on the stable channel. A
665+
value of `"2"` enables all of the new feature behavior of
666+
[`-Zfeatures=all`](#features) and [`-Zpackage-features`](#package-features).
667667

668668
This flag is global for a workspace. If using a virtual workspace, the root
669669
definition should be in the `[workspace]` table like this:

tests/testsuite/features2.rs

+57-2
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ fn resolver_bad_setting() {
13671367
[package]
13681368
name = "foo"
13691369
version = "0.1.0"
1370-
resolver = "1"
1370+
resolver = "foo"
13711371
"#,
13721372
)
13731373
.file("src/lib.rs", "")
@@ -1381,12 +1381,67 @@ fn resolver_bad_setting() {
13811381
error: failed to parse manifest at `[..]/foo/Cargo.toml`
13821382
13831383
Caused by:
1384-
`resolver` setting `1` is not valid, only valid option is \"2\"
1384+
`resolver` setting `foo` is not valid, valid options are \"1\" or \"2\"
13851385
",
13861386
)
13871387
.run();
13881388
}
13891389

1390+
#[cargo_test]
1391+
fn resolver_original() {
1392+
// resolver="1" uses old unification behavior.
1393+
Package::new("common", "1.0.0")
1394+
.feature("f1", &[])
1395+
.file(
1396+
"src/lib.rs",
1397+
r#"
1398+
#[cfg(feature = "f1")]
1399+
compile_error!("f1 should not activate");
1400+
"#,
1401+
)
1402+
.publish();
1403+
1404+
Package::new("bar", "1.0.0")
1405+
.add_dep(
1406+
Dependency::new("common", "1.0")
1407+
.target("cfg(whatever)")
1408+
.enable_features(&["f1"]),
1409+
)
1410+
.publish();
1411+
1412+
let manifest = |resolver| {
1413+
format!(
1414+
r#"
1415+
cargo-features = ["resolver"]
1416+
[package]
1417+
name = "foo"
1418+
version = "0.1.0"
1419+
resolver = "{}"
1420+
1421+
[dependencies]
1422+
common = "1.0"
1423+
bar = "1.0"
1424+
"#,
1425+
resolver
1426+
)
1427+
};
1428+
1429+
let p = project()
1430+
.file("Cargo.toml", &manifest("1"))
1431+
.file("src/lib.rs", "")
1432+
.build();
1433+
1434+
p.cargo("check")
1435+
.masquerade_as_nightly_cargo()
1436+
.with_status(101)
1437+
.with_stderr_contains("[..]f1 should not activate[..]")
1438+
.run();
1439+
1440+
p.change_file("Cargo.toml", &manifest("2"));
1441+
1442+
p.cargo("check").masquerade_as_nightly_cargo().run();
1443+
}
1444+
13901445
#[cargo_test]
13911446
fn resolver_not_both() {
13921447
// Can't specify resolver in both workspace and package.

0 commit comments

Comments
 (0)