Skip to content

Commit cd8d5f7

Browse files
committed
refactor(msrv): Simplify tracking of use of MSRV-aware resolver
The design for this stems from - It being unclear what the initialization order would be - Prematurely writing this for `Cargo.lock` version to leverage it and maybe to switch other MSRV-aware logic to
1 parent b89b81a commit cd8d5f7

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

src/bin/cargo/commands/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
7272
// code as we can.
7373
let root_manifest = args.root_manifest(gctx)?;
7474
let mut ws = Workspace::new(&root_manifest, gctx)?;
75-
ws.set_honor_rust_version(args.honor_rust_version());
75+
ws.set_resolve_honors_rust_version(args.honor_rust_version());
7676
let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;
7777

7878
if !opts.filter.is_specific() {

src/cargo/core/workspace.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ pub struct Workspace<'gctx> {
104104
/// The resolver behavior specified with the `resolver` field.
105105
resolve_behavior: ResolveBehavior,
106106
resolve_honors_rust_version: bool,
107-
honor_rust_version: Option<bool>,
108107

109108
/// Workspace-level custom metadata
110109
custom_metadata: Option<toml::Value>,
@@ -235,7 +234,6 @@ impl<'gctx> Workspace<'gctx> {
235234
ignore_lock: false,
236235
resolve_behavior: ResolveBehavior::V1,
237236
resolve_honors_rust_version: false,
238-
honor_rust_version: None,
239237
custom_metadata: None,
240238
}
241239
}
@@ -649,18 +647,14 @@ impl<'gctx> Workspace<'gctx> {
649647
self.members().filter_map(|pkg| pkg.rust_version()).min()
650648
}
651649

652-
pub fn set_honor_rust_version(&mut self, honor_rust_version: Option<bool>) {
653-
self.honor_rust_version = honor_rust_version;
654-
}
655-
656-
pub fn honor_rust_version(&self) -> Option<bool> {
657-
self.honor_rust_version
650+
pub fn set_resolve_honors_rust_version(&mut self, honor_rust_version: Option<bool>) {
651+
if let Some(honor_rust_version) = honor_rust_version {
652+
self.resolve_honors_rust_version = honor_rust_version;
653+
}
658654
}
659655

660656
pub fn resolve_honors_rust_version(&self) -> bool {
661-
// Give CLI precedence
662-
self.honor_rust_version
663-
.unwrap_or(self.resolve_honors_rust_version)
657+
self.resolve_honors_rust_version
664658
}
665659

666660
pub fn custom_metadata(&self) -> Option<&toml::Value> {

src/cargo/ops/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn fix(
108108
check_resolver_change(&original_ws, opts)?;
109109
}
110110
let mut ws = Workspace::new(&root_manifest, gctx)?;
111-
ws.set_honor_rust_version(original_ws.honor_rust_version());
111+
ws.set_resolve_honors_rust_version(Some(original_ws.resolve_honors_rust_version()));
112112

113113
// Spin up our lock server, which our subprocesses will use to synchronize fixes.
114114
let lock_server = LockServer::new()?;

src/cargo/util/command_prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub trait ArgMatchesExt {
505505
fn workspace<'a>(&self, gctx: &'a GlobalContext) -> CargoResult<Workspace<'a>> {
506506
let root = self.root_manifest(gctx)?;
507507
let mut ws = Workspace::new(&root, gctx)?;
508-
ws.set_honor_rust_version(self.honor_rust_version());
508+
ws.set_resolve_honors_rust_version(self.honor_rust_version());
509509
if gctx.cli_unstable().avoid_dev_deps {
510510
ws.set_require_optional_deps(false);
511511
}

0 commit comments

Comments
 (0)