@@ -31,8 +31,10 @@ impl Rewrite for Pat {
31
31
32
32
let sub_pat = match * sub_pat {
33
33
Some ( ref p) => {
34
+ // 3 - ` @ `.
34
35
let width = try_opt ! ( width. checked_sub( prefix. len( ) + mut_infix. len( ) +
35
- id_str. len( ) ) ) ;
36
+ id_str. len( ) +
37
+ 3 ) ) ;
36
38
format ! ( " @ {}" , try_opt!( p. rewrite( context, width, offset) ) )
37
39
}
38
40
None => "" . to_owned ( ) ,
@@ -105,17 +107,16 @@ impl Rewrite for Pat {
105
107
let suffix = suffix. iter ( ) . map ( |p| p. rewrite ( context, width, offset) ) ;
106
108
107
109
// Munge them together.
108
- let pats = prefix. chain ( slice_pat. into_iter ( ) ) . chain ( suffix) ;
110
+ let pats: Option < Vec < String > > = prefix. chain ( slice_pat. into_iter ( ) )
111
+ . chain ( suffix)
112
+ . collect ( ) ;
109
113
110
114
// Check that all the rewrites succeeded, and if not return None.
111
- let ( somes, nones) = pats. partition :: < Vec < Option < String > > , _ > ( Option :: is_some) ;
112
- if nones. len ( ) > 0 {
113
- return None ;
114
- }
115
+ let pats = try_opt ! ( pats) ;
115
116
116
117
// Unwrap all the sub-strings and join them with commas.
117
- let pats = somes . into_iter ( ) . map ( |p| p . unwrap ( ) ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ;
118
- Some ( format ! ( "[{}]" , pats ) )
118
+ let result = format ! ( "[{}]" , pats . join( ", " ) ) ;
119
+ wrap_str ( result , context . config . max_width , width , offset )
119
120
}
120
121
Pat_ :: PatStruct ( ref path, ref fields, elipses) => {
121
122
let path = try_opt ! ( rewrite_path( context, true , None , path, width, offset) ) ;
@@ -126,10 +127,12 @@ impl Rewrite for Pat {
126
127
( "" , "}" )
127
128
} ;
128
129
130
+ // 5 = `{` plus space before and after plus `}` plus space before.
129
131
let budget = try_opt ! ( width. checked_sub( path. len( ) + 5 + elipses_str. len( ) ) ) ;
130
132
// FIXME Using visual indenting, should use block or visual to match
131
133
// struct lit preference (however, in practice I think it is rare
132
134
// for struct patterns to be multi-line).
135
+ // 3 = `{` plus space before and after.
133
136
let offset = offset + path. len ( ) + 3 ;
134
137
135
138
let items = itemize_list ( context. codemap ,
@@ -157,7 +160,7 @@ impl Rewrite for Pat {
157
160
}
158
161
}
159
162
160
- if field_string. len ( ) == 0 {
163
+ if field_string. is_empty ( ) {
161
164
Some ( format ! ( "{} {{}}" , path) )
162
165
} else {
163
166
Some ( format ! ( "{} {{ {} }}" , path, field_string) )
@@ -180,7 +183,10 @@ impl Rewrite for FieldPat {
180
183
if self . is_shorthand {
181
184
pat
182
185
} else {
183
- Some ( format ! ( "{}: {}" , self . ident. to_string( ) , try_opt!( pat) ) )
186
+ wrap_str ( format ! ( "{}: {}" , self . ident. to_string( ) , try_opt!( pat) ) ,
187
+ context. config . max_width ,
188
+ width,
189
+ offset)
184
190
}
185
191
}
186
192
}
0 commit comments