refactor: include edition & style edition in CliOptions
This commit is contained in:
parent
53d5ccd5e9
commit
c0c3dc7a25
@ -734,6 +734,18 @@ fn apply_to(self, config: &mut Config) {
|
||||
fn config_path(&self) -> Option<&Path> {
|
||||
self.config_path.as_deref()
|
||||
}
|
||||
|
||||
fn edition(&self) -> Option<Edition> {
|
||||
self.inline_config
|
||||
.get("edition")
|
||||
.map_or(self.edition, |e| Edition::from_str(e).ok())
|
||||
}
|
||||
|
||||
fn style_edition(&self) -> Option<StyleEdition> {
|
||||
self.inline_config
|
||||
.get("style_edition")
|
||||
.map_or(self.style_edition, |se| StyleEdition::from_str(se).ok())
|
||||
}
|
||||
}
|
||||
|
||||
fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
|
||||
|
@ -376,9 +376,13 @@ pub fn load_config<O: CliOptions>(
|
||||
file_path: Option<&Path>,
|
||||
options: Option<O>,
|
||||
) -> Result<(Config, Option<PathBuf>), Error> {
|
||||
let over_ride = match options {
|
||||
Some(ref opts) => config_path(opts)?,
|
||||
None => None,
|
||||
let (over_ride, _edition, _style_edition) = match options {
|
||||
Some(ref opts) => (
|
||||
config_path(opts)?,
|
||||
opts.edition(),
|
||||
opts.style_edition(),
|
||||
),
|
||||
None => (None, None, None),
|
||||
};
|
||||
|
||||
let result = if let Some(over_ride) = over_ride {
|
||||
|
@ -419,6 +419,8 @@ pub trait CliOptions {
|
||||
/// It is ok if the returned path doesn't exist or is not canonicalized
|
||||
/// (i.e. the callers are expected to handle such cases).
|
||||
fn config_path(&self) -> Option<&Path>;
|
||||
fn edition(&self) -> Option<Edition>;
|
||||
fn style_edition(&self) -> Option<StyleEdition>;
|
||||
}
|
||||
|
||||
/// The edition of the syntax and semantics of code (RFC 2052).
|
||||
|
@ -89,6 +89,12 @@ fn apply_to(self, _: &mut rustfmt::Config) {
|
||||
fn config_path(&self) -> Option<&Path> {
|
||||
unreachable!();
|
||||
}
|
||||
fn edition(&self) -> Option<rustfmt_nightly::Edition> {
|
||||
unreachable!();
|
||||
}
|
||||
fn style_edition(&self) -> Option<rustfmt_nightly::StyleEdition> {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
fn uncommitted_files() -> Vec<String> {
|
||||
|
Loading…
Reference in New Issue
Block a user