From c6243c950ee3376f562cc2dd08a3d31c9c3818b2 Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 17 Sep 2016 03:20:00 +0200 Subject: [PATCH] Improve comment rewriting with normalize_comments == false Only change multiline comments of the form ```rust /* * Text */ ``` while not affecting comments of the form ```rust /* Text */ ``` when normalize_comments is off. In the first case, we have a known character we can align against, while we don't have one in the second case. Before, we have converted the second form into the first, but this is against the spirit of normalize_comments being turned off. Fixes #956 --- src/comment.rs | 10 ++++++++++ tests/source/comment4.rs | 12 ++++++++++++ tests/target/comment4.rs | 12 ++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/comment.rs b/src/comment.rs index 979d3bef90e..5a525f1bb23 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -71,6 +71,16 @@ pub fn rewrite_comment(orig: &str, let indent_str = offset.to_string(config); let line_breaks = s.chars().filter(|&c| c == '\n').count(); + let num_bare_lines = s.lines() + .enumerate() + .map(|(_, line)| line.trim()) + .filter(|l| !(l.starts_with('*') || l.starts_with("//") || l.starts_with("/*"))) + .count(); + + if num_bare_lines > 0 && !config.normalize_comments { + return Some(orig.to_owned()); + } + let lines = s.lines() .enumerate() .map(|(i, mut line)| { diff --git a/tests/source/comment4.rs b/tests/source/comment4.rs index 81754f93c4c..0ed18ca8da1 100644 --- a/tests/source/comment4.rs +++ b/tests/source/comment4.rs @@ -33,3 +33,15 @@ fn test() { /// test123 fn doc_comment() { } + +/* +Regression test for issue #956 + +(some very important text) +*/ + +/* +fn debug_function() { + println!("hello"); +} +// */ diff --git a/tests/target/comment4.rs b/tests/target/comment4.rs index c4d25ca1143..910bade6c88 100644 --- a/tests/target/comment4.rs +++ b/tests/target/comment4.rs @@ -32,3 +32,15 @@ fn test() { /// test123 fn doc_comment() {} + +/* +Regression test for issue #956 + +(some very important text) +*/ + +/* +fn debug_function() { + println!("hello"); +} +// */ -- 2.44.0