Skip to content

Commit 2e75d66

Browse files
committed
refactor: Track when MSRV is explicitly set, either way
This will hopefully help when merging between CLI and config with #13540.
1 parent bd1cf58 commit 2e75d66

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

src/bin/cargo/commands/add.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
205205

206206
let dependencies = parse_dependencies(gctx, args)?;
207207

208-
let ignore_rust_version = args.flag("ignore-rust-version");
209-
let honor_rust_version = !ignore_rust_version;
208+
let honor_rust_version = args.honor_rust_version();
210209

211210
let options = AddOptions {
212211
gctx,

src/cargo/ops/cargo_add/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct AddOptions<'a> {
5555
/// Act as if dependencies will be added
5656
pub dry_run: bool,
5757
/// Whether the minimum supported Rust version should be considered during resolution
58-
pub honor_rust_version: bool,
58+
pub honor_rust_version: Option<bool>,
5959
}
6060

6161
/// Add dependencies to a manifest
@@ -288,7 +288,7 @@ fn resolve_dependency(
288288
ws: &Workspace<'_>,
289289
spec: &Package,
290290
section: &DepTable,
291-
honor_rust_version: bool,
291+
honor_rust_version: Option<bool>,
292292
gctx: &GlobalContext,
293293
registry: &mut PackageRegistry<'_>,
294294
) -> CargoResult<DependencyUI> {
@@ -571,7 +571,7 @@ fn get_existing_dependency(
571571
fn get_latest_dependency(
572572
spec: &Package,
573573
dependency: &Dependency,
574-
honor_rust_version: bool,
574+
honor_rust_version: Option<bool>,
575575
gctx: &GlobalContext,
576576
registry: &mut PackageRegistry<'_>,
577577
) -> CargoResult<Dependency> {
@@ -608,7 +608,7 @@ fn get_latest_dependency(
608608
)
609609
})?;
610610

611-
if honor_rust_version {
611+
if honor_rust_version.unwrap_or(true) {
612612
let (req_msrv, is_msrv) = spec
613613
.rust_version()
614614
.cloned()

src/cargo/ops/cargo_compile/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub struct CompileOptions {
9898
pub rustdoc_document_private_items: bool,
9999
/// Whether the build process should check the minimum Rust version
100100
/// defined in the cargo metadata for a crate.
101-
pub honor_rust_version: bool,
101+
pub honor_rust_version: Option<bool>,
102102
}
103103

104104
impl CompileOptions {
@@ -116,7 +116,7 @@ impl CompileOptions {
116116
target_rustc_args: None,
117117
target_rustc_crate_types: None,
118118
rustdoc_document_private_items: false,
119-
honor_rust_version: true,
119+
honor_rust_version: None,
120120
})
121121
}
122122
}
@@ -474,7 +474,7 @@ pub fn create_bcx<'a, 'gctx>(
474474
.extend(args);
475475
}
476476

477-
if honor_rust_version {
477+
if honor_rust_version.unwrap_or(true) {
478478
let rustc_version = target_data.rustc.version.clone().into();
479479

480480
let mut incompatible = Vec::new();

src/cargo/ops/cargo_install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ pub fn install(
624624
let dst = root.join("bin").into_path_unlocked();
625625
let map = SourceConfigMap::new(gctx)?;
626626

627-
let current_rust_version = if opts.honor_rust_version {
627+
let current_rust_version = if opts.honor_rust_version.unwrap_or(true) {
628628
let rustc = gctx.load_global_rustc(None)?;
629629
Some(rustc.version.clone().into())
630630
} else {

src/cargo/ops/cargo_package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ fn run_verify(
933933
target_rustc_args: rustc_args,
934934
target_rustc_crate_types: None,
935935
rustdoc_document_private_items: false,
936-
honor_rust_version: true,
936+
honor_rust_version: None,
937937
},
938938
&exec,
939939
)?;

src/cargo/util/command_prelude.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ pub trait ArgMatchesExt {
534534
self.maybe_flag("keep-going")
535535
}
536536

537+
fn honor_rust_version(&self) -> Option<bool> {
538+
self.flag("ignore-rust-version").then_some(false)
539+
}
540+
537541
fn targets(&self) -> CargoResult<Vec<String>> {
538542
if self.is_present_with_zero_values("target") {
539543
let cmd = if is_rustup() {
@@ -763,7 +767,7 @@ Run `{cmd}` to see possible targets."
763767
target_rustc_args: None,
764768
target_rustc_crate_types: None,
765769
rustdoc_document_private_items: false,
766-
honor_rust_version: !self.flag("ignore-rust-version"),
770+
honor_rust_version: self.honor_rust_version(),
767771
};
768772

769773
if let Some(ws) = workspace {

0 commit comments

Comments
 (0)