Merge pull request #402 from tikue/master

Fix 1-tuple regression.
This commit is contained in:
Marcus Klaas de Vries 2015-10-02 08:44:21 +02:00
commit fff0be2f82
3 changed files with 19 additions and 16 deletions

View file

@ -11,6 +11,7 @@
#![feature(rustc_private)]
#![feature(custom_attribute)]
#![feature(slice_splits)]
#![feature(slice_patterns)]
#![feature(catch_panic)]
#![allow(unused_attributes)]

View file

@ -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<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)

8
tests/target/fn_once.rs Normal file
View file

@ -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)
}
}