about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authorNick Cameron <nrc@ncameron.org>2015-09-24 20:30:54 +1200
committerNick Cameron <nrc@ncameron.org>2015-09-24 20:30:54 +1200
commite80080deb60e78e7a57be4d693ca8e96cb14a1b2 (patch)
tree2b3a911ae1463facdfc634f23fa206ab15ba44a6 /src/expr.rs
parentd941fe20b4a9c6c15ed3307abec0f7d04c03db52 (diff)
parent19e887c3097488b8d4d911b9423ffba1dec99987 (diff)
Merge pull request #359 from eefriedman/rewrite-addrof
Add support for formatting AddrOf (unary "&").
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/expr.rs b/src/expr.rs
index b98756612d2..a2be6ee8fd1 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -163,12 +163,14 @@ impl Rewrite for ast::Expr {
             ast::Expr_::ExprRet(Some(ref expr)) => {
                 rewrite_unary_prefix(context, "return ", &expr, width, offset)
             }
+            ast::Expr_::ExprAddrOf(mutability, ref expr) => {
+                rewrite_expr_addrof(context, mutability, &expr, width, offset)
+            }
             // We do not format these expressions yet, but they should still
             // satisfy our width restrictions.
             ast::Expr_::ExprBox(..) |
             ast::Expr_::ExprCast(..) |
             ast::Expr_::ExprIndex(..) |
-            ast::Expr_::ExprAddrOf(..) |
             ast::Expr_::ExprInlineAsm(..) |
             ast::Expr_::ExprRepeat(..) => {
                 wrap_str(context.snippet(self.span), context.config.max_width, width, offset)
@@ -684,11 +686,7 @@ fn rewrite_match_arm_comment(context: &RewriteContext,
     if !missed_str.is_empty() {
         result.push('\n');
         result.push_str(arm_indent_str);
-        result.push_str(&rewrite_comment(&missed_str,
-                                         false,
-                                         width,
-                                         arm_indent,
-                                         context.config));
+        result.push_str(&rewrite_comment(&missed_str, false, width, arm_indent, context.config));
     }
     return result;
 }
@@ -746,7 +744,8 @@ fn rewrite_match(context: &RewriteContext,
     let last_comment = context.snippet(mk_sp(arm_end_pos(&arms[arms.len() - 1]), span.hi));
     result.push_str(&rewrite_match_arm_comment(context,
                                                &last_comment,
-                                               width, arm_indent,
+                                               width,
+                                               arm_indent,
                                                &arm_indent_str));
     result.push('\n');
     result.push_str(&(context.block_indent + context.overflow_indent).to_string(context.config));
@@ -1414,3 +1413,16 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
 
     Some(result)
 }
+
+fn rewrite_expr_addrof(context: &RewriteContext,
+                       mutability: ast::Mutability,
+                       expr: &ast::Expr,
+                       width: usize,
+                       offset: Indent)
+                       -> Option<String> {
+    let operator_str = match mutability {
+        ast::Mutability::MutImmutable => "&",
+        ast::Mutability::MutMutable => "&mut ",
+    };
+    rewrite_unary_prefix(context, operator_str, expr, width, offset)
+}