diff --git a/src/lib.rs b/src/lib.rs index fdf08c001a3f..c075589e99c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ #![feature(rustc_private)] #![feature(custom_attribute)] #![feature(slice_splits)] +#![feature(slice_patterns)] #![feature(catch_panic)] #![allow(unused_attributes)] diff --git a/src/types.rs b/src/types.rs index 69ee7193ab23..2b757671a139 100644 --- a/src/types.rs +++ b/src/types.rs @@ -484,22 +484,16 @@ impl Rewrite for ast::Ty { ty.rewrite(context, budget, offset + 1).map(|ty_str| format!("({})", ty_str)) } ast::TyTup(ref tup_ret) => { - let inner = try_opt!(tup_ret.iter() - .map(|item| item.rewrite(context, width, offset)) - .fold(Some("".to_owned()), - |sum, x| { - match (sum, x) { - (Some(sum), Some(x)) => { - if sum == "" { - // First item. - Some(x) - } else { - Some(sum + ", " + &x) - } - } - _ => None, - } - })); + let inner = if let [ref item] = &**tup_ret { + try_opt!(item.rewrite(context, width, offset)) + "," + } else { + let rewrites: Option>; + 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) diff --git a/tests/target/fn_once.rs b/tests/target/fn_once.rs new file mode 100644 index 000000000000..42b8f98e78ab --- /dev/null +++ b/tests/target/fn_once.rs @@ -0,0 +1,8 @@ +struct Add(usize); + +impl FnOnce<(usize,)> for Add { + type Output = Add; + extern "rust-call" fn call_once(self, to: (usize,)) -> Add { + Add(self.0 + to.0) + } +}