diff --git a/src/chains.rs b/src/chains.rs index c59638d9e50..f385012dadd 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -150,10 +150,7 @@ fn rewrite_chain_expr(expr: &ast::Expr, -> Option { match expr.node { ast::Expr_::ExprMethodCall(ref method_name, ref types, ref expressions) => { - let inner = &RewriteContext { - block_indent: offset, - ..*context - }; + let inner = &RewriteContext { block_indent: offset, ..*context }; rewrite_method_call(method_name.node, types, expressions, span, inner, width, offset) } ast::Expr_::ExprField(_, ref field) => { 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>(context: &RewriteContext, Some(result) } + +fn rewrite_expr_addrof(context: &RewriteContext, + mutability: ast::Mutability, + expr: &ast::Expr, + width: usize, + offset: Indent) + -> Option { + let operator_str = match mutability { + ast::Mutability::MutImmutable => "&", + ast::Mutability::MutMutable => "&mut ", + }; + rewrite_unary_prefix(context, operator_str, expr, width, offset) +} diff --git a/src/lists.rs b/src/lists.rs index e00e8b0ee37..60e5c7e5b56 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -200,7 +200,10 @@ pub fn write_list<'b>(items: &[ListItem], formatting: &ListFormatting<'b>) -> Op let block_mode = tactic != ListTactic::Vertical; // Width restriction is only relevant in vertical mode. let max_width = formatting.v_width; - result.push_str(&rewrite_comment(comment, block_mode, max_width, formatting.indent, + result.push_str(&rewrite_comment(comment, + block_mode, + max_width, + formatting.indent, formatting.config)); if tactic == ListTactic::Vertical { diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 5cfd661d080..fc34f799d7d 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -298,3 +298,8 @@ fn returns() { return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; } + +fn addrof() { + & mut(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); + & (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); +} diff --git a/tests/target/expr.rs b/tests/target/expr.rs index dc9ab9d71ef..34205819f60 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -306,3 +306,10 @@ fn returns() { return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; } + +fn addrof() { + &mut (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); + &(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); +}