refactor: use style edition when loading from partial config
This commit is contained in:
parent
5ee4d3b532
commit
53d5ccd5e9
@ -210,7 +210,7 @@ pub fn $i(&self) -> <$ty as StyleEditionDefault>::ConfigType {
|
|||||||
)+
|
)+
|
||||||
|
|
||||||
#[allow(unreachable_pub)]
|
#[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 {
|
Config {
|
||||||
$(
|
$(
|
||||||
$i: (
|
$i: (
|
||||||
|
@ -217,9 +217,37 @@ pub fn to_toml(&self) -> Result<String, ToTomlError> {
|
|||||||
|
|
||||||
::toml::to_string(&cloned).map_err(ToTomlError)
|
::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 {
|
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 {
|
pub(crate) fn version_meets_requirement(&self) -> bool {
|
||||||
if self.was_set().required_version() {
|
if self.was_set().required_version() {
|
||||||
let version = env!("CARGO_PKG_VERSION");
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
@ -324,12 +352,13 @@ pub(crate) fn from_toml(toml: &str, dir: &Path) -> Result<Config, String> {
|
|||||||
err.push_str(msg)
|
err.push_str(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match parsed.try_into() {
|
|
||||||
|
match parsed.try_into::<PartialConfig>() {
|
||||||
Ok(parsed_config) => {
|
Ok(parsed_config) => {
|
||||||
if !err.is_empty() {
|
if !err.is_empty() {
|
||||||
eprint!("{err}");
|
eprint!("{err}");
|
||||||
}
|
}
|
||||||
Ok(Config::default().fill_from_parsed_config(parsed_config, dir))
|
Ok(parsed_config.to_parsed_config(None, None, dir))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
err.push_str("Error: Decoding config file failed:\n");
|
err.push_str("Error: Decoding config file failed:\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user