diff --git a/src/chains.rs b/src/chains.rs index 27293175abb..1460c446352 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -424,10 +424,8 @@ fn rewrite_method_call(method_name: ast::Ident, let (lo, type_str) = if types.is_empty() { (args[0].span.hi, String::new()) } else { - let type_list: Vec<_> = try_opt!(types - .iter() - .map(|ty| ty.rewrite(context, shape)) - .collect()); + let type_list: Vec<_> = + try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect()); let type_str = if context.config.spaces_within_angle_brackets && type_list.len() > 0 { format!("::< {} >", type_list.join(", ")) diff --git a/src/comment.rs b/src/comment.rs index 3973c7fc048..9df303c86b2 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -99,10 +99,7 @@ pub fn rewrite_comment(orig: &str, config: config, }; - let line_breaks = orig.trim_right() - .chars() - .filter(|&c| c == '\n') - .count(); + let line_breaks = orig.trim_right().chars().filter(|&c| c == '\n').count(); let lines = orig.lines() .enumerate() .map(|(i, mut line)| { diff --git a/src/expr.rs b/src/expr.rs index 2723c4099c1..aa3ab1c41b5 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -594,9 +594,7 @@ 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[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2) { "{}".to_owned() } else { @@ -927,16 +925,12 @@ impl<'a> Rewrite for ControlFlow<'a> { // for event in event let between_kwd_cond = - mk_sp(context - .codemap - .span_after(self.span, self.keyword.trim()), + mk_sp(context.codemap.span_after(self.span, self.keyword.trim()), self.pat .map_or(cond_span.lo, |p| if self.matcher.is_empty() { p.span.lo } else { - context - .codemap - .span_before(self.span, self.matcher.trim()) + context.codemap.span_before(self.span, self.matcher.trim()) })); let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape); @@ -1131,10 +1125,7 @@ fn rewrite_match_arm_comment(context: &RewriteContext, let first = missed_str .find(|c: char| !c.is_whitespace()) .unwrap_or(missed_str.len()); - if missed_str[..first] - .chars() - .filter(|c| c == &'\n') - .count() >= 2 { + if missed_str[..first].chars().filter(|c| c == &'\n').count() >= 2 { // Excessive vertical whitespace before comment should be preserved // FIXME handle vertical whitespace better result.push('\n'); diff --git a/src/imports.rs b/src/imports.rs index 791ff0ee387..f5ecab2a6a2 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -29,10 +29,7 @@ fn path_of(a: &ast::ViewPath_) -> &ast::Path { } fn compare_path_segments(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering { - a.identifier - .name - .as_str() - .cmp(&b.identifier.name.as_str()) + a.identifier.name.as_str().cmp(&b.identifier.name.as_str()) } fn compare_paths(a: &ast::Path, b: &ast::Path) -> Ordering { diff --git a/src/items.rs b/src/items.rs index 2cb4e46ecb5..9ab551ddccc 100644 --- a/src/items.rs +++ b/src/items.rs @@ -242,9 +242,7 @@ impl<'a> FmtVisitor<'a> { let context = self.get_context(); let block_snippet = self.snippet(codemap::mk_sp(block.span.lo, block.span.hi)); - let has_body = !block_snippet[1..block_snippet.len() - 1] - .trim() - .is_empty() || + let has_body = !block_snippet[1..block_snippet.len() - 1].trim().is_empty() || !context.config.fn_empty_single_line; let (mut result, force_newline_brace) = try_opt!(rewrite_fn_base(&context, @@ -1227,10 +1225,7 @@ impl Rewrite for ast::StructField { let type_offset = shape.indent.block_indent(context.config); let rewrite_type_in_next_line = || { - let budget = try_opt!(context - .config - .max_width - .checked_sub(type_offset.width())); + let budget = try_opt!(context.config.max_width.checked_sub(type_offset.width())); self.ty .rewrite(context, Shape::legacy(budget, type_offset)) }; @@ -1624,9 +1619,7 @@ fn rewrite_fn_base(context: &RewriteContext, .ty_params .last() .map_or(span.lo, |tp| end_typaram(tp)); - let args_span = mk_sp(context - .codemap - .span_after(mk_sp(args_start, span.hi), "("), + let args_span = mk_sp(context.codemap.span_after(mk_sp(args_start, span.hi), "("), span_for_return(&fd.output).lo); let arg_str = try_opt!(rewrite_args(context, &fd.inputs, @@ -1767,10 +1760,7 @@ fn rewrite_fn_base(context: &RewriteContext, } } - let budget = try_opt!(context - .config - .max_width - .checked_sub(indent.block_indent)); + let budget = try_opt!(context.config.max_width.checked_sub(indent.block_indent)); let where_clause_str = try_opt!(rewrite_where_clause(context, where_clause, context.config.fn_brace_style, diff --git a/src/lists.rs b/src/lists.rs index 6b917ff29e6..7933ebab807 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -172,9 +172,7 @@ pub fn definitive_tactic(items: I, tactic: ListTactic, width: usize) -> De let real_total = total_width + total_sep_len; if real_total <= limit && !pre_line_comments && - !items - .into_iter() - .any(|item| item.as_ref().is_multiline()) { + !items.into_iter().any(|item| item.as_ref().is_multiline()) { DefinitiveListTactic::Horizontal } else { DefinitiveListTactic::Vertical @@ -536,10 +534,7 @@ pub fn struct_lit_shape(shape: Shape, IndentStyle::Block => { let shape = shape.block_indent(context.config.tab_spaces); Shape { - width: try_opt!(context - .config - .max_width - .checked_sub(shape.indent.width())), + width: try_opt!(context.config.max_width.checked_sub(shape.indent.width())), ..shape } } @@ -556,12 +551,7 @@ pub fn struct_lit_tactic(h_shape: Option, if let Some(h_shape) = h_shape { let mut prelim_tactic = match (context.config.struct_lit_style, items.len()) { (IndentStyle::Visual, 1) => ListTactic::HorizontalVertical, - _ => { - context - .config - .struct_lit_multiline_style - .to_list_tactic() - } + _ => context.config.struct_lit_multiline_style.to_list_tactic(), }; if prelim_tactic == ListTactic::HorizontalVertical && items.len() > 1 { diff --git a/src/macros.rs b/src/macros.rs index fd5578e7f00..f7f6eb19727 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -196,15 +196,9 @@ pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option MacroStyle { let snippet = context.snippet(mac.span); - let paren_pos = snippet - .find_uncommented("(") - .unwrap_or(usize::max_value()); - let bracket_pos = snippet - .find_uncommented("[") - .unwrap_or(usize::max_value()); - let brace_pos = snippet - .find_uncommented("{") - .unwrap_or(usize::max_value()); + let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value()); + let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value()); + let brace_pos = snippet.find_uncommented("{").unwrap_or(usize::max_value()); if paren_pos < bracket_pos && paren_pos < brace_pos { MacroStyle::Parens diff --git a/src/patterns.rs b/src/patterns.rs index bc5c917dc00..8821b7c9146 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -100,10 +100,8 @@ impl Rewrite for Pat { let suffix = suffix.iter().map(|p| p.rewrite(context, shape)); // Munge them together. - let pats: Option> = prefix - .chain(slice_pat.into_iter()) - .chain(suffix) - .collect(); + let pats: Option> = + prefix.chain(slice_pat.into_iter()).chain(suffix).collect(); // Check that all the rewrites succeeded, and if not return None. let pats = try_opt!(pats); @@ -242,9 +240,7 @@ fn rewrite_tuple_pat(pats: &[ptr::P], context: &RewriteContext, shape: Shape) -> Option { - let mut pat_vec: Vec<_> = pats.into_iter() - .map(|x| TuplePatField::Pat(x)) - .collect(); + let mut pat_vec: Vec<_> = pats.into_iter().map(|x| TuplePatField::Pat(x)).collect(); if let Some(pos) = dotdot_pos { let prev = if pos == 0 { diff --git a/tests/system.rs b/tests/system.rs index 0d7c47feb32..5b128aa6b35 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -28,9 +28,7 @@ const DIFF_CONTEXT_SIZE: usize = 3; fn get_path_string(dir_entry: io::Result) -> String { let path = dir_entry.expect("Couldn't get DirEntry").path(); - path.to_str() - .expect("Couldn't stringify path") - .to_owned() + path.to_str().expect("Couldn't stringify path").to_owned() } // Integration tests. The files in the tests/source are formatted and compared @@ -337,8 +335,7 @@ fn handle_result(result: HashMap, let mut f = fs::File::open(&target).expect("Couldn't open target"); let mut text = String::new(); - f.read_to_string(&mut text) - .expect("Failed reading target"); + f.read_to_string(&mut text).expect("Failed reading target"); if fmt_text != text { let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE); diff --git a/tests/target/chains.rs b/tests/target/chains.rs index 1d9b8a08622..2b14ec147d4 100644 --- a/tests/target/chains.rs +++ b/tests/target/chains.rs @@ -137,16 +137,7 @@ fn try_shorthand() { let y = expr.kaas()?.test(); let loooooooooooooooooooooooooooooooooooooooooong = does_this?.look?.good?.should_we_break?.after_the_first_question_mark?; - let yyyy = expr? - .another? - .another? - .another? - .another? - .another? - .another? - .another? - .another? - .test(); + let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test(); let zzzz = expr?.another?.another?.another?.another?; let aaa = x??????????????????????????????????????????????????????????????????????????; diff --git a/tests/target/long_field_access.rs b/tests/target/long_field_access.rs index d47a7d5a13e..349d2c2f639 100644 --- a/tests/target/long_field_access.rs +++ b/tests/target/long_field_access.rs @@ -1,6 +1,4 @@ fn f() { - block_flow - .base - .stacking_relative_position_of_display_port = + block_flow.base.stacking_relative_position_of_display_port = self.base.stacking_relative_position_of_display_port; }