Allow {} to remain.

This commit is contained in:
Nick Cameron 2015-08-16 16:13:55 +12:00
parent dc2544712c
commit d10629d8a5
4 changed files with 37 additions and 10 deletions

View File

@ -112,6 +112,11 @@ impl Rewrite for ast::Expr {
impl Rewrite for ast::Block {
fn rewrite(&self, context: &RewriteContext, width: usize, offset: usize) -> Option<String> {
let user_str = context.codemap.span_to_snippet(self.span).unwrap();
if user_str == "{}" && width > 1 {
return Some(user_str);
}
let mut visitor = FmtVisitor::from_codemap(context.codemap, context.config);
visitor.block_indent = context.block_indent;

View File

@ -91,3 +91,16 @@ fn baz() {
// Regular unsafe block
}
}
// Test some empty blocks.
fn qux() {
{}
// FIXME this one could be done better.
{ /* a block with a comment */ }
{
}
{
// A block with a comment.
}
}

View File

@ -22,15 +22,13 @@ fn foo() -> bool {
aaaaa)))))))));
{
for _ in 0..10 {
}
for _ in 0..10 {}
}
{
{
{
{
}
{}
}
}
}
@ -47,8 +45,7 @@ fn foo() -> bool {
}
if let Some(x) = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {
}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
if let (some_very_large,
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {
@ -56,8 +53,7 @@ fn foo() -> bool {
if let (some_very_large,
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1111 +
2222 {
}
2222 {}
if let (some_very_large, tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) =
1 + 2 + 3 {
@ -121,3 +117,17 @@ fn baz() {
// Regular unsafe block
}
}
// Test some empty blocks.
fn qux() {
{}
// FIXME this one could be done better.
{ /* a block with a comment */
}
{
}
{
// A block with a comment.
}
}

View File

@ -13,8 +13,7 @@ fn main() {
}
'a: while loooooooooooooooooooooooooooooooooong_variable_name + another_value >
some_other_value {
}
some_other_value {}
while aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb {
}