]> git.lizzy.rs Git - rust.git/blob - src/types.rs
Add support for spaces_within_parens config (#1187)
[rust.git] / src / types.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::ops::Deref;
12 use std::iter::ExactSizeIterator;
13
14 use syntax::ast::{self, Mutability, FunctionRetTy};
15 use syntax::print::pprust;
16 use syntax::codemap::{self, Span, BytePos};
17 use syntax::abi;
18
19 use {Indent, Spanned};
20 use codemap::SpanUtils;
21 use lists::{format_item_list, itemize_list, format_fn_args};
22 use rewrite::{Rewrite, RewriteContext};
23 use utils::{extra_offset, format_mutability, wrap_str};
24 use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple};
25 use config::TypeDensity;
26 use itertools::Itertools;
27
28 // Does not wrap on simple segments.
29 pub fn rewrite_path(context: &RewriteContext,
30                     expr_context: bool,
31                     qself: Option<&ast::QSelf>,
32                     path: &ast::Path,
33                     width: usize,
34                     offset: Indent)
35                     -> Option<String> {
36     let skip_count = qself.map_or(0, |x| x.position);
37
38     let mut result = if path.global && qself.is_none() {
39         "::".to_owned()
40     } else {
41         String::new()
42     };
43
44     let mut span_lo = path.span.lo;
45
46     if let Some(qself) = qself {
47         result.push('<');
48         let fmt_ty = try_opt!(qself.ty.rewrite(context, width, offset));
49         result.push_str(&fmt_ty);
50
51         if skip_count > 0 {
52             result.push_str(" as ");
53             if path.global {
54                 result.push_str("::");
55             }
56
57             let extra_offset = extra_offset(&result, offset);
58             // 3 = ">::".len()
59             let budget = try_opt!(width.checked_sub(extra_offset + 3));
60
61             result = try_opt!(rewrite_path_segments(false,
62                                                     result,
63                                                     path.segments.iter().take(skip_count),
64                                                     span_lo,
65                                                     path.span.hi,
66                                                     context,
67                                                     budget,
68                                                     offset + extra_offset));
69         }
70
71         result.push_str(">::");
72         span_lo = qself.ty.span.hi + BytePos(1);
73     }
74
75     let extra_offset = extra_offset(&result, offset);
76     let budget = try_opt!(width.checked_sub(extra_offset));
77     rewrite_path_segments(expr_context,
78                           result,
79                           path.segments.iter().skip(skip_count),
80                           span_lo,
81                           path.span.hi,
82                           context,
83                           budget,
84                           offset + extra_offset)
85 }
86
87 fn rewrite_path_segments<'a, I>(expr_context: bool,
88                                 mut buffer: String,
89                                 iter: I,
90                                 mut span_lo: BytePos,
91                                 span_hi: BytePos,
92                                 context: &RewriteContext,
93                                 width: usize,
94                                 offset: Indent)
95                                 -> Option<String>
96     where I: Iterator<Item = &'a ast::PathSegment>
97 {
98     let mut first = true;
99
100     for segment in iter {
101         if first {
102             first = false;
103         } else {
104             buffer.push_str("::");
105         }
106
107         let extra_offset = extra_offset(&buffer, offset);
108         let remaining_width = try_opt!(width.checked_sub(extra_offset));
109         let new_offset = offset + extra_offset;
110         let segment_string = try_opt!(rewrite_segment(expr_context,
111                                                       segment,
112                                                       &mut span_lo,
113                                                       span_hi,
114                                                       context,
115                                                       remaining_width,
116                                                       new_offset));
117
118         buffer.push_str(&segment_string);
119     }
120
121     Some(buffer)
122 }
123
124 #[derive(Debug)]
125 enum SegmentParam<'a> {
126     LifeTime(&'a ast::Lifetime),
127     Type(&'a ast::Ty),
128     Binding(&'a ast::TypeBinding),
129 }
130
131 impl<'a> SegmentParam<'a> {
132     fn get_span(&self) -> Span {
133         match *self {
134             SegmentParam::LifeTime(lt) => lt.span,
135             SegmentParam::Type(ty) => ty.span,
136             SegmentParam::Binding(binding) => binding.span,
137         }
138     }
139 }
140
141 impl<'a> Rewrite for SegmentParam<'a> {
142     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
143         match *self {
144             SegmentParam::LifeTime(lt) => lt.rewrite(context, width, offset),
145             SegmentParam::Type(ty) => ty.rewrite(context, width, offset),
146             SegmentParam::Binding(binding) => {
147                 let mut result = format!("{} = ", binding.ident);
148                 let budget = try_opt!(width.checked_sub(result.len()));
149                 let rewrite = try_opt!(binding.ty.rewrite(context, budget, offset + result.len()));
150                 result.push_str(&rewrite);
151                 Some(result)
152             }
153         }
154     }
155 }
156
157 // Formats a path segment. There are some hacks involved to correctly determine
158 // the segment's associated span since it's not part of the AST.
159 //
160 // The span_lo is assumed to be greater than the end of any previous segment's
161 // parameters and lesser or equal than the start of current segment.
162 //
163 // span_hi is assumed equal to the end of the entire path.
164 //
165 // When the segment contains a positive number of parameters, we update span_lo
166 // so that invariants described above will hold for the next segment.
167 fn rewrite_segment(expr_context: bool,
168                    segment: &ast::PathSegment,
169                    span_lo: &mut BytePos,
170                    span_hi: BytePos,
171                    context: &RewriteContext,
172                    width: usize,
173                    offset: Indent)
174                    -> Option<String> {
175     let ident_len = segment.identifier.to_string().len();
176     let width = try_opt!(width.checked_sub(ident_len));
177     let offset = offset + ident_len;
178
179     let params = match segment.parameters {
180         ast::PathParameters::AngleBracketed(ref data) if !data.lifetimes.is_empty() ||
181                                                          !data.types.is_empty() ||
182                                                          !data.bindings.is_empty() => {
183             let param_list = data.lifetimes
184                 .iter()
185                 .map(SegmentParam::LifeTime)
186                 .chain(data.types.iter().map(|x| SegmentParam::Type(&*x)))
187                 .chain(data.bindings.iter().map(|x| SegmentParam::Binding(&*x)))
188                 .collect::<Vec<_>>();
189
190             let next_span_lo = param_list.last().unwrap().get_span().hi + BytePos(1);
191             let list_lo = context.codemap.span_after(codemap::mk_sp(*span_lo, span_hi), "<");
192             let separator = if expr_context { "::" } else { "" };
193
194             // 1 for <
195             let extra_offset = 1 + separator.len();
196             // 1 for >
197             let list_width = try_opt!(width.checked_sub(extra_offset + 1));
198
199             let items = itemize_list(context.codemap,
200                                      param_list.into_iter(),
201                                      ">",
202                                      |param| param.get_span().lo,
203                                      |param| param.get_span().hi,
204                                      |seg| seg.rewrite(context, list_width, offset + extra_offset),
205                                      list_lo,
206                                      span_hi);
207             let list_str = try_opt!(format_item_list(items,
208                                                      list_width,
209                                                      offset + extra_offset,
210                                                      context.config));
211
212             // Update position of last bracket.
213             *span_lo = next_span_lo;
214
215             format!("{}<{}>", separator, list_str)
216         }
217         ast::PathParameters::Parenthesized(ref data) => {
218             let output = match data.output {
219                 Some(ref ty) => FunctionRetTy::Ty(ty.clone()),
220                 None => FunctionRetTy::Default(codemap::DUMMY_SP),
221             };
222             try_opt!(format_function_type(data.inputs.iter().map(|x| &**x),
223                                           &output,
224                                           false,
225                                           data.span,
226                                           context,
227                                           width,
228                                           offset))
229         }
230         _ => String::new(),
231     };
232
233     Some(format!("{}{}", segment.identifier, params))
234 }
235
236 fn format_function_type<'a, I>(inputs: I,
237                                output: &FunctionRetTy,
238                                variadic: bool,
239                                span: Span,
240                                context: &RewriteContext,
241                                width: usize,
242                                offset: Indent)
243                                -> Option<String>
244     where I: ExactSizeIterator,
245           <I as Iterator>::Item: Deref,
246           <I::Item as Deref>::Target: Rewrite + Spanned + 'a
247 {
248     // Code for handling variadics is somewhat duplicated for items, but they
249     // are different enough to need some serious refactoring to share code.
250     enum ArgumentKind<T>
251         where T: Deref,
252               <T as Deref>::Target: Rewrite + Spanned
253     {
254         Regular(Box<T>),
255         Variadic(BytePos),
256     }
257
258     let variadic_arg = if variadic {
259         let variadic_start = context.codemap.span_before(span, "...");
260         Some(ArgumentKind::Variadic(variadic_start))
261     } else {
262         None
263     };
264
265     // 2 for ()
266     let budget = try_opt!(width.checked_sub(2));
267     // 1 for (
268     let offset = offset + 1;
269     let list_lo = context.codemap.span_after(span, "(");
270     let items = itemize_list(context.codemap,
271                              // FIXME Would be nice to avoid this allocation,
272                              // but I couldn't get the types to work out.
273                              inputs.map(|i| ArgumentKind::Regular(Box::new(i)))
274                                  .chain(variadic_arg),
275                              ")",
276                              |arg| {
277                                  match *arg {
278                                      ArgumentKind::Regular(ref ty) => ty.span().lo,
279                                      ArgumentKind::Variadic(start) => start,
280                                  }
281                              },
282                              |arg| {
283                                  match *arg {
284                                      ArgumentKind::Regular(ref ty) => ty.span().hi,
285                                      ArgumentKind::Variadic(start) => start + BytePos(3),
286                                  }
287                              },
288                              |arg| {
289         match *arg {
290             ArgumentKind::Regular(ref ty) => ty.rewrite(context, budget, offset),
291             ArgumentKind::Variadic(_) => Some("...".to_owned()),
292         }
293     },
294                              list_lo,
295                              span.hi);
296
297     let list_str = try_opt!(format_fn_args(items, budget, offset, context.config));
298
299     let output = match *output {
300         FunctionRetTy::Ty(ref ty) => {
301             let budget = try_opt!(width.checked_sub(4));
302             let type_str = try_opt!(ty.rewrite(context, budget, offset + 4));
303             format!(" -> {}", type_str)
304         }
305         FunctionRetTy::Default(..) => String::new(),
306     };
307
308     let infix = if !output.is_empty() && output.len() + list_str.len() > width {
309         format!("\n{}", (offset - 1).to_string(context.config))
310     } else {
311         String::new()
312     };
313
314     Some(if context.config.spaces_within_parens {
315         format!("( {} ){}{}", list_str, infix, output)
316     } else {
317         format!("({}){}{}", list_str, infix, output)
318     })
319 }
320
321 impl Rewrite for ast::WherePredicate {
322     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
323         // TODO: dead spans?
324         let result = match *self {
325             ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate { ref bound_lifetimes,
326                                                                            ref bounded_ty,
327                                                                            ref bounds,
328                                                                            .. }) => {
329                 let type_str = try_opt!(bounded_ty.rewrite(context, width, offset));
330
331                 if !bound_lifetimes.is_empty() {
332                     let lifetime_str: String = try_opt!(bound_lifetimes.iter()
333                                                                .map(|lt| {
334                                                                    lt.rewrite(context,
335                                                                               width,
336                                                                               offset)
337                                                                })
338                                                                .intersperse(Some(", ".to_string()))
339                                                                .collect());
340
341                     // 8 = "for<> : ".len()
342                     let used_width = lifetime_str.len() + type_str.len() + 8;
343                     let budget = try_opt!(width.checked_sub(used_width));
344                     let bounds_str: String = try_opt!(bounds.iter()
345                                                     .map(|ty_bound| {
346                                                         ty_bound.rewrite(context,
347                                                                          budget,
348                                                                          offset + used_width)
349                                                     })
350                                                     .intersperse(Some(" + ".to_string()))
351                                                     .collect());
352
353                     format!("for<{}> {}: {}", lifetime_str, type_str, bounds_str)
354                 } else {
355                     // 2 = ": ".len()
356                     let used_width = type_str.len() + 2;
357                     let budget = try_opt!(width.checked_sub(used_width));
358                     let bounds_str: String = try_opt!(bounds.iter()
359                                                     .map(|ty_bound| {
360                                                         ty_bound.rewrite(context,
361                                                                          budget,
362                                                                          offset + used_width)
363                                                     })
364                                                     .intersperse(Some(" + ".to_string()))
365                                                     .collect());
366
367                     format!("{}: {}", type_str, bounds_str)
368                 }
369             }
370             ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate { ref lifetime,
371                                                                              ref bounds,
372                                                                              .. }) => {
373                 try_opt!(rewrite_bounded_lifetime(lifetime, bounds.iter(), context, width, offset))
374             }
375             ast::WherePredicate::EqPredicate(ast::WhereEqPredicate { ref path, ref ty, .. }) => {
376                 let ty_str = try_opt!(ty.rewrite(context, width, offset));
377                 // 3 = " = ".len()
378                 let used_width = 3 + ty_str.len();
379                 let budget = try_opt!(width.checked_sub(used_width));
380                 let path_str =
381                     try_opt!(rewrite_path(context, false, None, path, budget, offset + used_width));
382                 format!("{} = {}", path_str, ty_str)
383             }
384         };
385
386         wrap_str(result, context.config.max_width, width, offset)
387     }
388 }
389
390 impl Rewrite for ast::LifetimeDef {
391     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
392         rewrite_bounded_lifetime(&self.lifetime, self.bounds.iter(), context, width, offset)
393     }
394 }
395
396 fn rewrite_bounded_lifetime<'b, I>(lt: &ast::Lifetime,
397                                    bounds: I,
398                                    context: &RewriteContext,
399                                    width: usize,
400                                    offset: Indent)
401                                    -> Option<String>
402     where I: ExactSizeIterator<Item = &'b ast::Lifetime>
403 {
404     let result = try_opt!(lt.rewrite(context, width, offset));
405
406     if bounds.len() == 0 {
407         Some(result)
408     } else {
409         let appendix: Vec<_> = try_opt!(bounds.into_iter()
410             .map(|b| b.rewrite(context, width, offset))
411             .collect());
412         let bound_spacing_before = if context.config.space_before_bound {
413             " "
414         } else {
415             ""
416         };
417         let bound_spacing_after = if context.config.space_after_bound_colon {
418             " "
419         } else {
420             ""
421         };
422         let result = format!("{}{}:{}{}",
423                              result,
424                              bound_spacing_before,
425                              bound_spacing_after,
426                              appendix.join(" + "));
427         wrap_str(result, context.config.max_width, width, offset)
428     }
429 }
430
431 impl Rewrite for ast::TyParamBound {
432     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
433         match *self {
434             ast::TyParamBound::TraitTyParamBound(ref tref, ast::TraitBoundModifier::None) => {
435                 tref.rewrite(context, width, offset)
436             }
437             ast::TyParamBound::TraitTyParamBound(ref tref, ast::TraitBoundModifier::Maybe) => {
438                 let budget = try_opt!(width.checked_sub(1));
439                 Some(format!("?{}", try_opt!(tref.rewrite(context, budget, offset + 1))))
440             }
441             ast::TyParamBound::RegionTyParamBound(ref l) => l.rewrite(context, width, offset),
442         }
443     }
444 }
445
446 impl Rewrite for ast::Lifetime {
447     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
448         wrap_str(pprust::lifetime_to_string(self),
449                  context.config.max_width,
450                  width,
451                  offset)
452     }
453 }
454
455 impl Rewrite for ast::TyParamBounds {
456     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
457         let strs: Vec<_> = try_opt!(self.iter()
458             .map(|b| b.rewrite(context, width, offset))
459             .collect());
460         wrap_str(strs.join(" + "), context.config.max_width, width, offset)
461     }
462 }
463
464 impl Rewrite for ast::TyParam {
465     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
466         let mut result = String::with_capacity(128);
467         result.push_str(&self.ident.to_string());
468         if !self.bounds.is_empty() {
469             if context.config.space_before_bound {
470                 result.push_str(" ");
471             }
472             result.push_str(":");
473             if context.config.space_after_bound_colon {
474                 result.push_str(" ");
475             }
476
477             let bounds: String = try_opt!(self.bounds
478                 .iter()
479                 .map(|ty_bound| ty_bound.rewrite(context, width, offset))
480                 .intersperse(Some(" + ".to_string()))
481                 .collect());
482
483             result.push_str(&bounds);
484         }
485         if let Some(ref def) = self.default {
486
487             let eq_str = match context.config.type_punctuation_density {
488                 TypeDensity::Compressed => "=",
489                 TypeDensity::Wide => " = ",
490             };
491             result.push_str(eq_str);
492             let budget = try_opt!(width.checked_sub(result.len()));
493             let rewrite = try_opt!(def.rewrite(context, budget, offset + result.len()));
494             result.push_str(&rewrite);
495         }
496
497         wrap_str(result, context.config.max_width, width, offset)
498     }
499 }
500
501 impl Rewrite for ast::PolyTraitRef {
502     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
503         if !self.bound_lifetimes.is_empty() {
504             let lifetime_str: String = try_opt!(self.bound_lifetimes
505                 .iter()
506                 .map(|lt| lt.rewrite(context, width, offset))
507                 .intersperse(Some(", ".to_string()))
508                 .collect());
509
510             // 6 is "for<> ".len()
511             let extra_offset = lifetime_str.len() + 6;
512             let max_path_width = try_opt!(width.checked_sub(extra_offset));
513             let path_str = try_opt!(self.trait_ref
514                 .rewrite(context, max_path_width, offset + extra_offset));
515
516             Some(format!("for<{}> {}", lifetime_str, path_str))
517         } else {
518             self.trait_ref.rewrite(context, width, offset)
519         }
520     }
521 }
522
523 impl Rewrite for ast::TraitRef {
524     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
525         rewrite_path(context, false, None, &self.path, width, offset)
526     }
527 }
528
529 impl Rewrite for ast::Ty {
530     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
531         match self.node {
532             ast::TyKind::ObjectSum(ref ty, ref bounds) => {
533                 let ty_str = try_opt!(ty.rewrite(context, width, offset));
534                 let overhead = ty_str.len() + 3;
535                 let plus_str = match context.config.type_punctuation_density {
536                     TypeDensity::Compressed => "+",
537                     TypeDensity::Wide => " + ",
538                 };
539                 Some(format!("{}{}{}",
540                              ty_str,
541                              plus_str,
542                              try_opt!(bounds.rewrite(context,
543                                                      try_opt!(width.checked_sub(overhead)),
544                                                      offset + overhead))))
545             }
546             ast::TyKind::Ptr(ref mt) => {
547                 let prefix = match mt.mutbl {
548                     Mutability::Mutable => "*mut ",
549                     Mutability::Immutable => "*const ",
550                 };
551
552                 rewrite_unary_prefix(context, prefix, &*mt.ty, width, offset)
553             }
554             ast::TyKind::Rptr(ref lifetime, ref mt) => {
555                 let mut_str = format_mutability(mt.mutbl);
556                 let mut_len = mut_str.len();
557                 Some(match *lifetime {
558                     Some(ref lifetime) => {
559                         let lt_budget = try_opt!(width.checked_sub(2 + mut_len));
560                         let lt_str =
561                             try_opt!(lifetime.rewrite(context, lt_budget, offset + 2 + mut_len));
562                         let lt_len = lt_str.len();
563                         let budget = try_opt!(width.checked_sub(2 + mut_len + lt_len));
564                         format!("&{} {}{}",
565                                 lt_str,
566                                 mut_str,
567                                 try_opt!(mt.ty
568                                     .rewrite(context, budget, offset + 2 + mut_len + lt_len)))
569                     }
570                     None => {
571                         let budget = try_opt!(width.checked_sub(1 + mut_len));
572                         format!("&{}{}",
573                                 mut_str,
574                                 try_opt!(mt.ty.rewrite(context, budget, offset + 1 + mut_len)))
575                     }
576                 })
577             }
578             // FIXME: we drop any comments here, even though it's a silly place to put
579             // comments.
580             ast::TyKind::Paren(ref ty) => {
581                 let budget = try_opt!(width.checked_sub(2));
582                 ty.rewrite(context, budget, offset + 1)
583                     .map(|ty_str| if context.config.spaces_within_parens {
584                         format!("( {} )", ty_str)
585                     } else {
586                         format!("({})", ty_str)
587                     })
588             }
589             ast::TyKind::Vec(ref ty) => {
590                 let budget = try_opt!(width.checked_sub(2));
591                 ty.rewrite(context, budget, offset + 1).map(|ty_str| format!("[{}]", ty_str))
592             }
593             ast::TyKind::Tup(ref items) => {
594                 rewrite_tuple(context,
595                               items.iter().map(|x| &**x),
596                               self.span,
597                               width,
598                               offset)
599             }
600             ast::TyKind::PolyTraitRef(ref trait_ref) => trait_ref.rewrite(context, width, offset),
601             ast::TyKind::Path(ref q_self, ref path) => {
602                 rewrite_path(context, false, q_self.as_ref(), path, width, offset)
603             }
604             ast::TyKind::FixedLengthVec(ref ty, ref repeats) => {
605                 rewrite_pair(&**ty, &**repeats, "[", "; ", "]", context, width, offset)
606             }
607             ast::TyKind::Infer => {
608                 if width >= 1 {
609                     Some("_".to_owned())
610                 } else {
611                     None
612                 }
613             }
614             ast::TyKind::BareFn(ref bare_fn) => {
615                 rewrite_bare_fn(bare_fn, self.span, context, width, offset)
616             }
617             ast::TyKind::Never => Some(String::from("!")),
618             ast::TyKind::Mac(..) |
619             ast::TyKind::Typeof(..) => unreachable!(),
620             ast::TyKind::ImplicitSelf => Some(String::from("")),
621             ast::TyKind::ImplTrait(..) => {
622                 // FIXME(#1154) Implement impl Trait
623                 Some(String::from("impl TODO"))
624             }
625         }
626     }
627 }
628
629 fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
630                    span: Span,
631                    context: &RewriteContext,
632                    width: usize,
633                    offset: Indent)
634                    -> Option<String> {
635     let mut result = String::with_capacity(128);
636
637     if !bare_fn.lifetimes.is_empty() {
638         result.push_str("for<");
639         // 6 = "for<> ".len(), 4 = "for<".
640         // This doesn't work out so nicely for mutliline situation with lots of
641         // rightward drift. If that is a problem, we could use the list stuff.
642         result.push_str(&try_opt!(bare_fn.lifetimes
643             .iter()
644             .map(|l| l.rewrite(context, try_opt!(width.checked_sub(6)), offset + 4))
645             .intersperse(Some(", ".to_string()))
646             .collect::<Option<String>>()));
647         result.push_str("> ");
648     }
649
650     result.push_str(::utils::format_unsafety(bare_fn.unsafety));
651
652     if bare_fn.abi != abi::Abi::Rust {
653         result.push_str(&::utils::format_abi(bare_fn.abi, context.config.force_explicit_abi));
654     }
655
656     result.push_str("fn");
657
658     let budget = try_opt!(width.checked_sub(result.len()));
659     let indent = offset + result.len();
660
661     let rewrite = try_opt!(format_function_type(bare_fn.decl.inputs.iter(),
662                                                 &bare_fn.decl.output,
663                                                 bare_fn.decl.variadic,
664                                                 span,
665                                                 context,
666                                                 budget,
667                                                 indent));
668
669     result.push_str(&rewrite);
670
671     Some(result)
672 }