Skip to content

Commit

Permalink
syntax: Improve --pretty normal slightly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed May 14, 2014
1 parent 25ac81e commit 6878039
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,17 @@ 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());
buf
}
ty_tup(ref elems) => {
let strs: Vec<StrBuf> = 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)
Expand Down
10 changes: 8 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "$("));
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 6878039

Please sign in to comment.