From 7b58bd51c34907221ea38abf40652bef61b4b1ba Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Oct 2024 09:50:01 -0500 Subject: [PATCH] feat(resolver): Stabilize v3 resolver --- src/cargo/util/toml/mod.rs | 14 +------------- src/doc/src/reference/config.md | 2 +- src/doc/src/reference/resolver.md | 1 + tests/testsuite/rust_version.rs | 28 ++-------------------------- 4 files changed, 5 insertions(+), 40 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index be8e7512776..c0f6df61d90 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -273,12 +273,6 @@ fn normalize_toml( warnings: &mut Vec, errors: &mut Vec, ) -> CargoResult { - if let Some(workspace) = &original_toml.workspace { - if workspace.resolver.as_deref() == Some("3") { - features.require(Feature::edition2024())?; - } - } - let mut normalized_toml = manifest::TomlManifest { cargo_features: original_toml.cargo_features.clone(), package: None, @@ -316,8 +310,7 @@ fn normalize_toml( if let Some(original_package) = original_toml.package() { let package_name = &original_package.name; - let normalized_package = - normalize_package_toml(original_package, features, package_root, &inherit)?; + let normalized_package = normalize_package_toml(original_package, package_root, &inherit)?; let edition = normalized_package .normalized_edition() .expect("previously normalized") @@ -549,7 +542,6 @@ fn normalize_patch<'a>( #[tracing::instrument(skip_all)] fn normalize_package_toml<'a>( original_package: &manifest::TomlPackage, - features: &Features, package_root: &Path, inherit: &dyn Fn() -> CargoResult<&'a InheritableFields>, ) -> CargoResult> { @@ -682,10 +674,6 @@ fn normalize_package_toml<'a>( _invalid_cargo_features: Default::default(), }; - if normalized_package.resolver.as_deref() == Some("3") { - features.require(Feature::edition2024())?; - } - Ok(Box::new(normalized_package)) } diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index fe3941a7503..11ac2f9a5dc 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -981,7 +981,7 @@ The `[resolver]` table overrides [dependency resolution behavior](resolver.md) f #### `resolver.incompatible-rust-versions` * Type: string -* Default: `"allow"` +* Default: See [`resolver`](resolver.md#resolver-versions) docs * Environment: `CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS` When resolving which version of a dependency to use, select how versions with incompatible `package.rust-version`s are treated. diff --git a/src/doc/src/reference/resolver.md b/src/doc/src/reference/resolver.md index 1ca87b15c05..bc41517b21f 100644 --- a/src/doc/src/reference/resolver.md +++ b/src/doc/src/reference/resolver.md @@ -507,6 +507,7 @@ resolver = "2" - `"2"` ([`edition = "2021"`](manifest.md#the-edition-field) default): Introduces changes in [feature unification](#features). See the [features chapter][features-2] for more details. +- `"3"` (requires Rust 1.84+): Change the default for [`resolver.incompatible-rust-versions`] from `allow` to `fallback` The resolver is a global option that affects the entire workspace. The `resolver` version in dependencies is ignored, only the value in the top-level diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 463e599e5ba..a1af79b6b60 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -612,7 +612,7 @@ foo v0.0.1 ([ROOT]/foo) .run(); } -#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")] +#[cargo_test] fn resolve_v3() { Package::new("only-newer", "1.6.0") .rust_version("1.65.0") @@ -631,8 +631,6 @@ fn resolve_v3() { .file( "Cargo.toml", r#" - cargo-features = ["edition2024"] - [package] name = "foo" version = "0.0.1" @@ -651,7 +649,6 @@ fn resolve_v3() { // v3 should resolve for MSRV p.cargo("generate-lockfile") - .masquerade_as_nightly_cargo(&["edition2024"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest Rust 1.60.0 compatible versions @@ -661,7 +658,6 @@ fn resolve_v3() { "#]]) .run(); p.cargo("tree") - .masquerade_as_nightly_cargo(&["edition2024"]) .with_stdout_data(str![[r#" foo v0.0.1 ([ROOT]/foo) ├── newer-and-older v1.5.0 @@ -677,10 +673,8 @@ foo v0.0.1 ([ROOT]/foo) [LOCKING] 2 packages to latest compatible versions "#]]) - .masquerade_as_nightly_cargo(&["edition2024"]) .run(); p.cargo("tree") - .masquerade_as_nightly_cargo(&["edition2024"]) .with_stdout_data(str![[r#" foo v0.0.1 ([ROOT]/foo) ├── newer-and-older v1.6.0 @@ -697,29 +691,13 @@ foo v0.0.1 ([ROOT]/foo) [LOCKING] 2 packages to latest compatible versions "#]]) - .masquerade_as_nightly_cargo(&["edition2024"]) .run(); p.cargo("tree") - .masquerade_as_nightly_cargo(&["edition2024"]) .with_stdout_data(str![[r#" foo v0.0.1 ([ROOT]/foo) ├── newer-and-older v1.6.0 └── only-newer v1.6.0 -"#]]) - .run(); - - // unstable - p.cargo("generate-lockfile") - .with_status(101) - .with_stderr_data(str![[r#" -[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` - -Caused by: - the cargo feature `edition2024` requires a nightly version of Cargo, but this is the `stable` channel - See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. - See https://doc.rust-lang.org/cargo/reference/unstable.html#edition-2024 for more information about using this feature. - "#]]) .run(); } @@ -946,7 +924,7 @@ fn cargo_install_ignores_msrv_config() { .run(); } -#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")] +#[cargo_test] fn cargo_install_ignores_resolver_v3_msrv_change() { Package::new("dep", "1.0.0") .rust_version("1.50") @@ -958,14 +936,12 @@ fn cargo_install_ignores_resolver_v3_msrv_change() { .publish(); Package::new("foo", "0.0.1") .rust_version("1.60") - .cargo_feature("edition2024") .resolver("3") .file("src/main.rs", "fn main() {}") .dep("dep", "1") .publish(); cargo_process("install foo") - .masquerade_as_nightly_cargo(&["edition2024"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [DOWNLOADING] crates ...