Skip to content

Commit 7b09375

Browse files
committed
Auto merge of #13738 - epage:msrv, r=Muscraft
feat(reslve): Respect '--ignore-rust-version' ### What does this PR try to resolve? This is a part of #9930. ### How should we test and review this PR? I had considered several ways of implementing this. I first looked at passing this into `ops::resolve*`. .This would get a bit annoying with the function signature, so I considered moving it to a builder.. Each of the entry points is slightly different with different ownership needs, making it hard to have a common abstraction. In doing this, I noticed we currently pass some state around to the resolver via `Workspace`, so I mirrored that. The nice thing about this location is it provides a good place to hook in config and `package.resolve` so they affect this. ### Additional information
2 parents d467208 + cd3d31b commit 7b09375

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

Diff for: src/cargo/core/workspace.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub struct Workspace<'gctx> {
100100

101101
/// The resolver behavior specified with the `resolver` field.
102102
resolve_behavior: ResolveBehavior,
103+
honor_rust_version: Option<bool>,
103104

104105
/// Workspace-level custom metadata
105106
custom_metadata: Option<toml::Value>,
@@ -229,6 +230,7 @@ impl<'gctx> Workspace<'gctx> {
229230
loaded_packages: RefCell::new(HashMap::new()),
230231
ignore_lock: false,
231232
resolve_behavior: ResolveBehavior::V1,
233+
honor_rust_version: None,
232234
custom_metadata: None,
233235
}
234236
}
@@ -605,6 +607,14 @@ impl<'gctx> Workspace<'gctx> {
605607
self.members().filter_map(|pkg| pkg.rust_version()).min()
606608
}
607609

610+
pub fn set_honor_rust_version(&mut self, honor_rust_version: Option<bool>) {
611+
self.honor_rust_version = honor_rust_version;
612+
}
613+
614+
pub fn resolve_honors_rust_version(&self) -> bool {
615+
self.gctx().cli_unstable().msrv_policy && self.honor_rust_version.unwrap_or(true)
616+
}
617+
608618
pub fn custom_metadata(&self) -> Option<&toml::Value> {
609619
self.custom_metadata.as_ref()
610620
}
@@ -771,7 +781,7 @@ impl<'gctx> Workspace<'gctx> {
771781
}
772782
}
773783

774-
debug!("find_members - {}", manifest_path.display());
784+
debug!("find_path_deps - {}", manifest_path.display());
775785
self.members.push(manifest_path.clone());
776786

777787
let candidates = {

Diff for: src/cargo/ops/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn resolve_with_previous<'gctx>(
303303
if ws.gctx().cli_unstable().minimal_versions {
304304
version_prefs.version_ordering(VersionOrdering::MinimumVersionsFirst)
305305
}
306-
if ws.gctx().cli_unstable().msrv_policy {
306+
if ws.resolve_honors_rust_version() {
307307
version_prefs.max_rust_version(ws.rust_version().cloned().map(RustVersion::into_partial));
308308
}
309309

Diff for: src/cargo/util/command_prelude.rs

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ pub trait ArgMatchesExt {
504504
fn workspace<'a>(&self, gctx: &'a GlobalContext) -> CargoResult<Workspace<'a>> {
505505
let root = self.root_manifest(gctx)?;
506506
let mut ws = Workspace::new(&root, gctx)?;
507+
ws.set_honor_rust_version(self.honor_rust_version());
507508
if gctx.cli_unstable().avoid_dev_deps {
508509
ws.set_require_optional_deps(false);
509510
}

Diff for: tests/testsuite/rust_version.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,13 @@ fn dependency_rust_version_older_and_newer_than_package() {
347347
p.cargo("check --ignore-rust-version")
348348
.arg("-Zmsrv-policy")
349349
.masquerade_as_nightly_cargo(&["msrv-policy"])
350-
// This should pick 1.6.0
351350
.with_stderr(
352351
"\
353352
[UPDATING] `dummy-registry` index
354353
[LOCKING] 2 packages
355-
[ADDING] bar v1.5.0 (latest: v1.6.0)
356354
[DOWNLOADING] crates ...
357-
[DOWNLOADED] bar v1.5.0 (registry `dummy-registry`)
358-
[CHECKING] bar v1.5.0
355+
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
356+
[CHECKING] bar v1.6.0
359357
[CHECKING] [..]
360358
[FINISHED] [..]
361359
",
@@ -483,15 +481,13 @@ fn workspace_with_mixed_rust_version() {
483481
p.cargo("check --ignore-rust-version")
484482
.arg("-Zmsrv-policy")
485483
.masquerade_as_nightly_cargo(&["msrv-policy"])
486-
// This should pick 1.6.0
487484
.with_stderr(
488485
"\
489486
[UPDATING] `dummy-registry` index
490487
[LOCKING] 3 packages
491-
[ADDING] bar v1.4.0 (latest: v1.6.0)
492488
[DOWNLOADING] crates ...
493-
[DOWNLOADED] bar v1.4.0 (registry `dummy-registry`)
494-
[CHECKING] bar v1.4.0
489+
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
490+
[CHECKING] bar v1.6.0
495491
[CHECKING] [..]
496492
[FINISHED] [..]
497493
",

0 commit comments

Comments
 (0)