From d7fe47d858d55fcca7445436dd0517a98c6a13bb Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Thu, 23 Jul 2015 23:08:41 +0200 Subject: [PATCH] Preserve box syntax --- src/expr.rs | 6 ++++-- tests/source/expr.rs | 3 +++ tests/target/expr.rs | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 0beaee9dbf2..cb5188017fd 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -378,11 +378,13 @@ fn rewrite_unary_op(context: &RewriteContext, -> Option { // For some reason, an UnOp is not spanned like BinOp! let operator_str = match *op { - ast::UnOp::UnUniq => "&", + ast::UnOp::UnUniq => "box ", ast::UnOp::UnDeref => "*", ast::UnOp::UnNot => "!", ast::UnOp::UnNeg => "-" }; - Some(format!("{}{}", operator_str, try_opt!(expr.rewrite(context, width - 1, offset)))) + let subexpr = try_opt!(expr.rewrite(context, width - operator_str.len(), offset)); + + Some(format!("{}{}", operator_str, subexpr)) } diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 373e42d67c5..4f6e1b6f74a 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -1,6 +1,9 @@ // Test expressions fn foo() -> bool { + let boxed: Box = box 5; + let referenced = &5; + let very_long_variable_name = ( a + first + simple + test ); let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c); diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 25c84511c41..e5a584ecb96 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -1,6 +1,9 @@ // Test expressions fn foo() -> bool { + let boxed: Box = box 5; + let referenced = &5; + let very_long_variable_name = (a + first + simple + test); let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c);