Format source codes
This commit is contained in:
parent
f2ec5a7bac
commit
77a2e9858b
4
build.rs
4
build.rs
@ -16,11 +16,11 @@ fn main() {
|
||||
writeln!(f,
|
||||
"const COMMIT_HASH: Option<&'static str> = {:?};",
|
||||
git_head_sha1())
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
writeln!(f,
|
||||
"const WORKTREE_CLEAN: Option<bool> = {:?};",
|
||||
git_tree_is_clean())
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
|
||||
// cargo:rerun-if-changed requires one entry per individual file.
|
||||
for entry in WalkDir::new("src") {
|
||||
|
14
src/expr.rs
14
src/expr.rs
@ -120,7 +120,7 @@ fn format_expr(expr: &ast::Expr,
|
||||
expr_type == ExprType::SubExpression,
|
||||
false,
|
||||
expr.span)
|
||||
.rewrite(context, shape)
|
||||
.rewrite(context, shape)
|
||||
}
|
||||
ast::ExprKind::IfLet(ref pat, ref cond, ref if_block, ref else_block) => {
|
||||
ControlFlow::new_if(cond,
|
||||
@ -130,7 +130,7 @@ fn format_expr(expr: &ast::Expr,
|
||||
expr_type == ExprType::SubExpression,
|
||||
false,
|
||||
expr.span)
|
||||
.rewrite(context, shape)
|
||||
.rewrite(context, shape)
|
||||
}
|
||||
ast::ExprKind::Match(ref cond, ref arms) => {
|
||||
rewrite_match(context, cond, arms, shape, expr.span)
|
||||
@ -372,7 +372,7 @@ pub fn rewrite_array<'a, I>(expr_iter: I,
|
||||
|item| item.rewrite(context, nested_shape),
|
||||
span.lo,
|
||||
span.hi)
|
||||
.collect::<Vec<_>>();
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if items.is_empty() {
|
||||
if context.config.spaces_within_square_brackets() {
|
||||
@ -716,7 +716,7 @@ impl Rewrite for ast::Stmt {
|
||||
},
|
||||
context,
|
||||
try_opt!(shape.sub_width(suffix.len())))
|
||||
.map(|s| s + suffix)
|
||||
.map(|s| s + suffix)
|
||||
}
|
||||
ast::StmtKind::Mac(..) |
|
||||
ast::StmtKind::Item(..) => None,
|
||||
@ -1012,7 +1012,7 @@ 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(cond,
|
||||
@ -1022,7 +1022,7 @@ 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;
|
||||
@ -1065,7 +1065,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
||||
.as_ref()
|
||||
.map_or(between_sep, |s| &**s),
|
||||
after_else_comment.as_ref().map_or(after_sep, |s| &**s))
|
||||
.ok());
|
||||
.ok());
|
||||
result.push_str(&try_opt!(rewrite));
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
let suffix = if semicolon_for_expr(e) { ";" } else { "" };
|
||||
|
||||
e.rewrite(&self.get_context(),
|
||||
Shape::indented(self.block_indent, self.config))
|
||||
Shape::indented(self.block_indent, self.config))
|
||||
.map(|s| s + suffix)
|
||||
.or_else(|| Some(self.snippet(e.span)))
|
||||
}
|
||||
@ -376,7 +376,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
enum_def.variants.is_empty(),
|
||||
self.block_indent,
|
||||
mk_sp(span.lo, body_start))
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
self.buffer.push_str(&generics_str);
|
||||
|
||||
self.last_pos = body_start;
|
||||
@ -941,7 +941,7 @@ fn format_struct_struct(context: &RewriteContext,
|
||||
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
|
||||
context.codemap.span_after(span, "{"),
|
||||
span.hi)
|
||||
.collect::<Vec<_>>();
|
||||
.collect::<Vec<_>>();
|
||||
// 1 = ,
|
||||
let budget = context.config.max_width() - offset.width() + context.config.tab_spaces() - 1;
|
||||
|
||||
@ -1295,7 +1295,7 @@ pub fn rewrite_static(prefix: &str,
|
||||
lhs,
|
||||
expr,
|
||||
Shape::legacy(remaining_width, offset.block_only()))
|
||||
.map(|s| s + ";")
|
||||
.map(|s| s + ";")
|
||||
} else {
|
||||
let lhs = format!("{}{};", prefix, ty_str);
|
||||
Some(lhs)
|
||||
|
@ -266,7 +266,8 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
|
||||
// Post-comments
|
||||
if tactic != DefinitiveListTactic::Vertical && item.post_comment.is_some() {
|
||||
let comment = item.post_comment.as_ref().unwrap();
|
||||
let formatted_comment = try_opt!(rewrite_comment(comment,
|
||||
let formatted_comment =
|
||||
try_opt!(rewrite_comment(comment,
|
||||
true,
|
||||
Shape::legacy(formatting.shape.width, Indent::empty()),
|
||||
formatting.config));
|
||||
|
@ -163,7 +163,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
Shape::legacy(comment_width,
|
||||
self.block_indent),
|
||||
self.config)
|
||||
.unwrap());
|
||||
.unwrap());
|
||||
|
||||
last_wspace = None;
|
||||
line_start = offset + subslice.len();
|
||||
|
@ -293,7 +293,7 @@ fn rewrite_tuple_pat(pats: &[ptr::P<ast::Pat>],
|
||||
|item| item.rewrite(context, nested_shape),
|
||||
context.codemap.span_after(span, "("),
|
||||
span.hi - BytePos(1))
|
||||
.collect();
|
||||
.collect();
|
||||
|
||||
// Condense wildcard string suffix into a single ..
|
||||
let wildcard_suffix_len = count_wildcard_suffix_len(&items);
|
||||
|
42
src/types.rs
42
src/types.rs
@ -364,7 +364,9 @@ impl Rewrite for ast::WherePredicate {
|
||||
let colon = type_bound_colon(context);
|
||||
|
||||
if !bound_lifetimes.is_empty() {
|
||||
let lifetime_str: String = try_opt!(bound_lifetimes.iter()
|
||||
let lifetime_str: String =
|
||||
try_opt!(bound_lifetimes
|
||||
.iter()
|
||||
.map(|lt| lt.rewrite(context, shape))
|
||||
.intersperse(Some(", ".to_string()))
|
||||
.collect());
|
||||
@ -376,14 +378,17 @@ impl Rewrite for ast::WherePredicate {
|
||||
// 6 = "for<> ".len()
|
||||
let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
|
||||
let budget = try_opt!(shape.width.checked_sub(used_width));
|
||||
let bounds_str: String = try_opt!(bounds.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context,
|
||||
Shape::legacy(budget,
|
||||
shape.indent + used_width))
|
||||
})
|
||||
.intersperse(Some(joiner.to_string()))
|
||||
.collect());
|
||||
let bounds_str: String =
|
||||
try_opt!(bounds
|
||||
.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context,
|
||||
Shape::legacy(budget,
|
||||
shape.indent +
|
||||
used_width))
|
||||
})
|
||||
.intersperse(Some(joiner.to_string()))
|
||||
.collect());
|
||||
|
||||
if context.config.spaces_within_angle_brackets() && lifetime_str.len() > 0 {
|
||||
format!("for< {} > {}{}{}",
|
||||
@ -401,14 +406,17 @@ impl Rewrite for ast::WherePredicate {
|
||||
};
|
||||
let used_width = type_str.len() + colon.len();
|
||||
let budget = try_opt!(shape.width.checked_sub(used_width));
|
||||
let bounds_str: String = try_opt!(bounds.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context,
|
||||
Shape::legacy(budget,
|
||||
shape.indent + used_width))
|
||||
})
|
||||
.intersperse(Some(joiner.to_string()))
|
||||
.collect());
|
||||
let bounds_str: String =
|
||||
try_opt!(bounds
|
||||
.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context,
|
||||
Shape::legacy(budget,
|
||||
shape.indent +
|
||||
used_width))
|
||||
})
|
||||
.intersperse(Some(joiner.to_string()))
|
||||
.collect());
|
||||
|
||||
format!("{}{}{}", type_str, colon, bounds_str)
|
||||
}
|
||||
|
@ -282,10 +282,10 @@ impl<'a> FmtVisitor<'a> {
|
||||
item.span,
|
||||
indent,
|
||||
None)
|
||||
.map(|s| match *def {
|
||||
ast::VariantData::Tuple(..) => s + ";",
|
||||
_ => s,
|
||||
})
|
||||
.map(|s| match *def {
|
||||
ast::VariantData::Tuple(..) => s + ";",
|
||||
_ => s,
|
||||
})
|
||||
};
|
||||
self.push_rewrite(item.span, rewrite);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user