Skip to content

Commit b2f1fc1

Browse files
committed
separate inner function (get_toml) of Config::parse
Signed-off-by: onur-ozkan <[email protected]>
1 parent aba675f commit b2f1fc1

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
@@ -1191,37 +1191,39 @@ impl Config {
11911191
}
11921192
}
11931193

1194-
pub fn parse(flags: Flags) -> Config {
1195-
#[cfg(test)]
1196-
fn get_toml(_: &Path) -> TomlConfig {
1197-
TomlConfig::default()
1198-
}
1194+
#[cfg(test)]
1195+
fn get_toml(_: &Path) -> TomlConfig {
1196+
TomlConfig::default()
1197+
}
11991198

1200-
#[cfg(not(test))]
1201-
fn get_toml(file: &Path) -> TomlConfig {
1202-
let contents =
1203-
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
1204-
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
1205-
// TomlConfig and sub types to be monomorphized 5x by toml.
1206-
toml::from_str(&contents)
1207-
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
1208-
.unwrap_or_else(|err| {
1209-
if let Ok(Some(changes)) = toml::from_str(&contents)
1210-
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table)).map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
1211-
{
1212-
if !changes.is_empty() {
1213-
println!(
1214-
"WARNING: There have been changes to x.py since you last updated:\n{}",
1215-
crate::human_readable_changes(&changes)
1216-
);
1217-
}
1199+
#[cfg(not(test))]
1200+
fn get_toml(file: &Path) -> TomlConfig {
1201+
let contents =
1202+
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
1203+
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
1204+
// TomlConfig and sub types to be monomorphized 5x by toml.
1205+
toml::from_str(&contents)
1206+
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
1207+
.unwrap_or_else(|err| {
1208+
if let Ok(Some(changes)) = toml::from_str(&contents)
1209+
.and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table))
1210+
.map(|change_id| change_id.inner.map(crate::find_recent_config_change_ids))
1211+
{
1212+
if !changes.is_empty() {
1213+
println!(
1214+
"WARNING: There have been changes to x.py since you last updated:\n{}",
1215+
crate::human_readable_changes(&changes)
1216+
);
12181217
}
1218+
}
12191219

1220-
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1221-
exit!(2);
1222-
})
1223-
}
1224-
Self::parse_inner(flags, get_toml)
1220+
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1221+
exit!(2);
1222+
})
1223+
}
1224+
1225+
pub fn parse(flags: Flags) -> Config {
1226+
Self::parse_inner(flags, Self::get_toml)
12251227
}
12261228

12271229
pub(crate) fn parse_inner(mut flags: Flags, get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
@@ -2656,21 +2658,21 @@ fn check_incompatible_options_for_ci_rustc(rust: &Rust) -> Result<(), String> {
26562658
macro_rules! err {
26572659
($name:expr) => {
26582660
if $name.is_some() {
2659-
return Err(format!(
2660-
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.",
2661+
return Err(format!(
2662+
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.",
26612663
stringify!($name).replace("_", "-")
2662-
));
2664+
));
26632665
}
26642666
};
26652667
}
26662668

26672669
macro_rules! warn {
26682670
($name:expr) => {
26692671
if $name.is_some() {
2670-
println!(
2671-
"WARNING: `rust.{}` has no effect with `rust.download-rustc`.",
2672+
println!(
2673+
"WARNING: `rust.{}` has no effect with `rust.download-rustc`.",
26722674
stringify!($name).replace("_", "-")
2673-
);
2675+
);
26742676
}
26752677
};
26762678
}

0 commit comments

Comments
 (0)