File tree 4 files changed +57
-5
lines changed 4 files changed +57
-5
lines changed Original file line number Diff line number Diff line change @@ -249,8 +249,17 @@ fn rewrite_match_arm(
249
249
} ;
250
250
251
251
// Patterns
252
- // 5 = ` => {`
253
- let pat_shape = shape. sub_width ( 5 ) ?. offset_left ( pipe_offset) ?;
252
+ let is_empty_block = if let ast:: ExprKind :: Block ( ref block, _) = arm. body . kind {
253
+ is_empty_block ( context, block, Some ( & arm. body . attrs ) )
254
+ } else {
255
+ false
256
+ } ;
257
+ let sub_width = if is_empty_block {
258
+ " => {}" . len ( )
259
+ } else {
260
+ " => {" . len ( )
261
+ } ;
262
+ let pat_shape = shape. sub_width ( sub_width) ?. offset_left ( pipe_offset) ?;
254
263
255
264
let pats_str = arm. pat . rewrite ( context, pat_shape) ?;
256
265
@@ -480,7 +489,7 @@ fn rewrite_match_body(
480
489
481
490
match rewrite {
482
491
Some ( ref body_str)
483
- if is_block
492
+ if ( is_block && ( !is_empty_block || !body_str . contains ( '\n' ) ) )
484
493
|| ( !body_str. contains ( '\n' )
485
494
&& unicode_str_width ( body_str) <= body_shape. width ) =>
486
495
{
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 60
2
+
3
+ fn main ( ) {
4
+ match ( pat, num) {
5
+ ( PatternOne , 1 ) | ( RoomForBlockOnSameLine , 10 ) => { }
6
+
7
+ ( PatternOne , 1 ) | ( PatternStretchedToBounds , 2 ) => { }
8
+
9
+ UnsplitableVeryLongArmPatternWithRoomForBlock0 => { }
10
+
11
+ UnsplitableVeryLongArmPatternWithBraceAtEndOfLn => { }
12
+
13
+ UnsplitableVeryLongArmPatternWithArrowAtColnWidth => { }
14
+
15
+ UnsplitableVeryLongArmPatternWithArrowPastColnWidth => { }
16
+
17
+ UnsplitableVeryLongArmPatternGoingBeyondMaxColumnWidth => { }
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 60
2
+
3
+ fn main ( ) {
4
+ match ( pat, num) {
5
+ ( PatternOne , 1 ) | ( RoomForBlockOnSameLine , 10 ) => { }
6
+
7
+ ( PatternOne , 1 )
8
+ | ( PatternStretchedToBounds , 2 ) => { }
9
+
10
+ UnsplitableVeryLongArmPatternWithRoomForBlock0 => { }
11
+
12
+ UnsplitableVeryLongArmPatternWithBraceAtEndOfLn =>
13
+ { }
14
+
15
+ UnsplitableVeryLongArmPatternWithArrowAtColnWidth =>
16
+ { }
17
+
18
+ UnsplitableVeryLongArmPatternWithArrowPastColnWidth =>
19
+ { }
20
+
21
+ UnsplitableVeryLongArmPatternGoingBeyondMaxColumnWidth =>
22
+ { }
23
+ }
24
+ }
Original file line number Diff line number Diff line change @@ -124,8 +124,8 @@ fn issue339() {
124
124
// collapsing here is safe
125
125
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff => { }
126
126
// collapsing here exceeds line length
127
- ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg => {
128
- }
127
+ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg =>
128
+ { }
129
129
h => { // comment above block
130
130
}
131
131
i => { } // comment below block
You can’t perform that action at this time.
0 commit comments