1
Fork 0

Fix syntax in -Zunpretty-expanded output for derived PartialEq.

If you do `derive(PartialEq)` on a packed struct, the output shown by
`-Zunpretty=expanded` includes expressions like this:
```
{ self.x } == { other.x }
```
This is invalid syntax. This doesn't break compilation, because the AST
nodes are constructed within the compiler. But it does mean anyone using
`-Zunpretty=expanded` output as a guide for hand-written impls could get
a nasty surprise.

This commit fixes things by instead using this form:
```
({ self.x }) == ({ other.x })
```
This commit is contained in:
Nicholas Nethercote 2023-01-30 16:29:52 +11:00
parent a322848c6b
commit 75e87d1f81
3 changed files with 26 additions and 8 deletions

View file

@ -272,6 +272,10 @@ impl<'a> ExtCtxt<'a> {
self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e))
}
pub fn expr_paren(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
self.expr(sp, ast::ExprKind::Paren(e))
}
pub fn expr_call(
&self,
span: Span,