diff options
| -rw-r--r-- | src/bin/main.rs | 12 | ||||
| -rw-r--r-- | src/config/mod.rs | 10 | ||||
| -rw-r--r-- | src/config/options.rs | 2 | ||||
| -rw-r--r-- | src/git-rustfmt/main.rs | 6 |
4 files changed, 27 insertions, 3 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 1185454c8e7..2e4877c7569 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -734,6 +734,18 @@ impl CliOptions for GetOptsOptions { 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> { diff --git a/src/config/mod.rs b/src/config/mod.rs index 6462c62a358..3b77902fa2a 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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 { diff --git a/src/config/options.rs b/src/config/options.rs index 40cfafed29d..f7a8c114330 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -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). diff --git a/src/git-rustfmt/main.rs b/src/git-rustfmt/main.rs index 5674f40bef9..14ac81322b9 100644 --- a/src/git-rustfmt/main.rs +++ b/src/git-rustfmt/main.rs @@ -89,6 +89,12 @@ impl CliOptions for NullOptions { 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> { |
