Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resolver): Stabilize resolver v3 #14754

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@ fn normalize_toml(
warnings: &mut Vec<String>,
errors: &mut Vec<String>,
) -> CargoResult<manifest::TomlManifest> {
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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<Box<manifest::TomlPackage>> {
Expand Down Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/doc/src/reference/resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Comment on lines 507 to +510
Copy link
Contributor Author

@epage epage Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: When we stabilize 2024 edition, we'll need to update it to say that v3 is the default for it


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
Expand Down
28 changes: 2 additions & 26 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -631,8 +631,6 @@ fn resolve_v3() {
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]

[package]
name = "foo"
version = "0.0.1"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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")
Expand All @@ -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 ...
Expand Down