Skip to content

Commit 1d277df

Browse files
committed
Format source codes and update tests
1 parent 494036c commit 1d277df

11 files changed

+198
-45
lines changed

src/comment.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,15 @@ fn remove_comment_header(comment: &str) -> &str {
821821

822822
#[cfg(test)]
823823
mod test {
824-
use super::{CharClasses, CodeCharKind, FullCodeCharKind, contains_comment, rewrite_comment,
825-
FindUncommented, CommentCodeSlices};
824+
use super::{
825+
CharClasses,
826+
CodeCharKind,
827+
FullCodeCharKind,
828+
contains_comment,
829+
rewrite_comment,
830+
FindUncommented,
831+
CommentCodeSlices,
832+
};
826833
use {Indent, Shape};
827834

828835
#[test]

src/expr.rs

+30-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,37 @@ use std::fmt::Write;
1515
use {Indent, Shape, Spanned};
1616
use codemap::SpanUtils;
1717
use rewrite::{Rewrite, RewriteContext};
18-
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic,
19-
DefinitiveListTactic, definitive_tactic, ListItem, struct_lit_shape,
20-
struct_lit_tactic, shape_for_tactic, struct_lit_formatting};
18+
use lists::{
19+
write_list,
20+
itemize_list,
21+
ListFormatting,
22+
SeparatorTactic,
23+
ListTactic,
24+
DefinitiveListTactic,
25+
definitive_tactic,
26+
ListItem,
27+
struct_lit_shape,
28+
struct_lit_tactic,
29+
shape_for_tactic,
30+
struct_lit_formatting,
31+
};
2132
use string::{StringFormat, rewrite_string};
22-
use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width,
23-
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr,
24-
colon_spaces, contains_skip, mk_sp, last_line_extendable, paren_overhead};
33+
use utils::{
34+
extra_offset,
35+
last_line_width,
36+
wrap_str,
37+
binary_search,
38+
first_line_width,
39+
semicolon_for_stmt,
40+
trimmed_last_line_width,
41+
left_most_sub_expr,
42+
stmt_expr,
43+
colon_spaces,
44+
contains_skip,
45+
mk_sp,
46+
last_line_extendable,
47+
paren_overhead,
48+
};
2549
use visitor::FmtVisitor;
2650
use config::{Config, IndentStyle, MultilineStyle, ControlBraceStyle, Style};
2751
use comment::{FindUncommented, rewrite_comment, contains_comment, recover_comment_removed};

src/items.rs

+33-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,39 @@
1212

1313
use {Indent, Shape, Spanned};
1414
use codemap::SpanUtils;
15-
use utils::{format_mutability, format_visibility, contains_skip, end_typaram, wrap_str,
16-
last_line_width, format_unsafety, trim_newlines, stmt_expr, semicolon_for_expr,
17-
trimmed_last_line_width, colon_spaces, mk_sp};
18-
use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic,
19-
DefinitiveListTactic, ListTactic, definitive_tactic};
20-
use expr::{format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs,
21-
rewrite_call_inner, ExprType};
15+
use utils::{
16+
format_mutability,
17+
format_visibility,
18+
contains_skip,
19+
end_typaram,
20+
wrap_str,
21+
last_line_width,
22+
format_unsafety,
23+
trim_newlines,
24+
stmt_expr,
25+
semicolon_for_expr,
26+
trimmed_last_line_width,
27+
colon_spaces,
28+
mk_sp,
29+
};
30+
use lists::{
31+
write_list,
32+
itemize_list,
33+
ListItem,
34+
ListFormatting,
35+
SeparatorTactic,
36+
DefinitiveListTactic,
37+
ListTactic,
38+
definitive_tactic,
39+
};
40+
use expr::{
41+
format_expr,
42+
is_empty_block,
43+
is_simple_block_stmt,
44+
rewrite_assign_rhs,
45+
rewrite_call_inner,
46+
ExprType,
47+
};
2248
use comment::{FindUncommented, contains_comment, rewrite_comment, recover_comment_removed};
2349
use visitor::FmtVisitor;
2450
use rewrite::{Rewrite, RewriteContext};

src/patterns.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@ use Shape;
1212
use codemap::SpanUtils;
1313
use rewrite::{Rewrite, RewriteContext};
1414
use utils::{wrap_str, format_mutability, mk_sp};
15-
use lists::{DefinitiveListTactic, SeparatorTactic, itemize_list, struct_lit_shape,
16-
struct_lit_tactic, shape_for_tactic, struct_lit_formatting, write_list};
17-
use expr::{rewrite_call_inner, rewrite_unary_prefix, rewrite_pair, can_be_overflowed_expr,
18-
wrap_struct_field};
15+
use lists::{
16+
DefinitiveListTactic,
17+
SeparatorTactic,
18+
itemize_list,
19+
struct_lit_shape,
20+
struct_lit_tactic,
21+
shape_for_tactic,
22+
struct_lit_formatting,
23+
write_list,
24+
};
25+
use expr::{
26+
rewrite_call_inner,
27+
rewrite_unary_prefix,
28+
rewrite_pair,
29+
can_be_overflowed_expr,
30+
wrap_struct_field,
31+
};
1932
use types::{rewrite_path, PathContext};
2033
use super::Spanned;
2134
use comment::FindUncommented;

src/types.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ use syntax::symbol::keywords;
2020
use {Shape, Spanned};
2121
use codemap::SpanUtils;
2222
use items::{format_generics_item_list, generics_shape_from_config};
23-
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic,
24-
definitive_tactic};
23+
use lists::{
24+
write_list,
25+
itemize_list,
26+
ListFormatting,
27+
SeparatorTactic,
28+
ListTactic,
29+
definitive_tactic,
30+
};
2531
use rewrite::{Rewrite, RewriteContext};
2632
use utils::{extra_offset, format_mutability, colon_spaces, wrap_str, mk_sp, last_line_width};
2733
use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple, wrap_args_with_parens};

src/utils.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
use std::borrow::Cow;
1212
use std::cmp::Ordering;
1313

14-
use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind, NestedMetaItem,
15-
NestedMetaItemKind, Path};
14+
use syntax::ast::{
15+
self,
16+
Visibility,
17+
Attribute,
18+
MetaItem,
19+
MetaItemKind,
20+
NestedMetaItem,
21+
NestedMetaItemKind,
22+
Path,
23+
};
1624
use syntax::codemap::{BytePos, Span, NO_EXPANSION};
1725
use syntax::abi;
1826

src/visitor.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ use config::Config;
2525
use rewrite::{Rewrite, RewriteContext};
2626
use comment::rewrite_comment;
2727
use macros::{rewrite_macro, MacroPosition};
28-
use items::{rewrite_static, rewrite_associated_type, rewrite_associated_impl_type,
29-
rewrite_type_alias, format_impl, format_trait};
28+
use items::{
29+
rewrite_static,
30+
rewrite_associated_type,
31+
rewrite_associated_impl_type,
32+
rewrite_type_alias,
33+
format_impl,
34+
format_trait,
35+
};
3036
use lists::{itemize_list, write_list, DefinitiveListTactic, ListFormatting, SeparatorTactic};
3137

3238
fn is_use_item(item: &ast::Item) -> bool {
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
22
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd};
3-
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc,
4-
ddddddddd};
3+
use aaaaaaaaaaaaaaa::{
4+
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
5+
ccccccccccccccccccccccccccccccc,
6+
ddddddddd,
7+
};

tests/target/imports-reorder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-reorder_imported_names: true
33

4-
use path::{self /* self */, /* A */ A, B /* B */, C};
4+
use path::{
5+
self, // self
6+
// A
7+
A,
8+
B, // B
9+
C,
10+
};
511

612
use {Z, aa, ab, ac, b};

tests/target/imports.rs

+35-14
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,36 @@
55

66
// Long import.
77
use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl};
8-
use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA,
9-
ItemB};
10-
use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA,
11-
ItemB};
8+
use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{
9+
ItemA,
10+
ItemB,
11+
};
12+
use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{
13+
ItemA,
14+
ItemB,
15+
};
1216

13-
use list::{// Some item
14-
SomeItem, // Comment
15-
// Another item
16-
AnotherItem, // Another Comment
17-
// Last Item
18-
LastItem};
17+
use list::{
18+
// Some item
19+
SomeItem, // Comment
20+
// Another item
21+
AnotherItem, // Another Comment
22+
// Last Item
23+
LastItem,
24+
};
1925

20-
use test::{/* A */ self /* B */, Other /* C */};
26+
use test::{
27+
// A
28+
self, // B
29+
Other, // C
30+
};
2131

2232
use syntax;
23-
use {/* Pre-comment! */ Foo, Bar /* comment */};
33+
use {
34+
// Pre-comment!
35+
Foo,
36+
Bar, // comment
37+
};
2438
use Foo::{Bar, Baz};
2539
pub use syntax::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath};
2640

@@ -32,8 +46,15 @@ mod Foo {
3246
pub use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl};
3347

3448
mod Foo2 {
35-
pub use syntax::ast::{self, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic,
36-
ItemDefaultImpl};
49+
pub use syntax::ast::{
50+
self,
51+
ItemForeignMod,
52+
ItemImpl,
53+
ItemMac,
54+
ItemMod,
55+
ItemStatic,
56+
ItemDefaultImpl,
57+
};
3758
}
3859
}
3960

tests/target/multiple.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,42 @@ extern crate foo;
1717
extern crate foo;
1818

1919
use std::cell::*;
20-
use std::{self, any, ascii, borrow, boxed, char, borrow, boxed, char, borrow, borrow, boxed, char,
21-
borrow, boxed, char, borrow, boxed, char, borrow, boxed, char, borrow, boxed, char,
22-
borrow, boxed, char, borrow, boxed, char, borrow, boxed, char};
20+
use std::{
21+
self,
22+
any,
23+
ascii,
24+
borrow,
25+
boxed,
26+
char,
27+
borrow,
28+
boxed,
29+
char,
30+
borrow,
31+
borrow,
32+
boxed,
33+
char,
34+
borrow,
35+
boxed,
36+
char,
37+
borrow,
38+
boxed,
39+
char,
40+
borrow,
41+
boxed,
42+
char,
43+
borrow,
44+
boxed,
45+
char,
46+
borrow,
47+
boxed,
48+
char,
49+
borrow,
50+
boxed,
51+
char,
52+
borrow,
53+
boxed,
54+
char,
55+
};
2356

2457
mod doc;
2558
mod other;

0 commit comments

Comments
 (0)