@@ -7,7 +7,7 @@ use rustc_span::{BytePos, Span};
7
7
8
8
use crate :: comment:: { combine_strs_with_missing_comments, rewrite_comment} ;
9
9
use crate :: config:: lists:: * ;
10
- use crate :: config:: { Config , ControlBraceStyle , IndentStyle } ;
10
+ use crate :: config:: { Config , ControlBraceStyle , IndentStyle , MatchArmLeadingPipe } ;
11
11
use crate :: expr:: {
12
12
format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, rewrite_cond,
13
13
ExprType , RhsTactics ,
@@ -55,7 +55,13 @@ impl<'a> Spanned for ArmWrapper<'a> {
55
55
56
56
impl < ' a > Rewrite for ArmWrapper < ' a > {
57
57
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
58
- rewrite_match_arm ( context, self . arm , shape, self . is_last )
58
+ rewrite_match_arm (
59
+ context,
60
+ self . arm ,
61
+ shape,
62
+ self . is_last ,
63
+ self . beginning_vert . is_some ( ) ,
64
+ )
59
65
}
60
66
}
61
67
@@ -215,6 +221,7 @@ fn rewrite_match_arm(
215
221
arm : & ast:: Arm ,
216
222
shape : Shape ,
217
223
is_last : bool ,
224
+ has_leading_pipe : bool ,
218
225
) -> Option < String > {
219
226
let ( missing_span, attrs_str) = if !arm. attrs . is_empty ( ) {
220
227
if contains_skip ( & arm. attrs ) {
@@ -232,9 +239,18 @@ fn rewrite_match_arm(
232
239
( mk_sp ( arm. span ( ) . lo ( ) , arm. span ( ) . lo ( ) ) , String :: new ( ) )
233
240
} ;
234
241
242
+ // Leading pipe offset
243
+ // 2 = `| `
244
+ let ( pipe_offset, pipe_str) = match context. config . match_arm_leading_pipes ( ) {
245
+ MatchArmLeadingPipe :: Never => ( 0 , "" ) ,
246
+ MatchArmLeadingPipe :: KeepExisting if !has_leading_pipe => ( 0 , "" ) ,
247
+ MatchArmLeadingPipe :: KeepExisting | MatchArmLeadingPipe :: Always => ( 2 , "| " ) ,
248
+ } ;
249
+
235
250
// Patterns
236
251
// 5 = ` => {`
237
- let pat_shape = shape. sub_width ( 5 ) ?;
252
+ let pat_shape = shape. sub_width ( 5 ) ?. offset_left ( pipe_offset) ?;
253
+
238
254
let pats_str = arm. pat . rewrite ( context, pat_shape) ?;
239
255
240
256
// Guard
@@ -251,7 +267,7 @@ fn rewrite_match_arm(
251
267
let lhs_str = combine_strs_with_missing_comments (
252
268
context,
253
269
& attrs_str,
254
- & format ! ( "{}{}" , pats_str, guard_str) ,
270
+ & format ! ( "{}{}{}" , pipe_str , pats_str, guard_str) ,
255
271
missing_span,
256
272
shape,
257
273
false ,
0 commit comments