Skip to content

Commit c0c3dc7

Browse files
refactor: include edition & style edition in CliOptions
1 parent 53d5ccd commit c0c3dc7

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/bin/main.rs

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

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

src/config/mod.rs

+7-3
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

+2
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ pub trait CliOptions {
419419
/// It is ok if the returned path doesn't exist or is not canonicalized
420420
/// (i.e. the callers are expected to handle such cases).
421421
fn config_path(&self) -> Option<&Path>;
422+
fn edition(&self) -> Option<Edition>;
423+
fn style_edition(&self) -> Option<StyleEdition>;
422424
}
423425

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

src/git-rustfmt/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ impl CliOptions for NullOptions {
8989
fn config_path(&self) -> Option<&Path> {
9090
unreachable!();
9191
}
92+
fn edition(&self) -> Option<rustfmt_nightly::Edition> {
93+
unreachable!();
94+
}
95+
fn style_edition(&self) -> Option<rustfmt_nightly::StyleEdition> {
96+
unreachable!();
97+
}
9298
}
9399

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

0 commit comments

Comments
 (0)