Skip to content

Commit b7d9c87

Browse files
committed
Extract update_override()
1 parent ddb5a4b commit b7d9c87

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

src/config.rs

+28-16
Original file line numberDiff line numberDiff line change
@@ -487,26 +487,18 @@ impl Cfg {
487487
}
488488

489489
fn find_override_config(&self, path: &Path) -> Result<Option<(OverrideCfg, OverrideReason)>> {
490-
let mut override_ = None::<(OverrideFile, OverrideReason)>;
491-
492-
let mut update_override = |file, reason| {
493-
if let Some((file1, reason1)) = &mut override_ {
494-
if file1.has_toolchain() {
495-
// Update the reason only if the override file has a toolchain.
496-
*reason1 = reason
497-
}
498-
file1.merge(file);
499-
} else {
500-
override_ = Some((file, reason))
501-
};
502-
};
490+
let mut override_ = None;
503491

504492
// Check for all possible toolchain overrides below...
505493
// See: <https://rust-lang.github.io/rustup/overrides.html>
506494

507495
// 1. Check toolchain override from command
508496
if let Some(ref name) = self.toolchain_override {
509-
update_override(name.to_string().into(), OverrideReason::CommandLine);
497+
update_override(
498+
&mut override_,
499+
name.to_string().into(),
500+
OverrideReason::CommandLine,
501+
);
510502
}
511503

512504
// 2. Check RUSTUP_TOOLCHAIN
@@ -515,15 +507,19 @@ impl Cfg {
515507
// custom, distributable, and absolute path toolchains otherwise
516508
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
517509
// error when a nested rustup invocation occurs
518-
update_override(name.to_string().into(), OverrideReason::Environment);
510+
update_override(
511+
&mut override_,
512+
name.to_string().into(),
513+
OverrideReason::Environment,
514+
);
519515
}
520516

521517
// 3. walk up the directory tree from 'path' looking for either the
522518
// directory in override database, or
523519
// 4. a `rust-toolchain` file.
524520
self.settings_file.with(|s| {
525521
if let Some((file, reason)) = self.find_override_from_dir_walk(path, s)? {
526-
update_override(file, reason);
522+
update_override(&mut override_, file, reason);
527523
}
528524
Ok(())
529525
})?;
@@ -1006,6 +1002,22 @@ impl Cfg {
10061002
}
10071003
}
10081004

1005+
fn update_override(
1006+
override_: &mut Option<(OverrideFile, OverrideReason)>,
1007+
file: OverrideFile,
1008+
reason: OverrideReason,
1009+
) {
1010+
if let Some((file1, reason1)) = override_ {
1011+
if file1.has_toolchain() {
1012+
// Update the reason only if the override file has a toolchain.
1013+
*reason1 = reason
1014+
}
1015+
file1.merge(file);
1016+
} else {
1017+
*override_ = Some((file, reason))
1018+
};
1019+
}
1020+
10091021
fn get_default_host_triple(s: &Settings) -> dist::TargetTriple {
10101022
s.default_host_triple
10111023
.as_ref()

0 commit comments

Comments
 (0)