Skip to content

Commit

Permalink
fix: Only treat multi-line comments as inline if the entire comment i…
Browse files Browse the repository at this point in the history
…s on a single line. (#35)
  • Loading branch information
parno authored Feb 27, 2024
2 parents ad8fbf7 + e59dad4 commit f30fea9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion examples/wip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
verus! {

struct ExManuallyDrop<V: ?Sized>();
fn test() {
let x = 1;/* inline multi-line comment stays inline */
let y = 1; /* Long
dangling
comment doesn't */
}

} // verus!
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ const NONINLINE_COMMENT_DST: &str = "FORMATTER_NOT_INLINE_DST";
// let y = 5;
fn find_inline_comment_lines(s: &str) -> HashSet<usize> {
let mut comment_lines = HashSet::new();
let re_inline_candidate = Regex::new(r"^.*\S.*(//|/\*)").unwrap();
let re_inline_candidate = Regex::new(r"^.*\S.*(//|/\*.*\*/)").unwrap();
let re_spaced_comment = Regex::new(r"^\s*(///|//|/\*)").unwrap();
for (line_num, line) in s.lines().enumerate() {
if re_inline_candidate.captures(line).is_some()
Expand Down Expand Up @@ -1358,9 +1358,12 @@ fn fix_inline_comments(s: String) -> String {
let mut prev_str: String = "".to_string();
let mut first_iteration = true;
let mut comment_replacement = None;
//let mut line_num = 1;

for line in s.lines() {
fixed_str += &prev_str;
//println!("Processing line {}", line_num);
//line_num += 1;
if re_was_inline.is_match(line) {
if is_inline_comment(line) {
// After we formatted the inline comment, it's still inline,
Expand Down
14 changes: 14 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,12 @@ pub fn test() {
}// No space between the one character indicating non-inline and the comment
}
fn test() {
let x = 1;/* inline multi-line comment stays inline */
let y = 1; /* Long
dangling
comment doesn't */
}
} // verus!
"#;
Expand Down Expand Up @@ -1212,6 +1218,14 @@ pub fn test() {
}
fn test() {
let x = 1; /* inline multi-line comment stays inline */
let y = 1;
/* Long
dangling
comment doesn't */
}
} // verus!
"###);
}
Expand Down

0 comments on commit f30fea9

Please sign in to comment.