diff --git a/src/comment.rs b/src/comment.rs index d31ba5f9f2d..e9f84b71e48 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -319,8 +319,8 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> &'a str { } else { &line[opener.trim_right().len()..] } - } else if line.starts_with("/* ") || line.starts_with("// ") || - line.starts_with("//!") || line.starts_with("///") || + } else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") || + line.starts_with("///") || line.starts_with("** ") || line.starts_with("/*!") || (line.starts_with("/**") && !line.starts_with("/**/")) { diff --git a/src/expr.rs b/src/expr.rs index 7729ef5f10b..d236448caf5 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -729,9 +729,10 @@ fn and_one_line(x: Option) -> Option { fn nop_block_collapse(block_str: Option, budget: usize) -> Option { debug!("nop_block_collapse {:?} {}", block_str, budget); - block_str.map(|block_str| if block_str.starts_with('{') && - budget >= 2 && - (block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2) + block_str.map(|block_str| if block_str.starts_with('{') && budget >= 2 && + (block_str[1..] + .find(|c: char| !c.is_whitespace()) + .unwrap() == block_str.len() - 2) { "{}".to_owned() } else { @@ -1509,9 +1510,9 @@ impl Rewrite for ast::Arm { let pats_str = format!("{}{}", pats_str, guard_str); let (mut extend, body) = match body.node { - ast::ExprKind::Block(ref block) if !is_unsafe_block(block) && - is_simple_block(block, context.codemap) && - context.config.wrap_match_arms() => { + ast::ExprKind::Block(ref block) + if !is_unsafe_block(block) && is_simple_block(block, context.codemap) && + context.config.wrap_match_arms() => { if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node { (false, &**expr) } else { @@ -2539,21 +2540,10 @@ pub fn rewrite_assign_rhs>( // FIXME: DRY! match (rhs, new_rhs) { - (Some(ref orig_rhs), Some(ref replacement_rhs)) if count_line_breaks( - orig_rhs, - ) > - count_line_breaks( - replacement_rhs, - ) + 1 || - (orig_rhs - .rewrite(context, shape) - .is_none() && - replacement_rhs - .rewrite( - context, - new_shape, - ) - .is_some()) => { + (Some(ref orig_rhs), Some(ref replacement_rhs)) + if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 || + (orig_rhs.rewrite(context, shape).is_none() && + replacement_rhs.rewrite(context, new_shape).is_some()) => { result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config))); result.push_str(replacement_rhs); } diff --git a/src/items.rs b/src/items.rs index 2e00bcbd10d..a660f287a5b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -685,12 +685,12 @@ fn format_impl_ref_and_type( offset: Indent, ) -> Option { if let ast::ItemKind::Impl(unsafety, - polarity, - _, - ref generics, - ref trait_ref, - ref self_ty, - _) = item.node + polarity, + _, + ref generics, + ref trait_ref, + ref self_ty, + _) = item.node { let mut result = String::new(); @@ -942,8 +942,8 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) let has_body = !trait_items.is_empty(); let where_density = if (context.config.where_density() == Density::Compressed && - (!result.contains('\n') || - context.config.fn_args_layout() == IndentStyle::Block)) || + (!result.contains('\n') || + context.config.fn_args_layout() == IndentStyle::Block)) || (context.config.fn_args_layout() == IndentStyle::Block && result.is_empty()) || (context.config.where_density() == Density::CompressedIfEmpty && !has_body && !result.contains('\n')) @@ -1468,9 +1468,9 @@ impl Rewrite for ast::StructField { Some(ref ty) if ty.contains('\n') => { let new_ty = rewrite_type_in_next_line(); match new_ty { - Some(ref new_ty) if !new_ty.contains('\n') && - new_ty.len() + type_offset.width() <= - context.config.max_width() => { + Some(ref new_ty) + if !new_ty.contains('\n') && + new_ty.len() + type_offset.width() <= context.config.max_width() => { Some(format!( "{}\n{}{}", result, @@ -2688,7 +2688,8 @@ fn format_generics( let same_line_brace = force_same_line_brace || (generics.where_clause.predicates.is_empty() && trimmed_last_line_width(&result) == 1); if !same_line_brace && - (brace_style == BraceStyle::SameLineWhere || brace_style == BraceStyle::AlwaysNextLine) + (brace_style == BraceStyle::SameLineWhere || + brace_style == BraceStyle::AlwaysNextLine) { result.push('\n'); result.push_str(&offset.block_only().to_string(context.config)); diff --git a/src/string.rs b/src/string.rs index 6c20c18ca47..5ba273ad272 100644 --- a/src/string.rs +++ b/src/string.rs @@ -81,7 +81,7 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option if cur_end < cur_start + MIN_STRING { cur_end = cur_start + max_chars; while !(punctuation.contains(graphemes[cur_end - 1]) || - graphemes[cur_end - 1].trim().is_empty()) + graphemes[cur_end - 1].trim().is_empty()) { if cur_end >= graphemes.len() { let line = &graphemes[cur_start..].join(""); diff --git a/src/types.rs b/src/types.rs index 5e57ce790a7..3774df70146 100644 --- a/src/types.rs +++ b/src/types.rs @@ -206,9 +206,9 @@ fn rewrite_segment( let params = if let Some(ref params) = segment.parameters { match **params { - ast::PathParameters::AngleBracketed(ref data) if !data.lifetimes.is_empty() || - !data.types.is_empty() || - !data.bindings.is_empty() => { + ast::PathParameters::AngleBracketed(ref data) + if !data.lifetimes.is_empty() || !data.types.is_empty() || + !data.bindings.is_empty() => { let param_list = data.lifetimes .iter() .map(SegmentParam::LifeTime) diff --git a/src/visitor.rs b/src/visitor.rs index 7e3fed3faff..9ed40cc29ee 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -546,10 +546,11 @@ impl<'a> FmtVisitor<'a> { fn push_rewrite(&mut self, span: Span, rewrite: Option) { self.format_missing_with_indent(source!(self, span).lo); self.failed = match rewrite { - Some(ref s) if s.rewrite( - &self.get_context(), - Shape::indented(self.block_indent, self.config), - ).is_none() => true, + Some(ref s) + if s.rewrite( + &self.get_context(), + Shape::indented(self.block_indent, self.config), + ).is_none() => true, None => true, _ => self.failed, }; diff --git a/tests/target/configs-control_style-rfc.rs b/tests/target/configs-control_style-rfc.rs index 43a10e92339..20742da2195 100644 --- a/tests/target/configs-control_style-rfc.rs +++ b/tests/target/configs-control_style-rfc.rs @@ -5,7 +5,7 @@ fn main() { loop { if foo { if ((right_paddle_speed < 0.) && - (right_paddle.position().y - paddle_size.y / 2. > 5.)) || + (right_paddle.position().y - paddle_size.y / 2. > 5.)) || ((right_paddle_speed > 0.) && (right_paddle.position().y + paddle_size.y / 2. < game_height as f32 - 5.)) { diff --git a/tests/target/configs-trailing_comma-never.rs b/tests/target/configs-trailing_comma-never.rs index f38d26d64db..8f351e8dfc2 100644 --- a/tests/target/configs-trailing_comma-never.rs +++ b/tests/target/configs-trailing_comma-never.rs @@ -14,10 +14,10 @@ fn main() { // #1544 if let VrMsg::ClientReply { - request_num: reply_req_num, - value, - .. - } = msg + request_num: reply_req_num, + value, + .. + } = msg { let _ = safe_assert_eq!(reply_req_num, request_num, op); return Ok((request_num, op, value)); diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 3932992af62..3b17aee5a78 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -7,8 +7,8 @@ fn foo() -> bool { 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); + let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + + BBBBBBBBBBBBBBBBB + b + c); let is_internalxxxx = self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner); @@ -20,8 +20,10 @@ fn foo() -> bool { 10000 * 30000000000 + 40000 / 1002200000000 - 50000 * sqrt(-1), trivial_value, ); - (((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + a + - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaa))))))))) ; + (((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + a + + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + aaaaa))))))))); { for _ in 0..10 {} @@ -47,21 +49,21 @@ fn foo() -> bool { } if let Some(x) = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} if let (some_very_large, - tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 + tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 { } if let (some_very_large, - tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = + tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1111 + 2222 {} if let (some_very_large, - tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 + tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {} let test = if true { 5 } else { 3 }; diff --git a/tests/target/fn_args_layout-block.rs b/tests/target/fn_args_layout-block.rs index 93f14c526bd..1d4a1fb6792 100644 --- a/tests/target/fn_args_layout-block.rs +++ b/tests/target/fn_args_layout-block.rs @@ -96,7 +96,12 @@ fn foo() { foo(); } -fn foo() { +fn foo< + L: Loooooooooooooooooooooong, + G: Geeeeeeeeeeeneric, + I: iiiiiiiiis, + L: Looooooooooooooooong, +>() { foo(); } diff --git a/tests/target/hard-tabs.rs b/tests/target/hard-tabs.rs index 42d3875ad19..48c72afd055 100644 --- a/tests/target/hard-tabs.rs +++ b/tests/target/hard-tabs.rs @@ -22,7 +22,7 @@ fn main() { let str = "AAAAAAAAAAAAAAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaAa"; if let (some_very_large, - tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 + tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {} if cond() { diff --git a/tests/target/issue-1397.rs b/tests/target/issue-1397.rs index f267a91d3e1..21c3c9e38de 100644 --- a/tests/target/issue-1397.rs +++ b/tests/target/issue-1397.rs @@ -12,8 +12,8 @@ fn baz(p: Packet) { loop { loop { if let Packet::Transaction { - state: TransactionState::Committed(ts, ..), .. - } = p + state: TransactionState::Committed(ts, ..), .. + } = p { unreachable!() } diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 6185e21a835..9cc3305ea39 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -67,13 +67,18 @@ fn main() { vec![a, b; c]; vec![a; b, c]; - vec![a; - (|x| { - let y = x + 1; - let z = y + 1; - z - })(2)]; - vec![a; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]; + vec![ + a; + (|x| { + let y = x + 1; + let z = y + 1; + z + })(2) + ]; + vec![ + a; + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + ]; vec![a; unsafe { x + 1 }]; unknown_bracket_macro__comma_should_not_be_stripped![ diff --git a/tests/target/match.rs b/tests/target/match.rs index 35b97094535..040fbf155a4 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -37,10 +37,8 @@ fn foo() { Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {} _ => {} - ast::PathParameters::AngleBracketedParameters(ref data) if data.lifetimes.len() > - 0 || - data.types.len() > 0 || - data.bindings.len() > 0 => {} + ast::PathParameters::AngleBracketedParameters(ref data) + if data.lifetimes.len() > 0 || data.types.len() > 0 || data.bindings.len() > 0 => {} } let whatever = match something { @@ -316,16 +314,15 @@ fn issue386() { fn guards() { match foo { - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo && - barrrrrrrrrrrr => {} + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + if foooooooooooooo && barrrrrrrrrrrr => {} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo && - barrrrrrrrrrrr => {} + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + if foooooooooooooo && barrrrrrrrrrrr => {} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if fooooooooooooooooooooo && - (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => { - {} - } + (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || + cccccccccccccccccccccccccccccccccccccccc) => {} } }