mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 03:03:21 +00:00
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
This commit is contained in:
parent
efd3e5c091
commit
c6243c950e
@ -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)| {
|
||||
|
@ -33,3 +33,15 @@ fn test() {
|
||||
/// test123
|
||||
fn doc_comment() {
|
||||
}
|
||||
|
||||
/*
|
||||
Regression test for issue #956
|
||||
|
||||
(some very important text)
|
||||
*/
|
||||
|
||||
/*
|
||||
fn debug_function() {
|
||||
println!("hello");
|
||||
}
|
||||
// */
|
||||
|
@ -32,3 +32,15 @@ fn test() {
|
||||
|
||||
/// test123
|
||||
fn doc_comment() {}
|
||||
|
||||
/*
|
||||
Regression test for issue #956
|
||||
|
||||
(some very important text)
|
||||
*/
|
||||
|
||||
/*
|
||||
fn debug_function() {
|
||||
println!("hello");
|
||||
}
|
||||
// */
|
||||
|
Loading…
Reference in New Issue
Block a user