Skip to content

Commit c3f8a46

Browse files
authored
fix(nargo_fmt): let doc comment could come after regular comment (#7046)
1 parent 18ea051 commit c3f8a46

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

noir_stdlib/src/collections/umap.nr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ impl<K, V, B> UHashMap<K, V, B> {
114114
{
115115
// docs:end:contains_key
116116
/// Safety: unconstrained context
117-
unsafe { self.get(key) }
118-
.is_some()
117+
unsafe { self.get(key) }.is_some()
119118
}
120119

121120
// Returns true if the map contains no elements.

tooling/nargo_fmt/src/formatter/statement.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ impl<'a, 'b> ChunkFormatter<'a, 'b> {
2323

2424
// Now write any leading comment respecting multiple newlines after them
2525
group.leading_comment(self.chunk(|formatter| {
26+
// Doc comments for a let statement could come before a potential non-doc comment
2627
if formatter.token.kind() == TokenKind::OuterDocComment {
2728
formatter.format_outer_doc_comments();
2829
}
30+
2931
formatter.skip_comments_and_whitespace_writing_multiple_lines_if_found();
32+
33+
// Or doc comments could come after a potential non-doc comment
34+
if formatter.token.kind() == TokenKind::OuterDocComment {
35+
formatter.format_outer_doc_comments();
36+
}
3037
}));
3138

3239
ignore_next |= self.ignore_next;
@@ -390,6 +397,21 @@ mod tests {
390397
assert_format(src, expected);
391398
}
392399

400+
#[test]
401+
fn format_let_statement_with_unsafe_and_comment_before_it() {
402+
let src = " fn foo() {
403+
// Some comment
404+
/// Safety: some doc
405+
let x = unsafe { 1 } ; } ";
406+
let expected = "fn foo() {
407+
// Some comment
408+
/// Safety: some doc
409+
let x = unsafe { 1 };
410+
}
411+
";
412+
assert_format(src, expected);
413+
}
414+
393415
#[test]
394416
fn format_assign() {
395417
let src = " fn foo() { x = 2 ; } ";

0 commit comments

Comments
 (0)