Skip to content

Commit

Permalink
Merge pull request rust-lang#3048 from emilio/merged-comments
Browse files Browse the repository at this point in the history
lists: Detect block comment by starting from the end.
  • Loading branch information
nrc authored Sep 24, 2018
2 parents 1e60c61 + 66c15e4 commit ac6871f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,9 @@ where

pub fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListItemCommentStyle) {
let trimmed_pre_snippet = pre_snippet.trim();
let has_block_comment = trimmed_pre_snippet.ends_with("*/");
let has_single_line_comment = trimmed_pre_snippet.starts_with("//");
let has_block_comment = trimmed_pre_snippet.starts_with("/*");
if has_single_line_comment {
(
Some(trimmed_pre_snippet.to_owned()),
ListItemCommentStyle::DifferentLine,
)
} else if has_block_comment {
if has_block_comment {
let comment_end = pre_snippet.chars().rev().position(|c| c == '/').unwrap();
if pre_snippet
.chars()
Expand All @@ -591,6 +586,11 @@ pub fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListItemCommen
ListItemCommentStyle::SameLine,
)
}
} else if has_single_line_comment {
(
Some(trimmed_pre_snippet.to_owned()),
ListItemCommentStyle::DifferentLine,
)
} else {
(None, ListItemCommentStyle::None)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/source/expr-block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,21 @@ fn issue_1862() {
)
}

fn issue_3025() {
foo(
// This describes the argument below.
/* bar = */ None ,
// This describes the argument below.
something_something,
// This describes the argument below. */
None ,
// This describes the argument below.
/* This comment waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long to be kept on the same line */ None ,
// This describes the argument below.
/* com */ this_last_arg_is_tooooooooooooooooooooooooooooooooo_long_to_be_kept_with_the_pre_comment ,
)
}

fn issue_1878() {
let channel: &str = seq.next_element()?.ok_or_else(|| de::Error::invalid_length(2, &self))?;
}
17 changes: 17 additions & 0 deletions tests/target/expr-block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ fn issue_1862() {
)
}

fn issue_3025() {
foo(
// This describes the argument below.
/* bar = */ None,
// This describes the argument below.
something_something,
// This describes the argument below. */
None,
// This describes the argument below.
/* This comment waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long to be kept on the same line */
None,
// This describes the argument below.
/* com */
this_last_arg_is_tooooooooooooooooooooooooooooooooo_long_to_be_kept_with_the_pre_comment,
)
}

fn issue_1878() {
let channel: &str = seq
.next_element()?
Expand Down

0 comments on commit ac6871f

Please sign in to comment.