@@ -89,26 +89,81 @@ impl Rewrite for Pat {
8989 PatKind :: Box ( ref pat) => rewrite_unary_prefix ( context, "box " , & * * pat, shape) ,
9090 PatKind :: Ident ( binding_mode, ident, ref sub_pat) => {
9191 let ( prefix, mutability) = match binding_mode {
92- BindingMode :: ByRef ( mutability) => ( "ref " , mutability) ,
92+ BindingMode :: ByRef ( mutability) => ( "ref" , mutability) ,
9393 BindingMode :: ByValue ( mutability) => ( "" , mutability) ,
9494 } ;
95- let mut_infix = format_mutability ( mutability) ;
95+ let mut_infix = format_mutability ( mutability) . trim ( ) ;
9696 let id_str = rewrite_ident ( context, ident) ;
9797 let sub_pat = match * sub_pat {
9898 Some ( ref p) => {
99- // 3 - ` @ `.
99+ // 2 - `@ `.
100100 let width = shape
101101 . width
102- . checked_sub ( prefix. len ( ) + mut_infix. len ( ) + id_str. len ( ) + 3 ) ?;
103- format ! (
104- " @ {}" ,
105- p. rewrite( context, Shape :: legacy( width, shape. indent) ) ?
106- )
102+ . checked_sub ( prefix. len ( ) + mut_infix. len ( ) + id_str. len ( ) + 2 ) ?;
103+ let lo = context. snippet_provider . span_after ( self . span , "@" ) ;
104+ combine_strs_with_missing_comments (
105+ context,
106+ "@" ,
107+ & p. rewrite ( context, Shape :: legacy ( width, shape. indent ) ) ?,
108+ mk_sp ( lo, p. span . lo ( ) ) ,
109+ shape,
110+ true ,
111+ ) ?
107112 }
108113 None => "" . to_owned ( ) ,
109114 } ;
110115
111- Some ( format ! ( "{}{}{}{}" , prefix, mut_infix, id_str, sub_pat) )
116+ // combine prefix and mut
117+ let ( first_lo, first) = if !prefix. is_empty ( ) && !mut_infix. is_empty ( ) {
118+ let hi = context. snippet_provider . span_before ( self . span , "mut" ) ;
119+ let lo = context. snippet_provider . span_after ( self . span , "ref" ) ;
120+ (
121+ context. snippet_provider . span_after ( self . span , "mut" ) ,
122+ combine_strs_with_missing_comments (
123+ context,
124+ prefix,
125+ mut_infix,
126+ mk_sp ( lo, hi) ,
127+ shape,
128+ true ,
129+ ) ?,
130+ )
131+ } else if !prefix. is_empty ( ) {
132+ (
133+ context. snippet_provider . span_after ( self . span , "ref" ) ,
134+ prefix. to_owned ( ) ,
135+ )
136+ } else if !mut_infix. is_empty ( ) {
137+ (
138+ context. snippet_provider . span_after ( self . span , "mut" ) ,
139+ mut_infix. to_owned ( ) ,
140+ )
141+ } else {
142+ ( self . span . lo ( ) , "" . to_owned ( ) )
143+ } ;
144+
145+ let next = if !sub_pat. is_empty ( ) {
146+ let hi = context. snippet_provider . span_before ( self . span , "@" ) ;
147+ combine_strs_with_missing_comments (
148+ context,
149+ id_str,
150+ & sub_pat,
151+ mk_sp ( ident. span . hi ( ) , hi) ,
152+ shape,
153+ true ,
154+ ) ?
155+ } else {
156+ id_str. to_owned ( )
157+ } ;
158+
159+ combine_strs_with_missing_comments (
160+ context,
161+ & first,
162+ & next,
163+ mk_sp ( first_lo, ident. span . lo ( ) ) ,
164+ shape,
165+ true ,
166+ )
112167 }
113168 PatKind :: Wild => {
114169 if 1 <= shape. width {
0 commit comments