diff options
| author | Caleb Cartwright <caleb.cartwright@outlook.com> | 2024-08-01 18:42:45 -0500 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2024-08-27 20:49:15 -0500 |
| commit | 53d5ccd5e965086f7d43d43a1eabdb7064780cb5 (patch) | |
| tree | 1af6b6650f9eed72dc7ed9add5417cc611f32b33 | |
| parent | 5ee4d3b532a4f329fdb9319453a22d5ee9c3a7b0 (diff) | |
| download | rust-53d5ccd5e965086f7d43d43a1eabdb7064780cb5.tar.gz rust-53d5ccd5e965086f7d43d43a1eabdb7064780cb5.zip | |
refactor: use style edition when loading from partial config
| -rw-r--r-- | src/config/config_type.rs | 2 | ||||
| -rw-r--r-- | src/config/mod.rs | 33 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 91efb71744b..4b83e974932 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -210,7 +210,7 @@ macro_rules! create_config { )+ #[allow(unreachable_pub)] - pub fn default_with_style_edition(style_edition: StyleEdition) -> Config { + pub(super) fn default_with_style_edition(style_edition: StyleEdition) -> Config { Config { $( $i: ( diff --git a/src/config/mod.rs b/src/config/mod.rs index 5d6047c385d..6462c62a358 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -217,9 +217,37 @@ impl PartialConfig { ::toml::to_string(&cloned).map_err(ToTomlError) } + + pub(super) fn to_parsed_config( + self, + style_edition_override: Option<StyleEdition>, + edition_override: Option<Edition>, + dir: &Path, + ) -> Config { + Config::default_for_possible_style_edition( + style_edition_override.or(self.style_edition), + edition_override.or(self.edition), + ) + .fill_from_parsed_config(self, dir) + } } impl Config { + pub fn default_for_possible_style_edition( + style_edition: Option<StyleEdition>, + edition: Option<Edition>, + ) -> Config { + style_edition.map_or_else( + || { + edition.map_or_else( + || Config::default(), + |e| Self::default_with_style_edition(e.into()), + ) + }, + |se| Self::default_with_style_edition(se), + ) + } + pub(crate) fn version_meets_requirement(&self) -> bool { if self.was_set().required_version() { let version = env!("CARGO_PKG_VERSION"); @@ -324,12 +352,13 @@ impl Config { err.push_str(msg) } } - match parsed.try_into() { + + match parsed.try_into::<PartialConfig>() { Ok(parsed_config) => { if !err.is_empty() { eprint!("{err}"); } - Ok(Config::default().fill_from_parsed_config(parsed_config, dir)) + Ok(parsed_config.to_parsed_config(None, None, dir)) } Err(e) => { err.push_str("Error: Decoding config file failed:\n"); |
