Skip to content

Commit

Permalink
refactor(msrv): Simplify tracking of use of MSRV-aware resolver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epage committed Apr 23, 2024
1 parent b89b81a commit cd8d5f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
// code as we can.
let root_manifest = args.root_manifest(gctx)?;
let mut ws = Workspace::new(&root_manifest, gctx)?;
ws.set_honor_rust_version(args.honor_rust_version());
ws.set_resolve_honors_rust_version(args.honor_rust_version());
let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;

if !opts.filter.is_specific() {
Expand Down
16 changes: 5 additions & 11 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pub struct Workspace<'gctx> {
/// The resolver behavior specified with the `resolver` field.
resolve_behavior: ResolveBehavior,
resolve_honors_rust_version: bool,
honor_rust_version: Option<bool>,

/// Workspace-level custom metadata
custom_metadata: Option<toml::Value>,
Expand Down Expand Up @@ -235,7 +234,6 @@ impl<'gctx> Workspace<'gctx> {
ignore_lock: false,
resolve_behavior: ResolveBehavior::V1,
resolve_honors_rust_version: false,
honor_rust_version: None,
custom_metadata: None,
}
}
Expand Down Expand Up @@ -649,18 +647,14 @@ impl<'gctx> Workspace<'gctx> {
self.members().filter_map(|pkg| pkg.rust_version()).min()
}

pub fn set_honor_rust_version(&mut self, honor_rust_version: Option<bool>) {
self.honor_rust_version = honor_rust_version;
}

pub fn honor_rust_version(&self) -> Option<bool> {
self.honor_rust_version
pub fn set_resolve_honors_rust_version(&mut self, honor_rust_version: Option<bool>) {
if let Some(honor_rust_version) = honor_rust_version {
self.resolve_honors_rust_version = honor_rust_version;
}
}

pub fn resolve_honors_rust_version(&self) -> bool {
// Give CLI precedence
self.honor_rust_version
.unwrap_or(self.resolve_honors_rust_version)
self.resolve_honors_rust_version
}

pub fn custom_metadata(&self) -> Option<&toml::Value> {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn fix(
check_resolver_change(&original_ws, opts)?;
}
let mut ws = Workspace::new(&root_manifest, gctx)?;
ws.set_honor_rust_version(original_ws.honor_rust_version());
ws.set_resolve_honors_rust_version(Some(original_ws.resolve_honors_rust_version()));

// Spin up our lock server, which our subprocesses will use to synchronize fixes.
let lock_server = LockServer::new()?;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ pub trait ArgMatchesExt {
fn workspace<'a>(&self, gctx: &'a GlobalContext) -> CargoResult<Workspace<'a>> {
let root = self.root_manifest(gctx)?;
let mut ws = Workspace::new(&root, gctx)?;
ws.set_honor_rust_version(self.honor_rust_version());
ws.set_resolve_honors_rust_version(self.honor_rust_version());
if gctx.cli_unstable().avoid_dev_deps {
ws.set_require_optional_deps(false);
}
Expand Down

0 comments on commit cd8d5f7

Please sign in to comment.