Avoid some unnecessary blocks in derive output.

This commit is contained in:
Nicholas Nethercote 2022-07-08 15:27:42 +10:00
parent 56178d4259
commit f1d9e2b50c
2 changed files with 14 additions and 9 deletions

View File

@ -339,11 +339,19 @@ fn into_block(mut self, cx: &ExtCtxt<'_>, span: Span) -> P<ast::Block> {
// Converts it into an expression.
fn into_expr(self, cx: &ExtCtxt<'_>, span: Span) -> P<Expr> {
if self.0.is_empty() {
// No statements.
match self.1 {
None => cx.expr_block(cx.block(span, vec![])),
Some(expr) => expr,
}
} else if self.0.len() == 1
&& let ast::StmtKind::Expr(expr) = &self.0[0].kind
&& self.1.is_none()
{
// There's only a single statement expression. Pull it out.
expr.clone()
} else {
// Multiple statements and/or expressions.
cx.expr_block(self.into_block(cx, span))
}
}

View File

@ -697,9 +697,8 @@ impl ::core::fmt::Debug for Enum1 {
impl ::core::hash::Hash for Enum1 {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match self {
Enum1::Single { x: __self_0 } => {
::core::hash::Hash::hash(__self_0, state)
}
Enum1::Single { x: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}
@ -870,10 +869,9 @@ impl ::core::default::Default for Fieldless {
impl ::core::hash::Hash for Fieldless {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match self {
_ => {
_ =>
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
state),
}
}
}
@ -992,10 +990,9 @@ impl ::core::hash::Hash for Mixed {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
_ => {
_ =>
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
state),
}
}
}