File tree Expand file tree Collapse file tree 4 files changed +57
-5
lines changed Expand file tree Collapse file tree 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(
249249 } ;
250250
251251 // 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) ?;
254263
255264 let pats_str = arm. pat . rewrite ( context, pat_shape) ?;
256265
@@ -480,7 +489,7 @@ fn rewrite_match_body(
480489
481490 match rewrite {
482491 Some ( ref body_str)
483- if is_block
492+ if ( is_block && ( !is_empty_block || !body_str . contains ( '\n' ) ) )
484493 || ( !body_str. contains ( '\n' )
485494 && unicode_str_width ( body_str) <= body_shape. width ) =>
486495 {
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() {
124124 // collapsing here is safe
125125 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff => { }
126126 // collapsing here exceeds line length
127- ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg => {
128- }
127+ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg =>
128+ { }
129129 h => { // comment above block
130130 }
131131 i => { } // comment below block
You can’t perform that action at this time.
0 commit comments