@@ -176,48 +176,48 @@ impl Rewrite for ast::Expr {
176
176
ast:: ExprKind :: Cast ( ref expr, ref ty) => {
177
177
rewrite_pair ( & * * expr, & * * ty, "" , " as " , "" , context, width, offset)
178
178
}
179
- // TODO(#848): Handle type ascription; rust tracking issue
180
- // https://github.com/rust-lang/rust/issues/23416
181
- ast:: ExprKind :: Type ( _, _) => unimplemented ! ( ) ,
182
179
ast:: ExprKind :: Index ( ref expr, ref index) => {
183
180
rewrite_pair ( & * * expr, & * * index, "" , "[" , "]" , context, width, offset)
184
181
}
185
182
ast:: ExprKind :: Repeat ( ref expr, ref repeats) => {
186
183
rewrite_pair ( & * * expr, & * * repeats, "[" , "; " , "]" , context, width, offset)
187
184
}
188
- // TODO(#890): Handle closed ranges; rust tracking issue
189
- // https://github.com/rust-lang/rust/issues/28237
190
- ast:: ExprKind :: Range ( Some ( ref lhs) , Some ( ref rhs) , _range_limits) => {
191
- rewrite_pair ( & * * lhs, & * * rhs, "" , ".." , "" , context, width, offset)
192
- }
193
- ast:: ExprKind :: Range ( None , Some ( ref rhs) , _range_limits) => {
194
- rewrite_unary_prefix ( context, ".." , & * * rhs, width, offset)
195
- }
196
- ast:: ExprKind :: Range ( Some ( ref lhs) , None , _range_limits) => {
197
- Some ( format ! ( "{}.." ,
198
- try_opt!( lhs. rewrite( context,
199
- try_opt!( width. checked_sub( 2 ) ) ,
200
- offset) ) ) )
201
- }
202
- ast:: ExprKind :: Range ( None , None , _range_limits) => {
203
- if width >= 2 {
204
- Some ( ".." . into ( ) )
205
- } else {
206
- None
185
+ ast:: ExprKind :: Range ( ref lhs, ref rhs, limits) => {
186
+ let delim = match limits {
187
+ ast:: RangeLimits :: HalfOpen => ".." ,
188
+ ast:: RangeLimits :: Closed => "..." ,
189
+ } ;
190
+
191
+ match ( lhs. as_ref ( ) . map ( |x| & * * x) , rhs. as_ref ( ) . map ( |x| & * * x) ) {
192
+ ( Some ( ref lhs) , Some ( ref rhs) ) => {
193
+ rewrite_pair ( & * * lhs, & * * rhs, "" , delim, "" , context, width, offset)
194
+ }
195
+ ( None , Some ( ref rhs) ) => {
196
+ rewrite_unary_prefix ( context, delim, & * * rhs, width, offset)
197
+ }
198
+ ( Some ( ref lhs) , None ) => {
199
+ Some ( format ! ( "{}{}" ,
200
+ try_opt!( lhs. rewrite( context,
201
+ try_opt!( width. checked_sub( delim. len( ) ) ) ,
202
+ offset) ) ,
203
+ delim) )
204
+ }
205
+ ( None , None ) => wrap_str ( delim. into ( ) , context. config . max_width , width, offset) ,
207
206
}
208
207
}
209
208
// We do not format these expressions yet, but they should still
210
209
// satisfy our width restrictions.
211
210
ast:: ExprKind :: InPlace ( ..) |
212
- ast:: ExprKind :: InlineAsm ( ..) => {
211
+ ast:: ExprKind :: InlineAsm ( ..) |
212
+ // TODO(#848): Handle type ascription
213
+ ast:: ExprKind :: Type ( _, _) |
214
+ // TODO(#867): Handle try shorthand
215
+ ast:: ExprKind :: Try ( _) => {
213
216
wrap_str ( context. snippet ( self . span ) ,
214
217
context. config . max_width ,
215
218
width,
216
219
offset)
217
220
}
218
- // TODO(#867): Handle type ascription; rust tracking issue
219
- // https://github.com/rust-lang/rust/issues/31436
220
- ast:: ExprKind :: Try ( _) => unimplemented ! ( ) ,
221
221
} ;
222
222
result. and_then ( |res| recover_comment_removed ( res, self . span , context, width, offset) )
223
223
}
0 commit comments