Cargo fmt

This commit is contained in:
topecongiro 2017-11-29 17:37:51 +09:00
parent af663d8f62
commit 8b53d7806c
6 changed files with 17 additions and 36 deletions

View File

@ -87,9 +87,10 @@ impl CliOptions {
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
options.write_mode = Some(write_mode);
} else {
return Err(FmtError::from(
format!("Invalid write-mode: {}", write_mode),
));
return Err(FmtError::from(format!(
"Invalid write-mode: {}",
write_mode
)));
}
}

View File

@ -147,9 +147,8 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
let last_subexpr = &subexpr_list[suffix_try_num];
let subexpr_list = &subexpr_list[suffix_try_num..subexpr_num - prefix_try_num];
let iter = subexpr_list.iter().skip(1).rev().zip(child_shape_iter);
let mut rewrites = iter.map(|(e, shape)| {
rewrite_chain_subexpr(e, total_span, context, shape)
}).collect::<Option<Vec<_>>>()?;
let mut rewrites = iter.map(|(e, shape)| rewrite_chain_subexpr(e, total_span, context, shape))
.collect::<Option<Vec<_>>>()?;
// Total of all items excluding the last.
let extend_last_subexpr = last_line_extendable(&parent_rewrite) && rewrites.is_empty();

View File

@ -224,9 +224,7 @@ pub fn rewrite_comment(
// we should stop now.
let num_bare_lines = orig.lines()
.map(|line| line.trim())
.filter(|l| {
!(l.starts_with('*') || l.starts_with("//") || l.starts_with("/*"))
})
.filter(|l| !(l.starts_with('*') || l.starts_with("//") || l.starts_with("/*")))
.count();
if num_bare_lines > 0 && !config.normalize_comments() {
return Some(orig.to_owned());

View File

@ -292,9 +292,7 @@ pub fn format_expr(
};
expr_rw
.and_then(|expr_str| {
recover_comment_removed(expr_str, expr.span, context)
})
.and_then(|expr_str| recover_comment_removed(expr_str, expr.span, context))
.and_then(|expr_str| {
let attrs = outer_attributes(&expr.attrs);
let attrs_str = attrs.rewrite(context, shape)?;
@ -1925,9 +1923,7 @@ where
config: context.config,
};
write_list(&item_vec, &fmt).map(|args_str| {
(tactic != DefinitiveListTactic::Vertical, args_str)
})
write_list(&item_vec, &fmt).map(|args_str| (tactic != DefinitiveListTactic::Vertical, args_str))
}
fn try_overflow_last_arg<'a, T>(

View File

@ -817,8 +817,7 @@ fn format_impl_ref_and_type(
IndentStyle::Visual => new_line_offset + trait_ref_overhead,
IndentStyle::Block => new_line_offset,
};
result.push_str(&*self_ty
.rewrite(context, Shape::legacy(budget, type_offset))?);
result.push_str(&*self_ty.rewrite(context, Shape::legacy(budget, type_offset))?);
Some(result)
} else {
unreachable!();
@ -1578,9 +1577,7 @@ 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))
@ -2096,18 +2093,14 @@ fn rewrite_args(
generics_str_contains_newline: bool,
) -> Option<String> {
let mut arg_item_strs = args.iter()
.map(|arg| {
arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent))
})
.map(|arg| arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent)))
.collect::<Option<Vec<_>>>()?;
// Account for sugary self.
// FIXME: the comment for the self argument is dropped. This is blocked
// on rust issue #27522.
let min_args = explicit_self
.and_then(|explicit_self| {
rewrite_explicit_self(explicit_self, args, context)
})
.and_then(|explicit_self| rewrite_explicit_self(explicit_self, args, context))
.map_or(1, |self_str| {
arg_item_strs[0] = self_str;
2
@ -2326,9 +2319,8 @@ fn rewrite_generics(
) -> Option<String> {
let g_shape = generics_shape_from_config(context.config, shape, 0)?;
let one_line_width = shape.width.checked_sub(2).unwrap_or(0);
rewrite_generics_inner(context, generics, g_shape, one_line_width, span).or_else(|| {
rewrite_generics_inner(context, generics, g_shape, 0, span)
})
rewrite_generics_inner(context, generics, g_shape, one_line_width, span)
.or_else(|| rewrite_generics_inner(context, generics, g_shape, 0, span))
}
fn rewrite_generics_inner(

View File

@ -109,9 +109,7 @@ impl<'a> FmtVisitor<'a> {
if self.config.remove_blank_lines_at_start_or_end_of_block() {
if let Some(first_stmt) = b.stmts.first() {
let attr_lo = inner_attrs
.and_then(|attrs| {
inner_attributes(attrs).first().map(|attr| attr.span.lo())
})
.and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
.or_else(|| {
// Attributes for an item in a statement position
// do not belong to the statement. (rust-lang/rust#34459)
@ -872,10 +870,7 @@ fn rewrite_first_group_attrs(
for derive in derives {
derive_args.append(&mut get_derive_args(context, derive)?);
}
return Some((
derives.len(),
format_derive(context, &derive_args, shape)?,
));
return Some((derives.len(), format_derive(context, &derive_args, shape)?));
}
}
// Rewrite the first attribute.