Skip to content

Commit 53d5ccd

Browse files
refactor: use style edition when loading from partial config
1 parent 5ee4d3b commit 53d5ccd

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/config/config_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ macro_rules! create_config {
210210
)+
211211

212212
#[allow(unreachable_pub)]
213-
pub fn default_with_style_edition(style_edition: StyleEdition) -> Config {
213+
pub(super) fn default_with_style_edition(style_edition: StyleEdition) -> Config {
214214
Config {
215215
$(
216216
$i: (

src/config/mod.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,37 @@ impl PartialConfig {
217217

218218
::toml::to_string(&cloned).map_err(ToTomlError)
219219
}
220+
221+
pub(super) fn to_parsed_config(
222+
self,
223+
style_edition_override: Option<StyleEdition>,
224+
edition_override: Option<Edition>,
225+
dir: &Path,
226+
) -> Config {
227+
Config::default_for_possible_style_edition(
228+
style_edition_override.or(self.style_edition),
229+
edition_override.or(self.edition),
230+
)
231+
.fill_from_parsed_config(self, dir)
232+
}
220233
}
221234

222235
impl Config {
236+
pub fn default_for_possible_style_edition(
237+
style_edition: Option<StyleEdition>,
238+
edition: Option<Edition>,
239+
) -> Config {
240+
style_edition.map_or_else(
241+
|| {
242+
edition.map_or_else(
243+
|| Config::default(),
244+
|e| Self::default_with_style_edition(e.into()),
245+
)
246+
},
247+
|se| Self::default_with_style_edition(se),
248+
)
249+
}
250+
223251
pub(crate) fn version_meets_requirement(&self) -> bool {
224252
if self.was_set().required_version() {
225253
let version = env!("CARGO_PKG_VERSION");
@@ -324,12 +352,13 @@ impl Config {
324352
err.push_str(msg)
325353
}
326354
}
327-
match parsed.try_into() {
355+
356+
match parsed.try_into::<PartialConfig>() {
328357
Ok(parsed_config) => {
329358
if !err.is_empty() {
330359
eprint!("{err}");
331360
}
332-
Ok(Config::default().fill_from_parsed_config(parsed_config, dir))
361+
Ok(parsed_config.to_parsed_config(None, None, dir))
333362
}
334363
Err(e) => {
335364
err.push_str("Error: Decoding config file failed:\n");

0 commit comments

Comments
 (0)