Format source codes and update tests

This commit is contained in:
topecongiro 2017-07-26 16:30:58 +09:00
parent 3884b532b9
commit e523f053a3
7 changed files with 16 additions and 26 deletions

View file

@ -334,8 +334,7 @@ pub fn format_expr(
shape,
),
ast::ExprKind::Catch(ref block) => {
if let rewrite @ Some(_) =
rewrite_single_line_block(context, "do catch ", block, shape)
if let rewrite @ Some(_) = rewrite_single_line_block(context, "do catch ", block, shape)
{
return rewrite;
}
@ -826,8 +825,7 @@ fn rewrite_empty_block(
block: &ast::Block,
shape: Shape,
) -> Option<String> {
if block.stmts.is_empty() && !block_contains_comment(block, context.codemap) &&
shape.width >= 2
if block.stmts.is_empty() && !block_contains_comment(block, context.codemap) && shape.width >= 2
{
return Some("{}".to_owned());
}

View file

@ -2734,9 +2734,7 @@ fn format_generics(
let shape = Shape::legacy(context.budget(used_width + offset.width()), offset);
let mut result = try_opt!(rewrite_generics(context, generics, shape, span));
let same_line_brace = if !generics.where_clause.predicates.is_empty() ||
result.contains('\n')
{
let same_line_brace = if !generics.where_clause.predicates.is_empty() || result.contains('\n') {
let budget = context
.config
.max_width()

View file

@ -44,12 +44,11 @@ pub fn rewrite_path(
) -> Option<String> {
let skip_count = qself.map_or(0, |x| x.position);
let mut result =
if path.is_global() && qself.is_none() && path_context != PathContext::Import {
"::".to_owned()
} else {
String::new()
};
let mut result = if path.is_global() && qself.is_none() && path_context != PathContext::Import {
"::".to_owned()
} else {
String::new()
};
let mut span_lo = path.span.lo;

View file

@ -328,8 +328,7 @@ impl<'a> FmtVisitor<'a> {
}
ast::ItemKind::Trait(..) => {
self.format_missing_with_indent(item.span.lo);
if let Some(trait_str) =
format_trait(&self.get_context(), item, self.block_indent)
if let Some(trait_str) = format_trait(&self.get_context(), item, self.block_indent)
{
self.buffer.push_str(&trait_str);
self.last_pos = source!(self, item.span).hi;

View file

@ -12,8 +12,7 @@ fn main() {
foo
}
if ai_timer.elapsed_time().as_microseconds() > ai_time.as_microseconds() {
if ball.position().y + ball_radius >
right_paddle.position().y + paddle_size.y / 2.
if ball.position().y + ball_radius > right_paddle.position().y + paddle_size.y / 2.
{
foo
}

View file

@ -346,12 +346,10 @@ fn complex_if_else() {
ha();
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
yo();
} else if let Some(x) =
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
} else if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
ha();
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
xxxxxxxxx
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxxx
{
yo();
}

View file

@ -12,9 +12,9 @@ fn main() {
// Just comments
}
'a: while loooooooooooooooooooooooooooooooooong_variable_name + another_value >
some_other_value
{}
'a: while loooooooooooooooooooooooooooooooooong_variable_name + another_value > some_other_value
{
}
while aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb {
}
@ -22,8 +22,7 @@ fn main() {
while aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
}
'b: for xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx in
some_iter(arg1, arg2)
'b: for xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx in some_iter(arg1, arg2)
{
// do smth
}