Skip to content

Commit eeb062b

Browse files
committed
Auto merge of #31746 - erickt:newline, r=sfackler
syntax: Always pretty print a newline after doc comments Before this patch, code that had a doc comment as the first line, as in: ```rust /// Foo struct Foo; ``` Was pretty printed into: ```rust ///Foostruct Foo; ``` This makes sure that that there is always a trailing newline after a doc comment. Closes #31722
2 parents fd5603b + 0e3334e commit eeb062b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ pub trait PrintState<'a> {
752752
}
753753
try!(self.maybe_print_comment(attr.span.lo));
754754
if attr.node.is_sugared_doc {
755-
word(self.writer(), &attr.value_str().unwrap())
755+
try!(word(self.writer(), &attr.value_str().unwrap()));
756+
hardbreak(self.writer())
756757
} else {
757758
match attr.node.style {
758759
ast::AttrStyle::Inner => try!(word(self.writer(), "#![")),
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// Some doc comment.
2+
struct X;
3+
4+
// ignore-license
5+
6+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
7+
// file at the top-level directory of this distribution and at
8+
// http://rust-lang.org/COPYRIGHT.
9+
//
10+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
11+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
12+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
13+
// option. This file may not be copied, modified, or distributed
14+
// except according to those terms.
15+
16+
// pp-exact
17+
18+
// Test that rust can properly pretty print a doc comment if it's the first line in a file. some
19+
20+
fn main() { let x = X; }

0 commit comments

Comments
 (0)