diff --git a/src/chains.rs b/src/chains.rs index a011ad2ffef..665fb5ac073 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -21,7 +21,7 @@ use Indent; use rewrite::{Rewrite, RewriteContext}; -use utils::first_line_width; +use utils::{wrap_str, first_line_width}; use expr::rewrite_call; use config::BlockIndentStyle; @@ -58,12 +58,8 @@ pub fn rewrite_chain(mut expr: &ast::Expr, } else { match context.config.chain_indent { BlockIndentStyle::Inherit => (context.block_indent, false), - BlockIndentStyle::Tabbed => { - (context.block_indent.block_indent(context.config), false) - } - BlockIndentStyle::Visual => { - (offset + Indent::new(context.config.tab_spaces, 0), false) - } + BlockIndentStyle::Tabbed => (context.block_indent.block_indent(context.config), false), + BlockIndentStyle::Visual => (offset + Indent::new(context.config.tab_spaces, 0), false), } }; @@ -142,10 +138,13 @@ pub fn rewrite_chain(mut expr: &ast::Expr, &connector[..] }; - Some(format!("{}{}{}", - parent_rewrite, - first_connector, - rewrites.join(&connector))) + wrap_str(format!("{}{}{}", + parent_rewrite, + first_connector, + rewrites.join(&connector)), + context.config.max_width, + width, + offset) } // States whether an expression's last line exclusively consists of closing diff --git a/src/items.rs b/src/items.rs index 4f3c82ee0ab..19aec73f116 100644 --- a/src/items.rs +++ b/src/items.rs @@ -875,12 +875,14 @@ impl<'a> FmtVisitor<'a> { offset + header_str.len(), mk_sp(span.lo, body_lo))) } - None => if self.config.item_brace_style == BraceStyle::AlwaysNextLine && - !fields.is_empty() { - format!("\n{}{{", self.block_indent.to_string(self.config)) - } else { - " {".to_owned() - }, + None => { + if self.config.item_brace_style == BraceStyle::AlwaysNextLine && + !fields.is_empty() { + format!("\n{}{{", self.block_indent.to_string(self.config)) + } else { + " {".to_owned() + } + } }; result.push_str(&generics_str); diff --git a/tests/source/match.rs b/tests/source/match.rs index 9277319295e..b4d35cb3815 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -11,7 +11,6 @@ fn foo() { an_expression; foo() } - // Perhaps this should introduce braces? Foo(ref bar) => aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, Pattern1 | Pattern2 | Pattern3 => false, @@ -83,7 +82,11 @@ fn main() { "scopeid"), true, true), - } + }; + + match x{ + y=>{/*Block with comment. Preserve me.*/ } + z=>{stmt();} } } fn matches() { diff --git a/tests/target/match.rs b/tests/target/match.rs index b7f41c1dd6b..2c238ea8a68 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -12,7 +12,6 @@ fn foo() { an_expression; foo() } - // Perhaps this should introduce braces? Foo(ref bar) => { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa } @@ -93,6 +92,15 @@ fn main() { true, true) } + }; + + match x { + y => { + // Block with comment. Preserve me. + } + z => { + stmt(); + } } }