Skip to content

Commit

Permalink
refactor: Track when MSRV is explicitly set, either way
Browse files Browse the repository at this point in the history
This will hopefully help when merging between CLI and config with rust-lang#13540.
  • Loading branch information
epage committed Apr 10, 2024
1 parent bd1cf58 commit 2e75d66
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {

let dependencies = parse_dependencies(gctx, args)?;

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

let options = AddOptions {
gctx,
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct AddOptions<'a> {
/// Act as if dependencies will be added
pub dry_run: bool,
/// Whether the minimum supported Rust version should be considered during resolution
pub honor_rust_version: bool,
pub honor_rust_version: Option<bool>,
}

/// Add dependencies to a manifest
Expand Down Expand Up @@ -288,7 +288,7 @@ fn resolve_dependency(
ws: &Workspace<'_>,
spec: &Package,
section: &DepTable,
honor_rust_version: bool,
honor_rust_version: Option<bool>,
gctx: &GlobalContext,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<DependencyUI> {
Expand Down Expand Up @@ -571,7 +571,7 @@ fn get_existing_dependency(
fn get_latest_dependency(
spec: &Package,
dependency: &Dependency,
honor_rust_version: bool,
honor_rust_version: Option<bool>,
gctx: &GlobalContext,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<Dependency> {
Expand Down Expand Up @@ -608,7 +608,7 @@ fn get_latest_dependency(
)
})?;

if honor_rust_version {
if honor_rust_version.unwrap_or(true) {
let (req_msrv, is_msrv) = spec
.rust_version()
.cloned()
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub struct CompileOptions {
pub rustdoc_document_private_items: bool,
/// Whether the build process should check the minimum Rust version
/// defined in the cargo metadata for a crate.
pub honor_rust_version: bool,
pub honor_rust_version: Option<bool>,
}

impl CompileOptions {
Expand All @@ -116,7 +116,7 @@ impl CompileOptions {
target_rustc_args: None,
target_rustc_crate_types: None,
rustdoc_document_private_items: false,
honor_rust_version: true,
honor_rust_version: None,
})
}
}
Expand Down Expand Up @@ -474,7 +474,7 @@ pub fn create_bcx<'a, 'gctx>(
.extend(args);
}

if honor_rust_version {
if honor_rust_version.unwrap_or(true) {
let rustc_version = target_data.rustc.version.clone().into();

let mut incompatible = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ pub fn install(
let dst = root.join("bin").into_path_unlocked();
let map = SourceConfigMap::new(gctx)?;

let current_rust_version = if opts.honor_rust_version {
let current_rust_version = if opts.honor_rust_version.unwrap_or(true) {
let rustc = gctx.load_global_rustc(None)?;
Some(rustc.version.clone().into())
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ fn run_verify(
target_rustc_args: rustc_args,
target_rustc_crate_types: None,
rustdoc_document_private_items: false,
honor_rust_version: true,
honor_rust_version: None,
},
&exec,
)?;
Expand Down
6 changes: 5 additions & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ pub trait ArgMatchesExt {
self.maybe_flag("keep-going")
}

fn honor_rust_version(&self) -> Option<bool> {
self.flag("ignore-rust-version").then_some(false)
}

fn targets(&self) -> CargoResult<Vec<String>> {
if self.is_present_with_zero_values("target") {
let cmd = if is_rustup() {
Expand Down Expand Up @@ -763,7 +767,7 @@ Run `{cmd}` to see possible targets."
target_rustc_args: None,
target_rustc_crate_types: None,
rustdoc_document_private_items: false,
honor_rust_version: !self.flag("ignore-rust-version"),
honor_rust_version: self.honor_rust_version(),
};

if let Some(ws) = workspace {
Expand Down

0 comments on commit 2e75d66

Please sign in to comment.