From 6878039c122211f227d6c42b7f08282629ceb6c4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 11 May 2014 01:34:28 -0700 Subject: [PATCH] syntax: Improve --pretty normal slightly When printing doc comments, always put a newline after them in a macro invocation to ensure that a line-doc-comment doesn't consume remaining tokens on the line. --- src/librustc/util/ppaux.rs | 8 ++++---- src/libsyntax/print/pprust.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index f18f39ac925..95ae05985d3 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -360,9 +360,9 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> StrBuf { ty_uint(t) => ast_util::uint_ty_to_str(t, None, ast_util::AutoSuffix).to_strbuf(), ty_float(t) => ast_util::float_ty_to_str(t).to_strbuf(), - ty_box(typ) => "@".to_strbuf() + ty_to_str(cx, typ), - ty_uniq(typ) => "~".to_strbuf() + ty_to_str(cx, typ), - ty_ptr(ref tm) => "*".to_strbuf() + mt_to_str(cx, tm), + ty_box(typ) => format_strbuf!("@{}", ty_to_str(cx, typ)), + ty_uniq(typ) => format_strbuf!("~{}", ty_to_str(cx, typ)), + ty_ptr(ref tm) => format_strbuf!("*{}", mt_to_str(cx, tm)), ty_rptr(r, ref tm) => { let mut buf = region_ptr_to_str(cx, r); buf.push_str(mt_to_str(cx, tm).as_slice()); @@ -370,7 +370,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> StrBuf { } ty_tup(ref elems) => { let strs: Vec = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect(); - ("(".to_strbuf() + strs.connect(",") + ")").to_strbuf() + format_strbuf!("({})", strs.connect(",")) } ty_closure(ref f) => { closure_to_str(cx, *f) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0b6efcd4f40..15b931d5854 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -841,7 +841,13 @@ impl<'a> State<'a> { match *tt { ast::TTDelim(ref tts) => self.print_tts(tts.as_slice()), ast::TTTok(_, ref tk) => { - word(&mut self.s, parse::token::to_str(tk).as_slice()) + try!(word(&mut self.s, parse::token::to_str(tk).as_slice())); + match *tk { + parse::token::DOC_COMMENT(..) => { + hardbreak(&mut self.s) + } + _ => Ok(()) + } } ast::TTSeq(_, ref tts, ref sep, zerok) => { try!(word(&mut self.s, "$(")); @@ -2238,7 +2244,7 @@ impl<'a> State<'a> { ast::LitUint(u, t) => { word(&mut self.s, ast_util::uint_ty_to_str(t, Some(u), - ast_util::AutoSuffix).as_slice()) + ast_util::ForceSuffix).as_slice()) } ast::LitIntUnsuffixed(i) => { word(&mut self.s, format!("{}", i))