]> git.lizzy.rs Git - rust.git/blobdiff - src/config.rs
Implement match_arm_forces_newline option (#2039)
[rust.git] / src / config.rs
index f76d13e5dc74cb2164798c007e92353f38ecd733..8c200302c5b0894bb017e22c812231752ba782d6 100644 (file)
@@ -18,6 +18,7 @@
 
 use file_lines::FileLines;
 use lists::{ListTactic, SeparatorPlace, SeparatorTactic};
+use Summary;
 
 macro_rules! configuration_option_enum{
     ($e:ident: $( $x:ident ),+ $(,)*) => {
@@ -272,6 +273,23 @@ pub fn $i(&self) -> bool {
         }
 
         impl Config {
+            pub fn version_meets_requirement(&self, error_summary: &mut Summary) -> bool {
+                if self.was_set().required_version() {
+                    let version = env!("CARGO_PKG_VERSION");
+                    let required_version = self.required_version();
+                    if version != required_version {
+                        println!(
+                            "Error: rustfmt version ({}) doesn't match the required version ({})",
+                            version,
+                            required_version,
+                        );
+                        error_summary.add_formatting_error();
+                        return false;
+                    }
+                }
+
+                true
+            }
 
             $(
             pub fn $i(&self) -> $ty {
@@ -579,6 +597,8 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
                                   the same line with the pattern of arms";
     match_block_trailing_comma: bool, false,
         "Put a trailing comma after a block based match arm (non-block arms are not affected)";
+    match_arm_forces_newline: bool, false,
+        "Force match arm bodies to be in a new lines";
     indent_match_arms: bool, true, "Indent match arms instead of keeping them at the same \
                                     indentation level as the match keyword";
     match_pattern_separator_break_point: SeparatorPlace, SeparatorPlace::Back,
@@ -606,7 +626,7 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
          Replace, Overwrite, Display, Plain, Diff, Coverage";
     condense_wildcard_suffixes: bool, false, "Replace strings of _ wildcards by a single .. in \
                                               tuple patterns";
-    combine_control_expr: bool, true, "Combine control expressions with funciton calls.";
+    combine_control_expr: bool, true, "Combine control expressions with function calls.";
     struct_field_align_threshold: usize, 0, "Align struct fields if their diffs fits within \
                                              threshold.";
     remove_blank_lines_at_start_or_end_of_block: bool, true,
@@ -622,6 +642,8 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     merge_derives: bool, true, "Merge multiple `#[derive(...)]` into a single one";
     binop_separator: SeparatorPlace, SeparatorPlace::Front,
         "Where to put a binary operator when a binary expression goes multiline.";
+    required_version: String, env!("CARGO_PKG_VERSION").to_owned(),
+        "Require a specific version of rustfmt."
 }
 
 #[cfg(test)]