]> git.lizzy.rs Git - rust.git/commitdiff
Remove `remove_blank_lines_at_start_or_end_of_block`
authorNick Cameron <ncameron@mozilla.com>
Fri, 18 May 2018 04:56:55 +0000 (16:56 +1200)
committerNick Cameron <ncameron@mozilla.com>
Fri, 18 May 2018 04:56:55 +0000 (16:56 +1200)
cc #1974

Configurations.md
src/config/mod.rs
src/visitor.rs

index 713ecbdab372eca3b04af7a8514aa612b807a6fd..8c893f98d43e5b0a3306cb6ff120eaa1fa2fbe53 100644 (file)
@@ -1991,45 +1991,6 @@ fn bar() {
 }
 ```
 
-## `remove_blank_lines_at_start_or_end_of_block`
-
-Remove blank lines at the start or the end of a block.
-
-- **Default value**: `true`
-- **Possible values**: `true`, `false`
-- **Stable**: No
-
-#### `true`
-
-```rust
-fn foo() {
-    let msg = {
-        let mut str = String::new();
-        str.push_str("hello, ");
-        str.push_str("world!");
-        str
-    };
-    println!("{}", msg);
-}
-```
-
-#### `false`
-
-```rust
-fn foo() {
-
-    let msg = {
-
-        let mut str = String::new();
-        str.push_str("hello, ");
-        str.push_str("world!");
-        str
-
-    };
-    println!("{}", msg);
-
-}
-```
 
 ## `required_version`
 
index 1d76a06e3b5f0616fd6c3e1f64eb961b30460898..e97a351a52a4de27f6fdecb36b8ffd0b99e05126 100644 (file)
@@ -83,8 +83,6 @@
 
     // Misc.
     remove_nested_parens: bool, true, true, "Remove nested parens.";
-    remove_blank_lines_at_start_or_end_of_block: bool, true, false,
-        "Remove blank lines at start or end of a block";
     combine_control_expr: bool, true, false, "Combine control expressions with function calls.";
     struct_field_align_threshold: usize, 0, false, "Align struct fields if their diffs fits within \
                                              threshold.";
index ec1890035a72f28e7c05769fc676d9952b806123..a5f0c4441f6e464c3f445943fcf7e2acb20b325c 100644 (file)
@@ -128,45 +128,43 @@ pub fn visit_block(
         self.block_indent = self.block_indent.block_indent(self.config);
         self.push_str("{");
 
-        if self.config.remove_blank_lines_at_start_or_end_of_block() {
-            if let Some(first_stmt) = b.stmts.first() {
-                let attr_lo = inner_attrs
-                    .and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
-                    .or_else(|| {
-                        // Attributes for an item in a statement position
-                        // do not belong to the statement. (rust-lang/rust#34459)
-                        if let ast::StmtKind::Item(ref item) = first_stmt.node {
-                            item.attrs.first()
-                        } else {
-                            first_stmt.attrs().first()
-                        }.and_then(|attr| {
-                            // Some stmts can have embedded attributes.
-                            // e.g. `match { #![attr] ... }`
-                            let attr_lo = attr.span.lo();
-                            if attr_lo < first_stmt.span.lo() {
-                                Some(attr_lo)
-                            } else {
-                                None
-                            }
-                        })
-                    });
-
-                let snippet = self.snippet(mk_sp(
-                    self.last_pos,
-                    attr_lo.unwrap_or_else(|| first_stmt.span.lo()),
-                ));
-                let len = CommentCodeSlices::new(snippet)
-                    .nth(0)
-                    .and_then(|(kind, _, s)| {
-                        if kind == CodeCharKind::Normal {
-                            s.rfind('\n')
+        if let Some(first_stmt) = b.stmts.first() {
+            let attr_lo = inner_attrs
+                .and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
+                .or_else(|| {
+                    // Attributes for an item in a statement position
+                    // do not belong to the statement. (rust-lang/rust#34459)
+                    if let ast::StmtKind::Item(ref item) = first_stmt.node {
+                        item.attrs.first()
+                    } else {
+                        first_stmt.attrs().first()
+                    }.and_then(|attr| {
+                        // Some stmts can have embedded attributes.
+                        // e.g. `match { #![attr] ... }`
+                        let attr_lo = attr.span.lo();
+                        if attr_lo < first_stmt.span.lo() {
+                            Some(attr_lo)
                         } else {
                             None
                         }
-                    });
-                if let Some(len) = len {
-                    self.last_pos = self.last_pos + BytePos::from_usize(len);
-                }
+                    })
+                });
+
+            let snippet = self.snippet(mk_sp(
+                self.last_pos,
+                attr_lo.unwrap_or_else(|| first_stmt.span.lo()),
+            ));
+            let len = CommentCodeSlices::new(snippet)
+                .nth(0)
+                .and_then(|(kind, _, s)| {
+                    if kind == CodeCharKind::Normal {
+                        s.rfind('\n')
+                    } else {
+                        None
+                    }
+                });
+            if let Some(len) = len {
+                self.last_pos = self.last_pos + BytePos::from_usize(len);
             }
         }
 
@@ -195,24 +193,22 @@ pub fn visit_block(
         }
 
         let mut remove_len = BytePos(0);
-        if self.config.remove_blank_lines_at_start_or_end_of_block() {
-            if let Some(stmt) = b.stmts.last() {
-                let snippet = self.snippet(mk_sp(
-                    stmt.span.hi(),
-                    source!(self, b.span).hi() - brace_compensation,
-                ));
-                let len = CommentCodeSlices::new(snippet)
-                    .last()
-                    .and_then(|(kind, _, s)| {
-                        if kind == CodeCharKind::Normal && s.trim().is_empty() {
-                            Some(s.len())
-                        } else {
-                            None
-                        }
-                    });
-                if let Some(len) = len {
-                    remove_len = BytePos::from_usize(len);
-                }
+        if let Some(stmt) = b.stmts.last() {
+            let snippet = self.snippet(mk_sp(
+                stmt.span.hi(),
+                source!(self, b.span).hi() - brace_compensation,
+            ));
+            let len = CommentCodeSlices::new(snippet)
+                .last()
+                .and_then(|(kind, _, s)| {
+                    if kind == CodeCharKind::Normal && s.trim().is_empty() {
+                        Some(s.len())
+                    } else {
+                        None
+                    }
+                });
+            if let Some(len) = len {
+                remove_len = BytePos::from_usize(len);
             }
         }