Fix invalid printer IR error (#5422)

This commit is contained in:
Micha Reiser 2023-06-29 08:09:13 +02:00 committed by GitHub
parent ca5e10b5ea
commit 38189ed913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 18 deletions

View file

@ -242,23 +242,25 @@ impl<'fmt, 'ast, 'buf> JoinCommaSeparatedBuilder<'fmt, 'ast, 'buf> {
}
pub(crate) fn finish(&mut self) -> FormatResult<()> {
if let Some(last_end) = self.last_end.take() {
if_group_breaks(&text(",")).fmt(self.fmt)?;
self.result.and_then(|_| {
if let Some(last_end) = self.last_end.take() {
if_group_breaks(&text(",")).fmt(self.fmt)?;
if self.fmt.options().magic_trailing_comma().is_respect()
&& matches!(
first_non_trivia_token(last_end, self.fmt.context().contents()),
Some(Token {
kind: TokenKind::Comma,
..
})
)
{
expand_parent().fmt(self.fmt)?;
if self.fmt.options().magic_trailing_comma().is_respect()
&& matches!(
first_non_trivia_token(last_end, self.fmt.context().contents()),
Some(Token {
kind: TokenKind::Comma,
..
})
)
{
expand_parent().fmt(self.fmt)?;
}
}
}
Ok(())
Ok(())
})
}
}