about summary refs log tree commit diff
path: root/src/libsyntax/print
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-03-18 09:22:38 -0400
committerNiko Matsakis <niko@alum.mit.edu>2015-03-18 20:07:27 -0400
commitc225824bded695c8bced713f5a4c62fe327277bc (patch)
tree6c204a6e9a86dd6c23edf942abfd4abf14e1cf39 /src/libsyntax/print
parentf9a7bc58f89b9b15eb1269f0c0d68baf5fc7e966 (diff)
downloadrust-c225824bded695c8bced713f5a4c62fe327277bc.tar.gz
rust-c225824bded695c8bced713f5a4c62fe327277bc.zip
Require braces when a closure has an explicit return type. This is a
[breaking-change]: instead of a closure like `|| -> i32 22`, prefer `||
-> i32 { 22 }`.

Fixes #23420.
Diffstat (limited to 'src/libsyntax/print')
-rw-r--r--src/libsyntax/print/pprust.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 07303ba51ff..b58c121c5fd 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1777,7 +1777,12 @@ impl<'a> State<'a> {
                 try!(self.print_fn_block_args(&**decl));
                 try!(space(&mut self.s));
 
-                if !body.stmts.is_empty() || !body.expr.is_some() {
+                let default_return = match decl.output {
+                    ast::DefaultReturn(..) => true,
+                    _ => false
+                };
+
+                if !default_return || !body.stmts.is_empty() || body.expr.is_none() {
                     try!(self.print_block_unclosed(&**body));
                 } else {
                     // we extract the block, so as not to create another set of boxes