Skip to content

Commit

Permalink
fix(nargo_fmt): let doc comment could come after regular comment (#7046)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Jan 13, 2025
1 parent 18ea051 commit c3f8a46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions noir_stdlib/src/collections/umap.nr
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ impl<K, V, B> UHashMap<K, V, B> {
{
// docs:end:contains_key
/// Safety: unconstrained context
unsafe { self.get(key) }
.is_some()
unsafe { self.get(key) }.is_some()
}

// Returns true if the map contains no elements.
Expand Down
22 changes: 22 additions & 0 deletions tooling/nargo_fmt/src/formatter/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ impl<'a, 'b> ChunkFormatter<'a, 'b> {

// Now write any leading comment respecting multiple newlines after them
group.leading_comment(self.chunk(|formatter| {
// Doc comments for a let statement could come before a potential non-doc comment
if formatter.token.kind() == TokenKind::OuterDocComment {
formatter.format_outer_doc_comments();
}

formatter.skip_comments_and_whitespace_writing_multiple_lines_if_found();

// Or doc comments could come after a potential non-doc comment
if formatter.token.kind() == TokenKind::OuterDocComment {
formatter.format_outer_doc_comments();
}
}));

ignore_next |= self.ignore_next;
Expand Down Expand Up @@ -390,6 +397,21 @@ mod tests {
assert_format(src, expected);
}

#[test]
fn format_let_statement_with_unsafe_and_comment_before_it() {
let src = " fn foo() {
// Some comment
/// Safety: some doc
let x = unsafe { 1 } ; } ";
let expected = "fn foo() {
// Some comment
/// Safety: some doc
let x = unsafe { 1 };
}
";
assert_format(src, expected);
}

#[test]
fn format_assign() {
let src = " fn foo() { x = 2 ; } ";
Expand Down

0 comments on commit c3f8a46

Please sign in to comment.