File tree Expand file tree Collapse file tree 5 files changed +163
-3
lines changed Expand file tree Collapse file tree 5 files changed +163
-3
lines changed Original file line number Diff line number Diff line change @@ -1122,12 +1122,24 @@ pub(crate) fn format_trait(
1122
1122
}
1123
1123
}
1124
1124
1125
+ let block_span = mk_sp ( generics. where_clause . span . hi ( ) , item. span . hi ( ) ) ;
1126
+ let snippet = context. snippet ( block_span) ;
1127
+ let open_pos = snippet. find_uncommented ( "{" ) ? + 1 ;
1128
+
1125
1129
match context. config . brace_style ( ) {
1126
1130
_ if last_line_contains_single_line_comment ( & result)
1127
1131
|| last_line_width ( & result) + 2 > context. budget ( offset. width ( ) ) =>
1128
1132
{
1129
1133
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1130
1134
}
1135
+ _ if context. config . empty_item_single_line ( )
1136
+ && trait_items. is_empty ( )
1137
+ && !result. contains ( '\n' )
1138
+ && !contains_comment ( & snippet[ open_pos..] ) =>
1139
+ {
1140
+ result. push_str ( " {}" ) ;
1141
+ return Some ( result) ;
1142
+ }
1131
1143
BraceStyle :: AlwaysNextLine => {
1132
1144
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1133
1145
}
@@ -1144,9 +1156,6 @@ pub(crate) fn format_trait(
1144
1156
}
1145
1157
result. push ( '{' ) ;
1146
1158
1147
- let block_span = mk_sp ( generics. where_clause . span . hi ( ) , item. span . hi ( ) ) ;
1148
- let snippet = context. snippet ( block_span) ;
1149
- let open_pos = snippet. find_uncommented ( "{" ) ? + 1 ;
1150
1159
let outer_indent_str = offset. block_only ( ) . to_string_with_newline ( context. config ) ;
1151
1160
1152
1161
if !trait_items. is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
Original file line number Diff line number Diff line change
1
+ // rustfmt-brace_style: AlwaysNextLine
2
+ // rustfmt-empty_item_single_line: false
3
+
4
+ fn function ( )
5
+ {
6
+
7
+ }
8
+
9
+ struct Struct
10
+ {
11
+
12
+ }
13
+
14
+ enum Enum
15
+ {
16
+
17
+ }
18
+
19
+ trait Trait
20
+ {
21
+
22
+ }
23
+
24
+ impl < T > Trait for T
25
+ {
26
+
27
+ }
28
+
29
+ trait Trait2 < T >
30
+ where
31
+ T : Copy + Display + Write + Read + FromStr , { }
32
+
33
+ trait Trait3 < T >
34
+ where
35
+ T : Something
36
+ + SomethingElse
37
+ + Sync
38
+ + Send
39
+ + Display
40
+ + Debug
41
+ + Copy
42
+ + Hash
43
+ + Debug
44
+ + Display
45
+ + Write
46
+ + Read , { }
Original file line number Diff line number Diff line change @@ -27,3 +27,38 @@ mod M {
27
27
28
28
struct D < T > where T : Copy { }
29
29
}
30
+
31
+
32
+ fn function ( )
33
+ {
34
+
35
+ }
36
+
37
+ trait Trait
38
+ {
39
+
40
+ }
41
+
42
+ impl < T > Trait for T
43
+ {
44
+
45
+ }
46
+
47
+ trait Trait2 < T >
48
+ where
49
+ T : Copy + Display + Write + Read + FromStr , { }
50
+
51
+ trait Trait3 < T >
52
+ where
53
+ T : Something
54
+ + SomethingElse
55
+ + Sync
56
+ + Send
57
+ + Display
58
+ + Debug
59
+ + Copy
60
+ + Hash
61
+ + Debug
62
+ + Display
63
+ + Write
64
+ + Read , { }
Original file line number Diff line number Diff line change
1
+ // rustfmt-brace_style: AlwaysNextLine
2
+ // rustfmt-empty_item_single_line: false
3
+
4
+ fn function ( )
5
+ {
6
+ }
7
+
8
+ struct Struct { }
9
+
10
+ enum Enum { }
11
+
12
+ trait Trait
13
+ {
14
+ }
15
+
16
+ impl < T > Trait for T
17
+ {
18
+ }
19
+
20
+ trait Trait2 < T >
21
+ where
22
+ T : Copy + Display + Write + Read + FromStr ,
23
+ {
24
+ }
25
+
26
+ trait Trait3 < T >
27
+ where
28
+ T : Something
29
+ + SomethingElse
30
+ + Sync
31
+ + Send
32
+ + Display
33
+ + Debug
34
+ + Copy
35
+ + Hash
36
+ + Debug
37
+ + Display
38
+ + Write
39
+ + Read ,
40
+ {
41
+ }
Original file line number Diff line number Diff line change 40
40
where
41
41
T : Copy , { }
42
42
}
43
+
44
+ fn function ( ) { }
45
+
46
+ trait Trait { }
47
+
48
+ impl < T > Trait for T { }
49
+
50
+ trait Trait2 < T >
51
+ where
52
+ T : Copy + Display + Write + Read + FromStr ,
53
+ {
54
+ }
55
+
56
+ trait Trait3 < T >
57
+ where
58
+ T : Something
59
+ + SomethingElse
60
+ + Sync
61
+ + Send
62
+ + Display
63
+ + Debug
64
+ + Copy
65
+ + Hash
66
+ + Debug
67
+ + Display
68
+ + Write
69
+ + Read ,
70
+ {
71
+ }
You can’t perform that action at this time.
0 commit comments