mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 20:34:06 +00:00
Stop extra newlines from being added after block comments (#1185)
This commit is contained in:
parent
4b1c669037
commit
1c83c76015
@ -144,8 +144,13 @@ impl<'a> FmtVisitor<'a> {
|
||||
line_start = offset + subslice.len();
|
||||
|
||||
if let Some('/') = subslice.chars().skip(1).next() {
|
||||
// Add a newline after line comments
|
||||
self.buffer.push_str("\n");
|
||||
// check that there are no contained block comments
|
||||
if !subslice.split('\n')
|
||||
.map(|s| s.trim_left())
|
||||
.any(|s| s.len() > 2 && &s[0..2] == "/*") {
|
||||
// Add a newline after line comments
|
||||
self.buffer.push_str("\n");
|
||||
}
|
||||
} else if line_start <= snippet.len() {
|
||||
// For other comments add a newline if there isn't one at the end already
|
||||
match snippet[line_start..].chars().next() {
|
||||
|
6
tests/source/issue-1177.rs
Normal file
6
tests/source/issue-1177.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
// Line Comment
|
||||
/* Block Comment */
|
||||
|
||||
let d = 5;
|
||||
}
|
6
tests/target/issue-1177.rs
Normal file
6
tests/target/issue-1177.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
// Line Comment
|
||||
// Block Comment
|
||||
|
||||
let d = 5;
|
||||
}
|
Loading…
Reference in New Issue
Block a user