Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tooling/nargo_fmt/src/formatter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ mod tests {
assert_format(src, expected);
}

#[test]
fn format_trait_with_function_with_multiple_where_clauses() {
let src = " mod moo { trait Foo {
fn foo<T> () where A: B, C: D;
} }";
let expected = "mod moo {
trait Foo {
fn foo<T>()
where
A: B,
C: D;
}
}
";
assert_format(src, expected);
}

#[test]
fn format_trait_with_function_with_visibility() {
let src = " mod moo { trait Foo {
Expand Down
7 changes: 5 additions & 2 deletions tooling/nargo_fmt/src/formatter/where_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl<'a> Formatter<'a> {
// To format it we'll have to skip the second type `F` if we find a `+` token.
let mut write_type = true;

for constraint in constraints {
let constrains_len = constraints.len();
for (index, constraint) in constraints.into_iter().enumerate() {
if write_type {
self.write_line();
self.write_indentation();
Expand All @@ -45,7 +46,9 @@ impl<'a> Formatter<'a> {

write_type = true;

if self.is_at(Token::Comma) {
if index < constrains_len - 1 {
self.write_token(Token::Comma);
} else if self.is_at(Token::Comma) {
if write_trailing_comma_and_new_line {
self.write_token(Token::Comma);
} else {
Expand Down