Skip to content

Commit

Permalink
Treat comments inside function signatures as inline by default
Browse files Browse the repository at this point in the history
  • Loading branch information
parno committed Feb 1, 2024
1 parent b6dec8d commit 5395ef2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
13 changes: 10 additions & 3 deletions examples/wip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
verus! {

const y: int = 5;

// Comment
const x: int = 5;

impl a {
fn b()
//
// My favorite function
fn b() //
;
}
}

} // verus!
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ fn comment_to_doc<'a>(
arena: &'a Arena<'a, ()>,
pair: Pair<'a, Rule>,
add_newline: bool,
treat_as_inline: bool,
) -> DocBuilder<'a, Arena<'a>> {
assert!(matches!(pair.as_rule(), Rule::COMMENT));
let (line, _col) = pair.line_col();
let s = arena.text(pair.as_str().trim());
if ctx.inline_comment_lines.contains(&line) {
if ctx.inline_comment_lines.contains(&line) || treat_as_inline {
debug!(
"contains(line = <<{}>>), with {}",
pair.as_str(),
Expand Down Expand Up @@ -799,6 +800,7 @@ fn to_doc<'a>(
!has_qualifier
|| !saw_comment_after_param_list
|| (has_ret_type && pre_ret_type),
true,
)
}
Rule::param_list => {
Expand Down Expand Up @@ -1155,7 +1157,7 @@ fn to_doc<'a>(
Rule::trigger_attribute => unsupported(pair),

Rule::WHITESPACE => arena.nil(),
Rule::COMMENT => comment_to_doc(ctx, arena, pair, true),
Rule::COMMENT => comment_to_doc(ctx, arena, pair, true, false),
Rule::multiline_comment => s.append(arena.line()),
Rule::verus_macro_body => items_to_doc(ctx, arena, pair, false),
Rule::file | Rule::non_verus | Rule::verus_macro_use | Rule::EOI => unreachable!(),
Expand Down
23 changes: 23 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,18 @@ impl AbstractEndPoint {
}
}
const y: int = 5;
// Comment
const x: int = 5;
impl a {
// My favorite function
fn b()
//
;
}
} // verus!
"#;

Expand Down Expand Up @@ -1013,6 +1025,17 @@ impl AbstractEndPoint {
}
}
const y: int = 5;
// Comment
const x: int = 5;
impl a {
// My favorite function
fn b() //
;
}
} // verus!
"###);
}
Expand Down

0 comments on commit 5395ef2

Please sign in to comment.