diff --git a/tooling/nargo_fmt/src/formatter/traits.rs b/tooling/nargo_fmt/src/formatter/traits.rs index 77f991889e1..c40389f35e4 100644 --- a/tooling/nargo_fmt/src/formatter/traits.rs +++ b/tooling/nargo_fmt/src/formatter/traits.rs @@ -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 () where A: B, C: D; + } }"; + let expected = "mod moo { + trait Foo { + fn foo() + where + A: B, + C: D; + } +} +"; + assert_format(src, expected); + } + #[test] fn format_trait_with_function_with_visibility() { let src = " mod moo { trait Foo { diff --git a/tooling/nargo_fmt/src/formatter/where_clause.rs b/tooling/nargo_fmt/src/formatter/where_clause.rs index 538d2ba8c01..927383895b3 100644 --- a/tooling/nargo_fmt/src/formatter/where_clause.rs +++ b/tooling/nargo_fmt/src/formatter/where_clause.rs @@ -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(); @@ -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 {