From 1771dfca08538a501ec2a2be438f09ff76a25c7b Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sun, 1 Oct 2017 21:20:15 +0900 Subject: [PATCH] Break after '=' if a single line rhs exceeds max width --- src/expr.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 9b59e0cbd787..de2166bddbe4 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2895,7 +2895,7 @@ pub fn rewrite_assign_rhs>( let rhs = try_opt!(choose_rhs( context, ex, - shape, + orig_shape, ex.rewrite(context, orig_shape) )); Some(lhs + &rhs) @@ -2908,7 +2908,9 @@ fn choose_rhs( orig_rhs: Option, ) -> Option { match orig_rhs { - Some(ref new_str) if !new_str.contains('\n') => Some(format!(" {}", new_str)), + Some(ref new_str) if !new_str.contains('\n') && new_str.len() <= shape.width => { + Some(format!(" {}", new_str)) + } _ => { // Expression did not fit on the same line as the identifier. // Try splitting the line and see if that works better.