Skip to content

Commit ac6871f

Browse files
authored
Merge pull request #3048 from emilio/merged-comments
lists: Detect block comment by starting from the end.
2 parents 1e60c61 + 66c15e4 commit ac6871f

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/lists.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,9 @@ where
566566

567567
pub fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListItemCommentStyle) {
568568
let trimmed_pre_snippet = pre_snippet.trim();
569+
let has_block_comment = trimmed_pre_snippet.ends_with("*/");
569570
let has_single_line_comment = trimmed_pre_snippet.starts_with("//");
570-
let has_block_comment = trimmed_pre_snippet.starts_with("/*");
571-
if has_single_line_comment {
572-
(
573-
Some(trimmed_pre_snippet.to_owned()),
574-
ListItemCommentStyle::DifferentLine,
575-
)
576-
} else if has_block_comment {
571+
if has_block_comment {
577572
let comment_end = pre_snippet.chars().rev().position(|c| c == '/').unwrap();
578573
if pre_snippet
579574
.chars()
@@ -591,6 +586,11 @@ pub fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListItemCommen
591586
ListItemCommentStyle::SameLine,
592587
)
593588
}
589+
} else if has_single_line_comment {
590+
(
591+
Some(trimmed_pre_snippet.to_owned()),
592+
ListItemCommentStyle::DifferentLine,
593+
)
594594
} else {
595595
(None, ListItemCommentStyle::None)
596596
}

tests/source/expr-block.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,21 @@ fn issue_1862() {
280280
)
281281
}
282282

283+
fn issue_3025() {
284+
foo(
285+
// This describes the argument below.
286+
/* bar = */ None ,
287+
// This describes the argument below.
288+
something_something,
289+
// This describes the argument below. */
290+
None ,
291+
// This describes the argument below.
292+
/* This comment waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long to be kept on the same line */ None ,
293+
// This describes the argument below.
294+
/* com */ this_last_arg_is_tooooooooooooooooooooooooooooooooo_long_to_be_kept_with_the_pre_comment ,
295+
)
296+
}
297+
283298
fn issue_1878() {
284299
let channel: &str = seq.next_element()?.ok_or_else(|| de::Error::invalid_length(2, &self))?;
285300
}

tests/target/expr-block.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ fn issue_1862() {
281281
)
282282
}
283283

284+
fn issue_3025() {
285+
foo(
286+
// This describes the argument below.
287+
/* bar = */ None,
288+
// This describes the argument below.
289+
something_something,
290+
// This describes the argument below. */
291+
None,
292+
// This describes the argument below.
293+
/* This comment waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long to be kept on the same line */
294+
None,
295+
// This describes the argument below.
296+
/* com */
297+
this_last_arg_is_tooooooooooooooooooooooooooooooooo_long_to_be_kept_with_the_pre_comment,
298+
)
299+
}
300+
284301
fn issue_1878() {
285302
let channel: &str = seq
286303
.next_element()?

0 commit comments

Comments
 (0)