Skip to content

Commit 2ee8b0e

Browse files
committed
Remove remove_blank_lines_at_start_or_end_of_block
cc #1974
1 parent dd9c15a commit 2ee8b0e

File tree

3 files changed

+50
-95
lines changed

3 files changed

+50
-95
lines changed

Configurations.md

-39
Original file line numberDiff line numberDiff line change
@@ -1991,45 +1991,6 @@ fn bar() {
19911991
}
19921992
```
19931993

1994-
## `remove_blank_lines_at_start_or_end_of_block`
1995-
1996-
Remove blank lines at the start or the end of a block.
1997-
1998-
- **Default value**: `true`
1999-
- **Possible values**: `true`, `false`
2000-
- **Stable**: No
2001-
2002-
#### `true`
2003-
2004-
```rust
2005-
fn foo() {
2006-
let msg = {
2007-
let mut str = String::new();
2008-
str.push_str("hello, ");
2009-
str.push_str("world!");
2010-
str
2011-
};
2012-
println!("{}", msg);
2013-
}
2014-
```
2015-
2016-
#### `false`
2017-
2018-
```rust
2019-
fn foo() {
2020-
2021-
let msg = {
2022-
2023-
let mut str = String::new();
2024-
str.push_str("hello, ");
2025-
str.push_str("world!");
2026-
str
2027-
2028-
};
2029-
println!("{}", msg);
2030-
2031-
}
2032-
```
20331994

20341995
## `required_version`
20351996

src/config/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ create_config! {
8383

8484
// Misc.
8585
remove_nested_parens: bool, true, true, "Remove nested parens.";
86-
remove_blank_lines_at_start_or_end_of_block: bool, true, false,
87-
"Remove blank lines at start or end of a block";
8886
combine_control_expr: bool, true, false, "Combine control expressions with function calls.";
8987
struct_field_align_threshold: usize, 0, false, "Align struct fields if their diffs fits within \
9088
threshold.";

src/visitor.rs

+50-54
Original file line numberDiff line numberDiff line change
@@ -128,45 +128,43 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
128128
self.block_indent = self.block_indent.block_indent(self.config);
129129
self.push_str("{");
130130

131-
if self.config.remove_blank_lines_at_start_or_end_of_block() {
132-
if let Some(first_stmt) = b.stmts.first() {
133-
let attr_lo = inner_attrs
134-
.and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
135-
.or_else(|| {
136-
// Attributes for an item in a statement position
137-
// do not belong to the statement. (rust-lang/rust#34459)
138-
if let ast::StmtKind::Item(ref item) = first_stmt.node {
139-
item.attrs.first()
140-
} else {
141-
first_stmt.attrs().first()
142-
}.and_then(|attr| {
143-
// Some stmts can have embedded attributes.
144-
// e.g. `match { #![attr] ... }`
145-
let attr_lo = attr.span.lo();
146-
if attr_lo < first_stmt.span.lo() {
147-
Some(attr_lo)
148-
} else {
149-
None
150-
}
151-
})
152-
});
153-
154-
let snippet = self.snippet(mk_sp(
155-
self.last_pos,
156-
attr_lo.unwrap_or_else(|| first_stmt.span.lo()),
157-
));
158-
let len = CommentCodeSlices::new(snippet)
159-
.nth(0)
160-
.and_then(|(kind, _, s)| {
161-
if kind == CodeCharKind::Normal {
162-
s.rfind('\n')
131+
if let Some(first_stmt) = b.stmts.first() {
132+
let attr_lo = inner_attrs
133+
.and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
134+
.or_else(|| {
135+
// Attributes for an item in a statement position
136+
// do not belong to the statement. (rust-lang/rust#34459)
137+
if let ast::StmtKind::Item(ref item) = first_stmt.node {
138+
item.attrs.first()
139+
} else {
140+
first_stmt.attrs().first()
141+
}.and_then(|attr| {
142+
// Some stmts can have embedded attributes.
143+
// e.g. `match { #![attr] ... }`
144+
let attr_lo = attr.span.lo();
145+
if attr_lo < first_stmt.span.lo() {
146+
Some(attr_lo)
163147
} else {
164148
None
165149
}
166-
});
167-
if let Some(len) = len {
168-
self.last_pos = self.last_pos + BytePos::from_usize(len);
169-
}
150+
})
151+
});
152+
153+
let snippet = self.snippet(mk_sp(
154+
self.last_pos,
155+
attr_lo.unwrap_or_else(|| first_stmt.span.lo()),
156+
));
157+
let len = CommentCodeSlices::new(snippet)
158+
.nth(0)
159+
.and_then(|(kind, _, s)| {
160+
if kind == CodeCharKind::Normal {
161+
s.rfind('\n')
162+
} else {
163+
None
164+
}
165+
});
166+
if let Some(len) = len {
167+
self.last_pos = self.last_pos + BytePos::from_usize(len);
170168
}
171169
}
172170

@@ -195,24 +193,22 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
195193
}
196194

197195
let mut remove_len = BytePos(0);
198-
if self.config.remove_blank_lines_at_start_or_end_of_block() {
199-
if let Some(stmt) = b.stmts.last() {
200-
let snippet = self.snippet(mk_sp(
201-
stmt.span.hi(),
202-
source!(self, b.span).hi() - brace_compensation,
203-
));
204-
let len = CommentCodeSlices::new(snippet)
205-
.last()
206-
.and_then(|(kind, _, s)| {
207-
if kind == CodeCharKind::Normal && s.trim().is_empty() {
208-
Some(s.len())
209-
} else {
210-
None
211-
}
212-
});
213-
if let Some(len) = len {
214-
remove_len = BytePos::from_usize(len);
215-
}
196+
if let Some(stmt) = b.stmts.last() {
197+
let snippet = self.snippet(mk_sp(
198+
stmt.span.hi(),
199+
source!(self, b.span).hi() - brace_compensation,
200+
));
201+
let len = CommentCodeSlices::new(snippet)
202+
.last()
203+
.and_then(|(kind, _, s)| {
204+
if kind == CodeCharKind::Normal && s.trim().is_empty() {
205+
Some(s.len())
206+
} else {
207+
None
208+
}
209+
});
210+
if let Some(len) = len {
211+
remove_len = BytePos::from_usize(len);
216212
}
217213
}
218214

0 commit comments

Comments
 (0)