Skip to content

Pretty printer improvements #14106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
alexcrichton committed May 13, 2014
commit 5de4b87f4b55f9d063e9ccb9f18b38f41a87c84c
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