From d10629d8a5149e224126d2e05943122763f2f4cc Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sun, 16 Aug 2015 16:13:55 +1200 Subject: [PATCH] Allow `{}` to remain. --- src/expr.rs | 5 +++++ tests/source/expr.rs | 13 +++++++++++++ tests/target/expr.rs | 26 ++++++++++++++++++-------- tests/target/loop.rs | 3 +-- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index ce5dfb8cddf..3fb8f85295c 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -112,6 +112,11 @@ impl Rewrite for ast::Expr { impl Rewrite for ast::Block { fn rewrite(&self, context: &RewriteContext, width: usize, offset: usize) -> Option { + 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; diff --git a/tests/source/expr.rs b/tests/source/expr.rs index e7862b83e50..6b3b3daf0a9 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -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. + } +} diff --git a/tests/target/expr.rs b/tests/target/expr.rs index a1875a0ec26..356c5b7dbbd 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -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. + } +} diff --git a/tests/target/loop.rs b/tests/target/loop.rs index e1f2ccc91a4..fea5bfe2cb2 100644 --- a/tests/target/loop.rs +++ b/tests/target/loop.rs @@ -13,8 +13,7 @@ fn main() { } 'a: while loooooooooooooooooooooooooooooooooong_variable_name + another_value > - some_other_value { - } + some_other_value {} while aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb { }