diff --git a/src/types.rs b/src/types.rs index 9ba50a59cd9..28465404988 100644 --- a/src/types.rs +++ b/src/types.rs @@ -15,7 +15,7 @@ use syntax::codemap::{self, Span, BytePos, CodeMap}; use Indent; use lists::{itemize_list, write_list, ListFormatting}; use rewrite::{Rewrite, RewriteContext}; -use utils::{extra_offset, span_after}; +use utils::{extra_offset, span_after, format_mutability}; impl Rewrite for ast::Path { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option { @@ -437,9 +437,39 @@ impl Rewrite for ast::Ty { p.rewrite(context, width, offset) } ast::TyObjectSum(ref ty, ref bounds) => { + let ty_str = try_opt!(ty.rewrite(context, width, offset)); + let overhead = ty_str.len() + 3; Some(format!("{} + {}", - try_opt!(ty.rewrite(context, width, offset)), - try_opt!(bounds.rewrite(context, width, offset)))) + ty_str, + try_opt!(bounds.rewrite(context, + try_opt!(width.checked_sub(overhead)), + offset + overhead)))) + } + ast::TyRptr(ref lifetime, ref mt) => { + let mut_str = format_mutability(mt.mutbl); + let mut_len = mut_str.len(); + Some(match lifetime { + &Some(ref lifetime) => { + let lt_str = pprust::lifetime_to_string(lifetime); + let lt_len = lt_str.len(); + format!("&{} {}{}", + lt_str, + mut_str, + try_opt!(mt.ty.rewrite(context, + width - (2 + mut_len + lt_len), + offset + 2 + mut_len + lt_len))) + } + &None => { + format!("&{}{}", + mut_str, + try_opt!(mt.ty.rewrite(context, + width - (1 + mut_len), + offset + 1 + mut_len))) + } + }) + } + ast::TyParen(ref ty) => { + ty.rewrite(context, width - 2, offset + 1).map(|ty_str| format!("({})", ty_str)) } _ => Some(pprust::ty_to_string(self)), } diff --git a/tests/source/multiple.rs b/tests/source/multiple.rs index abc16035be2..a0a3f2599e8 100644 --- a/tests/source/multiple.rs +++ b/tests/source/multiple.rs @@ -92,6 +92,8 @@ pub struct Foo<'a, Y: Baz> f: SomeType, // Comment beside a field } +fn foo(ann: &'a (PpAnn+'a)) {} + fn main() { for i in 0i32..4 { println!("{}", i); diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index 9ff3f2cf7a8..c2e2a471afc 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -117,6 +117,9 @@ pub struct Foo<'a, Y: Baz> f: SomeType, // Comment beside a field } +fn foo(ann: &'a (PpAnn + 'a)) { +} + fn main() { for i in 0i32..4 { println!("{}", i);