Skip to content

Commit

Permalink
fix: format global attributes (#7401)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Feb 14, 2025
1 parent b2b632b commit b7ace68
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ contract Foo {

#[abi(bar)]
pub struct Bar {
inner: Field
inner: Field,
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
contract Foo {
pub struct T { x: [Field] }
pub struct T {
x: [Field],
}

impl T {
fn t(self) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
contract Foo {
pub struct PlaceholderStruct{x : u32 }
pub struct PlaceholderStruct {
x: u32,
}

#[contract_library_method]
pub fn has_mut(_context: &mut PlaceholderStruct) {}
Expand Down
2 changes: 1 addition & 1 deletion test_programs/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo "[workspace]" > Nargo.toml
echo "members = [" >> Nargo.toml

collect_dirs compile_success_empty
# collect_dirs compile_success_contract
collect_dirs compile_success_contract
collect_dirs compile_success_no_bug
collect_dirs compile_success_with_bug
collect_dirs execution_success
Expand Down
11 changes: 11 additions & 0 deletions tooling/nargo_fmt/src/formatter/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ impl<'a> Formatter<'a> {
let_statement: LetStatement,
visibility: ItemVisibility,
) {
self.format_secondary_attributes(let_statement.attributes.clone());

let group = self.chunk_formatter().format_global(let_statement, visibility);
self.write_indentation();
self.format_chunk_group(group);
Expand Down Expand Up @@ -99,4 +101,13 @@ mod tests {
let expected = "pub comptime mut global x: Field = 1;\n";
assert_format(src, expected);
}

#[test]
fn format_global_with_attributes() {
let src = " #[abi ( foo ) ] global x = 1 ; ";
let expected = "#[abi(foo)]
global x = 1;
";
assert_format(src, expected);
}
}

1 comment on commit b7ace68

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: b7ace68 Previous: b2b632b Ratio
AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types 60 s 46 s 1.30

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Please sign in to comment.