Merge pull request #505 from tikue/master

Fix doc comment regression and add tests.
This commit is contained in:
Marcus Klaas de Vries 2015-10-20 20:14:27 +02:00
commit 8e2547b6bc
5 changed files with 23 additions and 2 deletions

View File

@ -27,6 +27,10 @@ pub fn rewrite_comment(orig: &str,
// Edge case: block comments. Let's not trim their lines (for now).
let (opener, closer, line_start) = if block_style {
("/* ", " */", " * ")
} else if orig.starts_with("///") {
("/// ", "", "/// ")
} else if orig.starts_with("//!") {
("//! ", "", "//! ")
} else {
("// ", "", "// ")
};
@ -81,7 +85,7 @@ pub fn rewrite_comment(orig: &str,
let rewrite = try_opt!(rewrite_string(line, &fmt));
result.push_str(&rewrite);
} else {
if line.len() == 0 || line.starts_with('!') {
if line.len() == 0 {
// Remove space if this is an empty comment or a doc comment.
result.pop();
}
@ -97,7 +101,10 @@ pub fn rewrite_comment(orig: &str,
}
fn left_trim_comment_line(line: &str) -> &str {
if line.starts_with("/* ") || line.starts_with("// ") {
if line.starts_with("//! ") || line.starts_with("/// ") {
&line[4..]
} else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") ||
line.starts_with("///") {
&line[3..]
} else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") {
&line[2..]

2
tests/source/comment2.rs Normal file
View File

@ -0,0 +1,2 @@
/// This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly and justly.
pub mod foo {}

3
tests/source/comment3.rs Normal file
View File

@ -0,0 +1,3 @@
//! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly and justly.
pub mod foo {}

4
tests/target/comment2.rs Normal file
View File

@ -0,0 +1,4 @@
/// This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
/// and justly.
pub mod foo {
}

5
tests/target/comment3.rs Normal file
View File

@ -0,0 +1,5 @@
//! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
//! and justly.
pub mod foo {
}