Skip to content

Commit 6878039

Browse files
committed
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.
1 parent 25ac81e commit 6878039

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/librustc/util/ppaux.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,17 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> StrBuf {
360360
ty_uint(t) => ast_util::uint_ty_to_str(t, None,
361361
ast_util::AutoSuffix).to_strbuf(),
362362
ty_float(t) => ast_util::float_ty_to_str(t).to_strbuf(),
363-
ty_box(typ) => "@".to_strbuf() + ty_to_str(cx, typ),
364-
ty_uniq(typ) => "~".to_strbuf() + ty_to_str(cx, typ),
365-
ty_ptr(ref tm) => "*".to_strbuf() + mt_to_str(cx, tm),
363+
ty_box(typ) => format_strbuf!("@{}", ty_to_str(cx, typ)),
364+
ty_uniq(typ) => format_strbuf!("~{}", ty_to_str(cx, typ)),
365+
ty_ptr(ref tm) => format_strbuf!("*{}", mt_to_str(cx, tm)),
366366
ty_rptr(r, ref tm) => {
367367
let mut buf = region_ptr_to_str(cx, r);
368368
buf.push_str(mt_to_str(cx, tm).as_slice());
369369
buf
370370
}
371371
ty_tup(ref elems) => {
372372
let strs: Vec<StrBuf> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
373-
("(".to_strbuf() + strs.connect(",") + ")").to_strbuf()
373+
format_strbuf!("({})", strs.connect(","))
374374
}
375375
ty_closure(ref f) => {
376376
closure_to_str(cx, *f)

src/libsyntax/print/pprust.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,13 @@ impl<'a> State<'a> {
841841
match *tt {
842842
ast::TTDelim(ref tts) => self.print_tts(tts.as_slice()),
843843
ast::TTTok(_, ref tk) => {
844-
word(&mut self.s, parse::token::to_str(tk).as_slice())
844+
try!(word(&mut self.s, parse::token::to_str(tk).as_slice()));
845+
match *tk {
846+
parse::token::DOC_COMMENT(..) => {
847+
hardbreak(&mut self.s)
848+
}
849+
_ => Ok(())
850+
}
845851
}
846852
ast::TTSeq(_, ref tts, ref sep, zerok) => {
847853
try!(word(&mut self.s, "$("));
@@ -2238,7 +2244,7 @@ impl<'a> State<'a> {
22382244
ast::LitUint(u, t) => {
22392245
word(&mut self.s,
22402246
ast_util::uint_ty_to_str(t, Some(u),
2241-
ast_util::AutoSuffix).as_slice())
2247+
ast_util::ForceSuffix).as_slice())
22422248
}
22432249
ast::LitIntUnsuffixed(i) => {
22442250
word(&mut self.s, format!("{}", i))

0 commit comments

Comments
 (0)