Skip to content

Commit c38b8c8

Browse files
refactor: include edition & style edition in CliOptions
1 parent fb81d4e commit c38b8c8

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/bin/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,18 @@ impl CliOptions for GetOptsOptions {
733733
fn config_path(&self) -> Option<&Path> {
734734
self.config_path.as_deref()
735735
}
736+
737+
fn edition(&self) -> Option<Edition> {
738+
self.inline_config
739+
.get("edition")
740+
.map_or(self.edition, |e| Edition::from_str(e).ok())
741+
}
742+
743+
fn style_edition(&self) -> Option<StyleEdition> {
744+
self.inline_config
745+
.get("style_edition")
746+
.map_or(self.style_edition, |se| StyleEdition::from_str(se).ok())
747+
}
736748
}
737749

738750
fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {

src/config/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,13 @@ pub fn load_config<O: CliOptions>(
376376
file_path: Option<&Path>,
377377
options: Option<O>,
378378
) -> Result<(Config, Option<PathBuf>), Error> {
379-
let over_ride = match options {
380-
Some(ref opts) => config_path(opts)?,
381-
None => None,
379+
let (over_ride, _edition, _style_edition) = match options {
380+
Some(ref opts) => (
381+
config_path(opts)?,
382+
opts.edition(),
383+
opts.style_edition(),
384+
),
385+
None => (None, None, None),
382386
};
383387

384388
let result = if let Some(over_ride) = over_ride {

src/config/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ impl FromStr for IgnoreList {
416416
pub trait CliOptions {
417417
fn apply_to(self, config: &mut Config);
418418
fn config_path(&self) -> Option<&Path>;
419+
fn edition(&self) -> Option<Edition>;
420+
fn style_edition(&self) -> Option<StyleEdition>;
419421
}
420422

421423
/// The edition of the syntax and semantics of code (RFC 2052).

src/git-rustfmt/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ impl CliOptions for NullOptions {
8585
fn config_path(&self) -> Option<&Path> {
8686
unreachable!();
8787
}
88+
fn edition(&self) -> Option<rustfmt_nightly::Edition> {
89+
unreachable!();
90+
}
91+
fn style_edition(&self) -> Option<rustfmt_nightly::StyleEdition> {
92+
unreachable!();
93+
}
8894
}
8995

9096
fn uncommitted_files() -> Vec<String> {

0 commit comments

Comments
 (0)