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 @@ -248,8 +248,17 @@ fn rewrite_match_arm(
248
248
} ;
249
249
250
250
// Patterns
251
- // 5 = ` => {`
252
- let pat_shape = shape. sub_width ( 5 ) ?. offset_left ( pipe_offset) ?;
251
+ let is_empty_block = if let ast:: ExprKind :: Block ( ref block, _) = arm. body . kind {
252
+ is_empty_block ( context, block, Some ( & arm. body . attrs ) )
253
+ } else {
254
+ false
255
+ } ;
256
+ let sub_width = if is_empty_block {
257
+ " => {}" . len ( )
258
+ } else {
259
+ " => {" . len ( )
260
+ } ;
261
+ let pat_shape = shape. sub_width ( sub_width) ?. offset_left ( pipe_offset) ?;
253
262
254
263
let pats_str = arm. pat . rewrite ( context, pat_shape) ?;
255
264
@@ -479,7 +488,7 @@ fn rewrite_match_body(
479
488
480
489
match rewrite {
481
490
Some ( ref body_str)
482
- if is_block
491
+ if ( is_block && ( !is_empty_block || !body_str . contains ( '\n' ) ) )
483
492
|| ( !body_str. contains ( '\n' )
484
493
&& unicode_str_width ( body_str) <= body_shape. width ) =>
485
494
{
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