mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Cargo fmt
This commit is contained in:
parent
d4f7e219dc
commit
e2b9c66cc9
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
|
@ -216,7 +216,8 @@ impl FileLines {
|
||||
.map(|(file, range)| JsonSpan {
|
||||
file: file.to_owned(),
|
||||
range: (range.lo, range.hi),
|
||||
}).collect(),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,8 @@ impl IgnoreList {
|
||||
path.push(s);
|
||||
path
|
||||
}
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn skip_file_inner(&self, file: &Path) -> bool {
|
||||
|
@ -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(),
|
||||
);
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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, ..) => {
|
||||
|
15
src/items.rs
15
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.
|
||||
|
@ -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.
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -207,7 +207,8 @@ where
|
||||
out,
|
||||
"{} {} {}",
|
||||
mismatch.line_number_orig, num_removed, num_added
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for line in mismatch.lines {
|
||||
match line {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user