Format source codes and update tests

This commit is contained in:
Seiichi Uchida 2017-07-20 00:35:00 +09:00
parent 28e32ce898
commit a8b0a6e4c5
10 changed files with 31 additions and 38 deletions

View File

@ -1428,7 +1428,7 @@ fn block_contains_comment(block: &ast::Block, codemap: &CodeMap) -> bool {
// the expression.
pub fn is_simple_block(block: &ast::Block, codemap: &CodeMap) -> bool {
(block.stmts.len() == 1 && stmt_is_expr(&block.stmts[0]) &&
!block_contains_comment(block, codemap))
!block_contains_comment(block, codemap))
}
/// Checks whether a block contains at most one statement or expression, and no comments.
@ -1770,7 +1770,7 @@ fn rewrite_match_body(
Some(ref body_str)
if !forbid_same_line &&
(is_block ||
(!body_str.contains('\n') && body_str.len() <= body_shape.width)) =>
(!body_str.contains('\n') && body_str.len() <= body_shape.width)) =>
{
return combine_orig_body(body_str);
}
@ -2375,7 +2375,7 @@ pub fn wrap_args_with_parens(
) -> String {
if !context.use_block_indent() ||
(context.inside_macro && !args_str.contains('\n') &&
args_str.len() + paren_overhead(context) <= shape.width) || is_extendable
args_str.len() + paren_overhead(context) <= shape.width) || is_extendable
{
if context.config.spaces_within_parens() && args_str.len() > 0 {
format!("( {} )", args_str)
@ -2605,8 +2605,8 @@ pub fn wrap_struct_field(
) -> String {
if context.config.struct_lit_style() == IndentStyle::Block &&
(fields_str.contains('\n') ||
context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti ||
fields_str.len() > one_line_width)
context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti ||
fields_str.len() > one_line_width)
{
format!(
"\n{}{}\n{}",

View File

@ -942,11 +942,10 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
let has_body = !trait_items.is_empty();
let where_density = if (context.config.where_density() == Density::Compressed &&
(!result.contains('\n') ||
context.config.fn_args_layout() == IndentStyle::Block)) ||
(!result.contains('\n') || context.config.fn_args_layout() == IndentStyle::Block)) ||
(context.config.fn_args_layout() == IndentStyle::Block && result.is_empty()) ||
(context.config.where_density() == Density::CompressedIfEmpty && !has_body &&
!result.contains('\n'))
!result.contains('\n'))
{
Density::Compressed
} else {
@ -1079,7 +1078,7 @@ pub fn format_struct_struct(
// 3 = ` {}`, 2 = ` {`.
let overhead = if fields.is_empty() { 3 } else { 2 };
if (context.config.item_brace_style() == BraceStyle::AlwaysNextLine &&
!fields.is_empty()) ||
!fields.is_empty()) ||
context
.config
.max_width()
@ -1247,8 +1246,8 @@ fn format_tuple_struct(
if !where_clause_str.is_empty() && !where_clause_str.contains('\n') &&
(result.contains('\n') ||
offset.block_indent + result.len() + where_clause_str.len() + 1 >
context.config.max_width())
offset.block_indent + result.len() + where_clause_str.len() + 1 >
context.config.max_width())
{
// We need to put the where clause on a new line, but we didn't
// know that earlier, so the where clause will not be indented properly.

View File

@ -368,7 +368,7 @@ where
let inner_item_width = item.inner_as_ref().len();
if !first &&
(item.is_multiline() || !item.post_comment.is_some() ||
inner_item_width + overhead > max_budget)
inner_item_width + overhead > max_budget)
{
return max_width;
}

View File

@ -83,7 +83,7 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
if cur_end < cur_start + MIN_STRING {
cur_end = cur_start + max_chars;
while !(punctuation.contains(graphemes[cur_end - 1]) ||
graphemes[cur_end - 1].trim().is_empty())
graphemes[cur_end - 1].trim().is_empty())
{
if cur_end >= graphemes.len() {
let line = &graphemes[cur_start..].join("");

View File

@ -54,7 +54,7 @@ impl Summary {
pub fn has_no_errors(&self) -> bool {
!(self.has_operational_errors || self.has_parsing_errors || self.has_formatting_errors ||
self.has_diff)
self.has_diff)
}
pub fn add(&mut self, other: Summary) {

View File

@ -632,12 +632,12 @@ impl<'a> FmtVisitor<'a> {
.take_while(|ppi| {
is_use_item(&***ppi) &&
(!reorder_imports_in_group ||
{
let current = self.codemap.lookup_line_range(item_bound(&ppi));
let in_same_group = current.lo < last.hi + 2;
last = current;
in_same_group
})
{
let current = self.codemap.lookup_line_range(item_bound(&ppi));
let in_same_group = current.lo < last.hi + 2;
last = current;
in_same_group
})
})
.count();
let (use_items, rest) = items_left.split_at(use_item_length);

View File

@ -240,15 +240,9 @@ fn read_config(filename: &str) -> Config {
fn format_file<P: Into<PathBuf>>(filepath: P, config: &Config) -> (FileMap, FormatReport) {
let filepath = filepath.into();
let display_path = filepath.display().to_string();
let input = Input::File(filepath);
let (error_summary, file_map, report) =
let (_error_summary, file_map, report) =
format_input::<io::Stdout>(input, &config, None).unwrap();
assert!(
error_summary.has_no_errors(),
"Encountered errors formatting {}",
display_path
);
return (file_map, report);
}

View File

@ -5,9 +5,9 @@ fn main() {
loop {
if foo {
if ((right_paddle_speed < 0.) &&
(right_paddle.position().y - paddle_size.y / 2. > 5.)) ||
(right_paddle.position().y - paddle_size.y / 2. > 5.)) ||
((right_paddle_speed > 0.) &&
(right_paddle.position().y + paddle_size.y / 2. < game_height as f32 - 5.))
(right_paddle.position().y + paddle_size.y / 2. < game_height as f32 - 5.))
{
foo
}

View File

@ -21,9 +21,9 @@ fn foo() -> bool {
trivial_value,
);
(((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
a +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaa)))))))));
a +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaa)))))))));
{
for _ in 0..10 {}
@ -263,9 +263,9 @@ fn returns() {
fn addrof() {
&mut (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
&(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
}
fn casts() {

View File

@ -72,10 +72,10 @@ fn main() {
vec![
a;
(|x| {
let y = x + 1;
let z = y + 1;
z
})(2)
let y = x + 1;
let z = y + 1;
z
})(2)
];
vec![
a;