diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-10-09 16:07:14 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-10-10 14:55:31 +1300 |
| commit | aed558fce435924e6839f46c4cc0f021fe33f097 (patch) | |
| tree | b83fe099a3d95c8dbf931f0e481532aadb625392 /src/types.rs | |
| parent | e9ea76983ce8bfc320c48ed55ce6cf53e212025e (diff) | |
Handle multi-line return types and multi-line tuples
Closes #409
Diffstat (limited to 'src/types.rs')
| -rw-r--r-- | src/types.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/types.rs b/src/types.rs index 2cbbed92fa5..a706f7ec464 100644 --- a/src/types.rs +++ b/src/types.rs @@ -13,7 +13,7 @@ use syntax::print::pprust; use syntax::codemap::{self, Span, BytePos, CodeMap}; use Indent; -use lists::{format_item_list, itemize_list, format_fn_args}; +use lists::{format_item_list, itemize_list, format_fn_args, list_helper, ListTactic}; use rewrite::{Rewrite, RewriteContext}; use utils::{extra_offset, span_after, format_mutability, wrap_str}; @@ -475,19 +475,27 @@ impl Rewrite for ast::Ty { ty.rewrite(context, budget, offset + 1).map(|ty_str| format!("({})", ty_str)) } ast::TyTup(ref tup_ret) => { - let inner = if let [ref item] = &**tup_ret { - try_opt!(item.rewrite(context, width, offset)) + "," + let budget = try_opt!(width.checked_sub(2)); + if tup_ret.is_empty() { + Some("()".to_string()) + } else if let [ref item] = &**tup_ret { + let inner = try_opt!(item.rewrite(context, budget, offset + 1)); + let ret = format!("({},)", inner); + wrap_str(ret, context.config.max_width, budget, offset + 1) } else { - let rewrites: Option<Vec<_>>; - rewrites = tup_ret.iter() - .map(|item| item.rewrite(context, width, offset)) - .collect(); - - try_opt!(rewrites).join(", ") - }; - - let ret = format!("({})", inner); - wrap_str(ret, context.config.max_width, width, offset) + let items = itemize_list(context.codemap, + tup_ret.iter(), + ")", + |item| item.span.lo, + |item| item.span.hi, + |item| item.rewrite(context, budget, offset + 1), + tup_ret[0].span.lo, + self.span.hi); + + + list_helper(items, budget, offset + 1, context.config, ListTactic::Mixed) + .map(|s| format!("({})", s)) + } } _ => wrap_str(pprust::ty_to_string(self), context.config.max_width, |
