diff options
| author | Seiichi Uchida <seuchida@gmail.com> | 2018-09-19 23:22:26 +0900 |
|---|---|---|
| committer | Seiichi Uchida <seuchida@gmail.com> | 2018-09-19 23:22:26 +0900 |
| commit | e2b9c66cc9d3228339d07cb5410f6cabdac97de8 (patch) | |
| tree | 5b796cfcd88ff2c317b5e1be540f6a58d01851a9 /src | |
| parent | d4f7e219dcd74989f695fe261534cc8fef5b1477 (diff) | |
Cargo fmt
Diffstat (limited to 'src')
| -rw-r--r-- | src/attr.rs | 3 | ||||
| -rw-r--r-- | src/bin/main.rs | 3 | ||||
| -rw-r--r-- | src/cargo-fmt/main.rs | 3 | ||||
| -rw-r--r-- | src/chains.rs | 6 | ||||
| -rw-r--r-- | src/closures.rs | 9 | ||||
| -rw-r--r-- | src/comment.rs | 12 | ||||
| -rw-r--r-- | src/config/file_lines.rs | 3 | ||||
| -rw-r--r-- | src/config/options.rs | 3 | ||||
| -rw-r--r-- | src/expr.rs | 9 | ||||
| -rw-r--r-- | src/formatting.rs | 3 | ||||
| -rw-r--r-- | src/git-rustfmt/main.rs | 3 | ||||
| -rw-r--r-- | src/imports.rs | 12 | ||||
| -rw-r--r-- | src/items.rs | 15 | ||||
| -rw-r--r-- | src/macros.rs | 15 | ||||
| -rw-r--r-- | src/overflow.rs | 15 | ||||
| -rw-r--r-- | src/pairs.rs | 3 | ||||
| -rw-r--r-- | src/patterns.rs | 3 | ||||
| -rw-r--r-- | src/reorder.rs | 6 | ||||
| -rw-r--r-- | src/rustfmt_diff.rs | 3 | ||||
| -rw-r--r-- | src/test/mod.rs | 9 | ||||
| -rw-r--r-- | src/types.rs | 3 | ||||
| -rw-r--r-- | src/vertical.rs | 9 | ||||
| -rw-r--r-- | src/visitor.rs | 3 |
23 files changed, 102 insertions, 51 deletions
diff --git a/src/attr.rs b/src/attr.rs index f8f6cd1c376..aa1517167d8 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -229,7 +229,8 @@ impl Rewrite for ast::MetaItem { None, &inner_meta_item.ident, shape, - ).map_or(false, |s| s.len() + path.len() + 2 <= shape.width), + ) + .map_or(false, |s| s.len() + path.len() + 2 <= shape.width), _ => false, } } diff --git a/src/bin/main.rs b/src/bin/main.rs index 7069733cae1..8676e6290e0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -421,7 +421,8 @@ fn determine_operation(matches: &Matches) -> Result<Operation, ErrorKind> { // we will do comparison later, so here tries to canonicalize first // to get the expected behavior. p.canonicalize().unwrap_or(p) - }).collect(); + }) + .collect(); Ok(Operation::Format { files, diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 1ce5ef2fce8..eee102b6bf8 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -163,7 +163,8 @@ fn format_crate( if verbosity == Verbosity::Verbose { println!("[{}] {:?}", t.kind, t.path) } - }).map(|t| t.path) + }) + .map(|t| t.path) .collect(); run_rustfmt(&files, &rustfmt_args, verbosity) diff --git a/src/chains.rs b/src/chains.rs index 56bd8574fc9..36c89eef20d 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -558,7 +558,8 @@ impl<'a> ChainFormatterShared<'a> { shape.width } else { min(shape.width, context.config.width_heuristics().chain_width) - }.saturating_sub(almost_total); + } + .saturating_sub(almost_total); let all_in_one_line = !self.children.iter().any(ChainItem::is_comment) && self.rewrites.iter().all(|s| !s.contains('\n')) @@ -710,7 +711,8 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { shape.block_indent(0) } else { shape.block_indent(context.config.tab_spaces()) - }.with_max_width(context.config), + } + .with_max_width(context.config), ) } diff --git a/src/closures.rs b/src/closures.rs index 3451fcfe6f4..9546451d7ca 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -198,7 +198,8 @@ fn rewrite_closure_expr( } else { Some(rw) } - }).map(|rw| format!("{} {}", prefix, rw)) + }) + .map(|rw| format!("{} {}", prefix, rw)) } // Rewrite closure whose body is block. @@ -367,8 +368,10 @@ where .map(|e| match e.node { ast::ExprKind::Closure(..) => true, _ => false, - }).unwrap_or(false) - }).count() + }) + .unwrap_or(false) + }) + .count() > 1 } diff --git a/src/comment.rs b/src/comment.rs index 17ec29c3cbc..e79b9011cbf 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -370,7 +370,8 @@ fn rewrite_comment_inner( } line - }).map(|s| left_trim_comment_line(s, &style)) + }) + .map(|s| left_trim_comment_line(s, &style)) .map(|(line, has_leading_whitespace)| { if orig.starts_with("/*") && line_breaks == 0 { ( @@ -542,7 +543,8 @@ fn trim_custom_comment_prefix(s: &str) -> String { } else { line } - }).collect::<Vec<_>>() + }) + .collect::<Vec<_>>() .join("\n") } @@ -630,7 +632,8 @@ fn light_rewrite_comment( }; // Preserve markdown's double-space line break syntax in doc comment. trim_right_unless_two_whitespaces(left_trimmed, is_doc_comment) - }).collect(); + }) + .collect(); Some(lines.join(&format!("\n{}", offset.to_string(config)))) } @@ -1455,7 +1458,8 @@ mod test { .filter_map(|(s, c)| match s { FullCodeCharKind::Normal | FullCodeCharKind::InString => Some(c), _ => None, - }).collect() + }) + .collect() } #[test] diff --git a/src/config/file_lines.rs b/src/config/file_lines.rs index e113118c643..84ab0a8fc07 100644 --- a/src/config/file_lines.rs +++ b/src/config/file_lines.rs @@ -216,7 +216,8 @@ impl FileLines { .map(|(file, range)| JsonSpan { file: file.to_owned(), range: (range.lo, range.hi), - }).collect(), + }) + .collect(), } } diff --git a/src/config/options.rs b/src/config/options.rs index e1aec1ddea9..7dca87e1777 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -394,7 +394,8 @@ impl IgnoreList { path.push(s); path } - }).collect(); + }) + .collect(); } fn skip_file_inner(&self, file: &Path) -> bool { diff --git a/src/expr.rs b/src/expr.rs index a5d1cdd5583..674f719b5c7 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1029,7 +1029,8 @@ impl<'a> Rewrite for ControlFlow<'a> { false, true, mk_sp(else_block.span.lo(), self.span.hi()), - ).rewrite(context, shape) + ) + .rewrite(context, shape) } ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => { ControlFlow::new_if( @@ -1040,7 +1041,8 @@ impl<'a> Rewrite for ControlFlow<'a> { false, true, mk_sp(else_block.span.lo(), self.span.hi()), - ).rewrite(context, shape) + ) + .rewrite(context, shape) } _ => { last_in_chain = true; @@ -1237,7 +1239,8 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt new_indent.to_string(context.config), line.trim_left() ) - }).collect::<Vec<_>>() + }) + .collect::<Vec<_>>() .join("\n") .trim_left(), ); diff --git a/src/formatting.rs b/src/formatting.rs index 90fb5899098..d940c35f1c7 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -240,7 +240,8 @@ impl FormattingError { fl.file .get_line(fl.lines[0].line_index) .map(|l| l.into_owned()) - }).unwrap_or_else(String::new), + }) + .unwrap_or_else(String::new), } } diff --git a/src/git-rustfmt/main.rs b/src/git-rustfmt/main.rs index 0042ff353a7..4ad004d3a8b 100644 --- a/src/git-rustfmt/main.rs +++ b/src/git-rustfmt/main.rs @@ -46,7 +46,8 @@ fn prune_files(files: Vec<&str>) -> Vec<&str> { return true; } pruned_prefixes.iter().all(|pp| !f.starts_with(pp)) - }).collect() + }) + .collect() } fn git_diff(commits: &str) -> String { diff --git a/src/imports.rs b/src/imports.rs index 3ca063a58e7..962d82868d7 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -44,7 +44,8 @@ impl<'a> FmtVisitor<'a> { Some(item.vis.clone()), Some(item.span.lo()), Some(item.attrs.clone()), - ).rewrite_top_level(&self.get_context(), shape); + ) + .rewrite_top_level(&self.get_context(), shape); match rw { Some(ref s) if s.is_empty() => { // Format up to last newline @@ -291,7 +292,8 @@ impl UseTree { } else { Some(item.attrs.clone()) }, - ).normalize(), + ) + .normalize(), ), _ => None, } @@ -345,13 +347,15 @@ impl UseTree { context.snippet_provider.span_after(a.span, "{"), a.span.hi(), false, - ).collect(); + ) + .collect(); result.path.push(UseSegment::List( list.iter() .zip(items.into_iter()) .map(|(t, list_item)| { Self::from_ast(context, &t.0, Some(list_item), None, None, None) - }).collect(), + }) + .collect(), )); } UseTreeKind::Simple(ref rename, ..) => { diff --git a/src/items.rs b/src/items.rs index 44d8889d832..18b43972051 100644 --- a/src/items.rs +++ b/src/items.rs @@ -460,7 +460,8 @@ impl<'a> FmtVisitor<'a> { self.block_indent, mk_sp(span.lo(), body_start), last_line_width(&enum_header), - ).unwrap(); + ) + .unwrap(); self.push_str(&generics_str); self.last_pos = body_start; @@ -517,7 +518,8 @@ impl<'a> FmtVisitor<'a> { body_lo, body_hi, false, - ).collect() + ) + .collect() }; let mut items: Vec<_> = itemize_list_with(self.config.width_heuristics().struct_variant_width); @@ -1705,7 +1707,8 @@ fn rewrite_static( lhs, &**expr, Shape::legacy(remaining_width, offset.block_only()), - ).and_then(|res| recover_comment_removed(res, static_parts.span, context)) + ) + .and_then(|res| recover_comment_removed(res, static_parts.span, context)) .map(|s| if s.ends_with(';') { s } else { s + ";" }) } else { Some(format!("{}{};", prefix, ty_str)) @@ -2233,7 +2236,8 @@ fn rewrite_args( .map(|arg| { arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent)) .unwrap_or_else(|| context.snippet(arg.span()).to_owned()) - }).collect::<Vec<_>>(); + }) + .collect::<Vec<_>>(); // Account for sugary self. // FIXME: the comment for the self argument is dropped. This is blocked @@ -2815,7 +2819,8 @@ impl Rewrite for ast::ForeignItem { span, false, false, - ).map(|(s, _)| format!("{};", s)), + ) + .map(|(s, _)| format!("{};", s)), ast::ForeignItemKind::Static(ref ty, is_mutable) => { // FIXME(#21): we're dropping potential comments in between the // function keywords here. diff --git a/src/macros.rs b/src/macros.rs index 736333cf44d..282519286fa 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -287,7 +287,8 @@ pub fn rewrite_macro_inner( } else { Some(SeparatorTactic::Never) }, - ).map(|rw| match position { + ) + .map(|rw| match position { MacroPosition::Item => format!("{};", rw), _ => rw, }) @@ -418,7 +419,8 @@ pub fn rewrite_macro_def( context.snippet_provider.span_after(span, "{"), span.hi(), false, - ).collect::<Vec<_>>(); + ) + .collect::<Vec<_>>(); let fmt = ListFormatting::new(arm_shape, context.config) .separator(if def.legacy { ";" } else { "" }) @@ -1141,7 +1143,8 @@ fn indent_macro_snippet( FullCodeCharKind::InString | FullCodeCharKind::EndString => None, _ => prefix_space_width, } - }).min()?; + }) + .min()?; Some( first_line + "\n" + &trimmed_lines @@ -1157,7 +1160,8 @@ fn indent_macro_snippet( } None => String::new(), }, - ).collect::<Vec<_>>() + ) + .collect::<Vec<_>>() .join("\n"), ) } @@ -1322,7 +1326,8 @@ impl MacroBranch { } (s + l + "\n", !kind.is_string() || l.ends_with('\\')) }, - ).0; + ) + .0; // Undo our replacement of macro variables. // FIXME: this could be *much* more efficient. diff --git a/src/overflow.rs b/src/overflow.rs index 674eb14b677..acf6d7b4d38 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -52,7 +52,8 @@ where item_max_width, force_separator_tactic, None, - ).rewrite(shape) + ) + .rewrite(shape) } pub fn rewrite_with_angle_brackets<T>( @@ -76,7 +77,8 @@ where context.config.max_width(), None, None, - ).rewrite(shape) + ) + .rewrite(shape) } pub fn rewrite_with_square_brackets<T>( @@ -107,7 +109,8 @@ where context.config.width_heuristics().array_width, force_separator_tactic, Some(("[", "]")), - ).rewrite(shape) + ) + .rewrite(shape) } struct Context<'a, T: 'a> { @@ -242,7 +245,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> { list_items, self.one_line_shape, self.item_max_width, - ).and_then(|arg_shape| { + ) + .and_then(|arg_shape| { self.rewrite_last_item_with_overflow( &mut list_items[self.items.len() - 1], arg_shape, @@ -495,7 +499,8 @@ where Shape { width: min(args_max_width, shape.width), ..shape - }.offset_left(offset) + } + .offset_left(offset) } fn shape_from_indent_style( diff --git a/src/pairs.rs b/src/pairs.rs index 17b86975022..f078022b9e0 100644 --- a/src/pairs.rs +++ b/src/pairs.rs @@ -124,7 +124,8 @@ fn rewrite_pairs_multiline<T: Rewrite>( let nested_shape = (match context.config.indent_style() { IndentStyle::Visual => shape.visual_indent(0), IndentStyle::Block => shape.block_indent(context.config.tab_spaces()), - }).with_max_width(&context.config) + }) + .with_max_width(&context.config) .sub_width(rhs_offset)?; let indent_str = nested_shape.indent.to_string_with_newline(context.config); diff --git a/src/patterns.rs b/src/patterns.rs index d5c4802904b..13fea046aaf 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -397,7 +397,8 @@ fn count_wildcard_suffix_len( context.snippet_provider.span_after(span, "("), span.hi() - BytePos(1), false, - ).collect(); + ) + .collect(); for item in items.iter().rev().take_while(|i| match i.item { Some(ref internal_string) if internal_string == "_" => true, diff --git a/src/reorder.rs b/src/reorder.rs index 47aae3bfc2a..f990e686565 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -140,7 +140,8 @@ fn rewrite_reorderable_items( .map(|use_tree| ListItem { item: use_tree.rewrite_top_level(context, nested_shape), ..use_tree.list_item.unwrap_or_else(ListItem::empty) - }).collect(); + }) + .collect(); wrap_reorderable_items(context, &item_vec, nested_shape) } @@ -237,7 +238,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { last = current; in_same_group }) - }).count(); + }) + .count(); let items = &items[..item_length]; let at_least_one_in_file_lines = items diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs index 4e0ac31e312..dbe1c05406a 100644 --- a/src/rustfmt_diff.rs +++ b/src/rustfmt_diff.rs @@ -207,7 +207,8 @@ where out, "{} {} {}", mismatch.line_number_orig, num_removed, num_added - ).unwrap(); + ) + .unwrap(); for line in mismatch.lines { match line { diff --git a/src/test/mod.rs b/src/test/mod.rs index f7848dfd737..a9015cedf6a 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -514,7 +514,8 @@ fn read_significant_comments(file_name: &Path) -> HashMap<String, String> { .to_owned(), ) }) - }).collect() + }) + .collect() } // Compare output to input. @@ -882,7 +883,8 @@ fn configuration_snippet_tests() { let mut file_iter = BufReader::new( fs::File::open(Path::new(CONFIGURATIONS_FILE_NAME)) .expect(&format!("Couldn't read file {}", CONFIGURATIONS_FILE_NAME)), - ).lines() + ) + .lines() .map(|l| l.unwrap()) .enumerate(); let mut code_blocks: Vec<ConfigCodeBlock> = Vec::new(); @@ -970,6 +972,7 @@ fn verify_check_works() { rustfmt().to_str().unwrap(), "--check", temp_file.path.to_str().unwrap(), - ]).succeeds() + ]) + .succeeds() .unwrap(); } diff --git a/src/types.rs b/src/types.rs index 07794030ba8..5f71dd6bdc4 100644 --- a/src/types.rs +++ b/src/types.rs @@ -844,7 +844,8 @@ fn rewrite_lifetime_param( .filter(|p| match p.kind { ast::GenericParamKind::Lifetime => true, _ => false, - }).map(|lt| lt.rewrite(context, shape)) + }) + .map(|lt| lt.rewrite(context, shape)) .collect::<Option<Vec<_>>>()? .join(", "); if result.is_empty() { diff --git a/src/vertical.rs b/src/vertical.rs index 3f533920106..d18fa4b9b75 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -200,12 +200,14 @@ fn struct_field_prefix_max_min_width<T: AlignedItem>( Some(field_str.len()) } }) - }).fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) { + }) + .fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) { (Some((max_len, min_len)), Some(len)) => { Some((cmp::max(max_len, len), cmp::min(min_len, len))) } _ => None, - }).unwrap_or((0, 0)) + }) + .unwrap_or((0, 0)) } fn rewrite_aligned_items_inner<T: AlignedItem>( @@ -236,7 +238,8 @@ fn rewrite_aligned_items_inner<T: AlignedItem>( span.lo(), span.hi(), false, - ).collect::<Vec<_>>(); + ) + .collect::<Vec<_>>(); let tactic = definitive_tactic( &items, diff --git a/src/visitor.rs b/src/visitor.rs index f27a399beed..ba87efb5052 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -158,7 +158,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { item.attrs.first() } else { first_stmt.attrs().first() - }.and_then(|attr| { + } + .and_then(|attr| { // Some stmts can have embedded attributes. // e.g. `match { #![attr] ... }` let attr_lo = attr.span.lo(); |
