Cargo fmt
This commit is contained in:
parent
af663d8f62
commit
8b53d7806c
6 changed files with 17 additions and 36 deletions
|
@ -87,9 +87,10 @@ impl CliOptions {
|
||||||
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
|
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
|
||||||
options.write_mode = Some(write_mode);
|
options.write_mode = Some(write_mode);
|
||||||
} else {
|
} else {
|
||||||
return Err(FmtError::from(
|
return Err(FmtError::from(format!(
|
||||||
format!("Invalid write-mode: {}", write_mode),
|
"Invalid write-mode: {}",
|
||||||
));
|
write_mode
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,9 +147,8 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
|
||||||
let last_subexpr = &subexpr_list[suffix_try_num];
|
let last_subexpr = &subexpr_list[suffix_try_num];
|
||||||
let subexpr_list = &subexpr_list[suffix_try_num..subexpr_num - prefix_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 iter = subexpr_list.iter().skip(1).rev().zip(child_shape_iter);
|
||||||
let mut rewrites = iter.map(|(e, shape)| {
|
let mut rewrites = iter.map(|(e, shape)| rewrite_chain_subexpr(e, total_span, context, shape))
|
||||||
rewrite_chain_subexpr(e, total_span, context, shape)
|
.collect::<Option<Vec<_>>>()?;
|
||||||
}).collect::<Option<Vec<_>>>()?;
|
|
||||||
|
|
||||||
// Total of all items excluding the last.
|
// Total of all items excluding the last.
|
||||||
let extend_last_subexpr = last_line_extendable(&parent_rewrite) && rewrites.is_empty();
|
let extend_last_subexpr = last_line_extendable(&parent_rewrite) && rewrites.is_empty();
|
||||||
|
|
|
@ -224,9 +224,7 @@ pub fn rewrite_comment(
|
||||||
// we should stop now.
|
// we should stop now.
|
||||||
let num_bare_lines = orig.lines()
|
let num_bare_lines = orig.lines()
|
||||||
.map(|line| line.trim())
|
.map(|line| line.trim())
|
||||||
.filter(|l| {
|
.filter(|l| !(l.starts_with('*') || l.starts_with("//") || l.starts_with("/*")))
|
||||||
!(l.starts_with('*') || l.starts_with("//") || l.starts_with("/*"))
|
|
||||||
})
|
|
||||||
.count();
|
.count();
|
||||||
if num_bare_lines > 0 && !config.normalize_comments() {
|
if num_bare_lines > 0 && !config.normalize_comments() {
|
||||||
return Some(orig.to_owned());
|
return Some(orig.to_owned());
|
||||||
|
|
|
@ -292,9 +292,7 @@ pub fn format_expr(
|
||||||
};
|
};
|
||||||
|
|
||||||
expr_rw
|
expr_rw
|
||||||
.and_then(|expr_str| {
|
.and_then(|expr_str| recover_comment_removed(expr_str, expr.span, context))
|
||||||
recover_comment_removed(expr_str, expr.span, context)
|
|
||||||
})
|
|
||||||
.and_then(|expr_str| {
|
.and_then(|expr_str| {
|
||||||
let attrs = outer_attributes(&expr.attrs);
|
let attrs = outer_attributes(&expr.attrs);
|
||||||
let attrs_str = attrs.rewrite(context, shape)?;
|
let attrs_str = attrs.rewrite(context, shape)?;
|
||||||
|
@ -1925,9 +1923,7 @@ where
|
||||||
config: context.config,
|
config: context.config,
|
||||||
};
|
};
|
||||||
|
|
||||||
write_list(&item_vec, &fmt).map(|args_str| {
|
write_list(&item_vec, &fmt).map(|args_str| (tactic != DefinitiveListTactic::Vertical, args_str))
|
||||||
(tactic != DefinitiveListTactic::Vertical, args_str)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_overflow_last_arg<'a, T>(
|
fn try_overflow_last_arg<'a, T>(
|
||||||
|
|
20
src/items.rs
20
src/items.rs
|
@ -817,8 +817,7 @@ fn format_impl_ref_and_type(
|
||||||
IndentStyle::Visual => new_line_offset + trait_ref_overhead,
|
IndentStyle::Visual => new_line_offset + trait_ref_overhead,
|
||||||
IndentStyle::Block => new_line_offset,
|
IndentStyle::Block => new_line_offset,
|
||||||
};
|
};
|
||||||
result.push_str(&*self_ty
|
result.push_str(&*self_ty.rewrite(context, Shape::legacy(budget, type_offset))?);
|
||||||
.rewrite(context, Shape::legacy(budget, type_offset))?);
|
|
||||||
Some(result)
|
Some(result)
|
||||||
} else {
|
} else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
@ -1578,9 +1577,7 @@ fn rewrite_static(
|
||||||
lhs,
|
lhs,
|
||||||
&**expr,
|
&**expr,
|
||||||
Shape::legacy(remaining_width, offset.block_only()),
|
Shape::legacy(remaining_width, offset.block_only()),
|
||||||
).and_then(|res| {
|
).and_then(|res| recover_comment_removed(res, static_parts.span, context))
|
||||||
recover_comment_removed(res, static_parts.span, context)
|
|
||||||
})
|
|
||||||
.map(|s| if s.ends_with(';') { s } else { s + ";" })
|
.map(|s| if s.ends_with(';') { s } else { s + ";" })
|
||||||
} else {
|
} else {
|
||||||
Some(format!("{}{};", prefix, ty_str))
|
Some(format!("{}{};", prefix, ty_str))
|
||||||
|
@ -2096,18 +2093,14 @@ fn rewrite_args(
|
||||||
generics_str_contains_newline: bool,
|
generics_str_contains_newline: bool,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let mut arg_item_strs = args.iter()
|
let mut arg_item_strs = args.iter()
|
||||||
.map(|arg| {
|
.map(|arg| arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent)))
|
||||||
arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent))
|
|
||||||
})
|
|
||||||
.collect::<Option<Vec<_>>>()?;
|
.collect::<Option<Vec<_>>>()?;
|
||||||
|
|
||||||
// Account for sugary self.
|
// Account for sugary self.
|
||||||
// FIXME: the comment for the self argument is dropped. This is blocked
|
// FIXME: the comment for the self argument is dropped. This is blocked
|
||||||
// on rust issue #27522.
|
// on rust issue #27522.
|
||||||
let min_args = explicit_self
|
let min_args = explicit_self
|
||||||
.and_then(|explicit_self| {
|
.and_then(|explicit_self| rewrite_explicit_self(explicit_self, args, context))
|
||||||
rewrite_explicit_self(explicit_self, args, context)
|
|
||||||
})
|
|
||||||
.map_or(1, |self_str| {
|
.map_or(1, |self_str| {
|
||||||
arg_item_strs[0] = self_str;
|
arg_item_strs[0] = self_str;
|
||||||
2
|
2
|
||||||
|
@ -2326,9 +2319,8 @@ fn rewrite_generics(
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let g_shape = generics_shape_from_config(context.config, shape, 0)?;
|
let g_shape = generics_shape_from_config(context.config, shape, 0)?;
|
||||||
let one_line_width = shape.width.checked_sub(2).unwrap_or(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, one_line_width, span)
|
||||||
rewrite_generics_inner(context, generics, g_shape, 0, span)
|
.or_else(|| rewrite_generics_inner(context, generics, g_shape, 0, span))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rewrite_generics_inner(
|
fn rewrite_generics_inner(
|
||||||
|
|
|
@ -109,9 +109,7 @@ impl<'a> FmtVisitor<'a> {
|
||||||
if self.config.remove_blank_lines_at_start_or_end_of_block() {
|
if self.config.remove_blank_lines_at_start_or_end_of_block() {
|
||||||
if let Some(first_stmt) = b.stmts.first() {
|
if let Some(first_stmt) = b.stmts.first() {
|
||||||
let attr_lo = inner_attrs
|
let attr_lo = inner_attrs
|
||||||
.and_then(|attrs| {
|
.and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
|
||||||
inner_attributes(attrs).first().map(|attr| attr.span.lo())
|
|
||||||
})
|
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
// Attributes for an item in a statement position
|
// Attributes for an item in a statement position
|
||||||
// do not belong to the statement. (rust-lang/rust#34459)
|
// do not belong to the statement. (rust-lang/rust#34459)
|
||||||
|
@ -872,10 +870,7 @@ fn rewrite_first_group_attrs(
|
||||||
for derive in derives {
|
for derive in derives {
|
||||||
derive_args.append(&mut get_derive_args(context, derive)?);
|
derive_args.append(&mut get_derive_args(context, derive)?);
|
||||||
}
|
}
|
||||||
return Some((
|
return Some((derives.len(), format_derive(context, &derive_args, shape)?));
|
||||||
derives.len(),
|
|
||||||
format_derive(context, &derive_args, shape)?,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Rewrite the first attribute.
|
// Rewrite the first attribute.
|
||||||
|
|
Loading…
Reference in a new issue