Skip to content

Commit c18434a

Browse files
onur-ozkanrezwanahmedsami
authored andcommitted
separate inner function (get_toml) of Config::parse
Signed-off-by: onur-ozkan <[email protected]>
1 parent faf5eab commit c18434a

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,37 +1203,39 @@ impl Config {
12031203
}
12041204
}
12051205

1206-
pub fn parse(flags: Flags) -> Config {
1207-
#[cfg(test)]
1208-
fn get_toml(_: &Path) -> TomlConfig {
1209-
TomlConfig::default()
1210-
}
1206+
#[cfg(test)]
1207+
fn get_toml(_: &Path) -> TomlConfig {
1208+
TomlConfig::default()
1209+
}
12111210

1212-
#[cfg(not(test))]
1213-
fn get_toml(file: &Path) -> TomlConfig {
1214-
let contents =
1215-
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
1216-
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
1217-
// TomlConfig and sub types to be monomorphized 5x by toml.
1218-
toml::from_str(&contents)
1219-
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
1220-
.unwrap_or_else(|err| {
1221-
if let Ok(Some(changes)) = toml::from_str(&contents)
1222-
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table)).map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
1223-
{
1224-
if !changes.is_empty() {
1225-
println!(
1226-
"WARNING: There have been changes to x.py since you last updated:\n{}",
1227-
crate::human_readable_changes(&changes)
1228-
);
1229-
}
1211+
#[cfg(not(test))]
1212+
fn get_toml(file: &Path) -> TomlConfig {
1213+
let contents =
1214+
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
1215+
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
1216+
// TomlConfig and sub types to be monomorphized 5x by toml.
1217+
toml::from_str(&contents)
1218+
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
1219+
.unwrap_or_else(|err| {
1220+
if let Ok(Some(changes)) = toml::from_str(&contents)
1221+
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
1222+
.map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
1223+
{
1224+
if !changes.is_empty() {
1225+
println!(
1226+
"WARNING: There have been changes to x.py since you last updated:\n{}",
1227+
crate::human_readable_changes(&changes)
1228+
);
12301229
}
1230+
}
12311231

1232-
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1233-
exit!(2);
1234-
})
1235-
}
1236-
Self::parse_inner(flags, get_toml)
1232+
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1233+
exit!(2);
1234+
})
1235+
}
1236+
1237+
pub fn parse(flags: Flags) -> Config {
1238+
Self::parse_inner(flags, Self::get_toml)
12371239
}
12381240

12391241
pub(crate) fn parse_inner(mut flags: Flags, get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
@@ -2668,21 +2670,21 @@ fn check_incompatible_options_for_ci_rustc(rust: &Rust) -> Result<(), String> {
26682670
macro_rules! err {
26692671
($name:expr) => {
26702672
if $name.is_some() {
2671-
return Err(format!(
2672-
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.",
2673+
return Err(format!(
2674+
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.",
26732675
stringify!($name).replace("_", "-")
2674-
));
2676+
));
26752677
}
26762678
};
26772679
}
26782680

26792681
macro_rules! warn {
26802682
($name:expr) => {
26812683
if $name.is_some() {
2682-
println!(
2683-
"WARNING: `rust.{}` has no effect with `rust.download-rustc`.",
2684+
println!(
2685+
"WARNING: `rust.{}` has no effect with `rust.download-rustc`.",
26842686
stringify!($name).replace("_", "-")
2685-
);
2687+
);
26862688
}
26872689
};
26882690
}

0 commit comments

Comments
 (0)