1
Fork 0

Fix formatting empty block comments (/**/)

issue #1086
This commit is contained in:
sinkuu 2016-07-09 22:41:28 +09:00
parent ffa5a22d1c
commit 0dc3fc7a2c
3 changed files with 14 additions and 4 deletions

View file

@ -33,7 +33,7 @@ pub fn rewrite_comment(orig: &str,
if block_style { if block_style {
("/* ", " */", " * ") ("/* ", " */", " * ")
} else if !config.normalize_comments { } else if !config.normalize_comments {
if orig.starts_with("/**") { if orig.starts_with("/**") && !orig.starts_with("/**/") {
("/** ", " **/", " ** ") ("/** ", " **/", " ** ")
} else if orig.starts_with("/*!") { } else if orig.starts_with("/*!") {
("/*! ", " */", " * ") ("/*! ", " */", " * ")
@ -46,7 +46,8 @@ pub fn rewrite_comment(orig: &str,
} else { } else {
("// ", "", "// ") ("// ", "", "// ")
} }
} else if orig.starts_with("///") || orig.starts_with("/**") { } else if orig.starts_with("///") ||
(orig.starts_with("/**") && !orig.starts_with("/**/")) {
("/// ", "", "/// ") ("/// ", "", "/// ")
} else if orig.starts_with("//!") || orig.starts_with("/*!") { } else if orig.starts_with("//!") || orig.starts_with("/*!") {
("//! ", "", "//! ") ("//! ", "", "//! ")
@ -130,7 +131,7 @@ fn left_trim_comment_line(line: &str) -> &str {
} else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") || } else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") ||
line.starts_with("///") || line.starts_with("///") ||
line.starts_with("** ") || line.starts_with("/*!") || line.starts_with("** ") || line.starts_with("/*!") ||
line.starts_with("/**") { (line.starts_with("/**") && !line.starts_with("/**/")) {
&line[3..] &line[3..]
} else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") || } else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") ||
line.starts_with("**") { line.starts_with("**") {
@ -606,7 +607,8 @@ fn remove_comment_header(comment: &str) -> &str {
&comment[3..] &comment[3..]
} else if comment.starts_with("//") { } else if comment.starts_with("//") {
&comment[2..] &comment[2..]
} else if comment.starts_with("/**") || comment.starts_with("/*!") { } else if (comment.starts_with("/**") && !comment.starts_with("/**/")) ||
comment.starts_with("/*!") {
&comment[3..comment.len() - 2] &comment[3..comment.len() - 2]
} else { } else {
assert!(comment.starts_with("/*"), assert!(comment.starts_with("/*"),

View file

@ -43,6 +43,10 @@ fn chains() {
/* comment */ x }) /* comment */ x })
} }
fn issue_1086() {
/**/
}
/* /*
* random comment */ * random comment */

View file

@ -45,6 +45,10 @@ fn chains() {
}) })
} }
fn issue_1086() {
//
}
// random comment // random comment
fn main() { fn main() {