From e2f5d4a8c97230a54b9a95341bb6d833173f75e6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 10 Dec 2023 17:23:22 -0800 Subject: [PATCH] Include empty 'stmts = []' in snapshots --- codegen/src/snapshot.rs | 4 +++- tests/debug/gen.rs | 4 +--- tests/test_asyncness.rs | 8 ++++++-- tests/test_generics.rs | 4 +++- tests/test_item.rs | 8 ++++++-- tests/test_shebang.rs | 8 ++++++-- tests/test_stmt.rs | 12 +++++++++--- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/codegen/src/snapshot.rs b/codegen/src/snapshot.rs index 7fa42f0c0c..5bda15a619 100644 --- a/codegen/src/snapshot.rs +++ b/codegen/src/snapshot.rs @@ -263,7 +263,9 @@ fn expand_impl_body(defs: &Definitions, node: &Node, name: &str, val: &Operand) let mut call = quote! { formatter.field(#f, #format); }; - if let Type::Vec(_) | Type::Punctuated(_) = ty { + if node.ident == "Block" && f == "stmts" { + // Format regardless of whether is_empty(). + } else if let Type::Vec(_) | Type::Punctuated(_) = ty { call = quote! { if !#val.#ident.is_empty() { #call diff --git a/tests/debug/gen.rs b/tests/debug/gen.rs index 3f92598d7d..95ac837157 100644 --- a/tests/debug/gen.rs +++ b/tests/debug/gen.rs @@ -301,9 +301,7 @@ impl Debug for Lite { impl Debug for Lite { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let mut formatter = formatter.debug_struct("Block"); - if !self.value.stmts.is_empty() { - formatter.field("stmts", Lite(&self.value.stmts)); - } + formatter.field("stmts", Lite(&self.value.stmts)); formatter.finish() } } diff --git a/tests/test_asyncness.rs b/tests/test_asyncness.rs index 6bc5a16370..9968934490 100644 --- a/tests/test_asyncness.rs +++ b/tests/test_asyncness.rs @@ -18,7 +18,9 @@ fn test_async_fn() { generics: Generics, output: ReturnType::Default, }, - block: Block, + block: Block { + stmts: [], + }, } "###); } @@ -32,7 +34,9 @@ fn test_async_closure() { asyncness: Some, output: ReturnType::Default, body: Expr::Block { - block: Block, + block: Block { + stmts: [], + }, }, } "###); diff --git a/tests/test_generics.rs b/tests/test_generics.rs index 51119adc84..b9bb75ef15 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -243,7 +243,9 @@ fn test_fn_precedence_in_where_clause() { }, output: ReturnType::Default, }, - block: Block, + block: Block { + stmts: [], + }, } "###); diff --git a/tests/test_item.rs b/tests/test_item.rs index 9b0e1c9ff0..11d4ba484b 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -38,7 +38,9 @@ fn test_macro_variable_attr() { generics: Generics, output: ReturnType::Default, }, - block: Block, + block: Block { + stmts: [], + }, } "###); } @@ -320,7 +322,9 @@ fn test_impl_trait_trailing_plus() { }, ), }, - block: Block, + block: Block { + stmts: [], + }, } "###); } diff --git a/tests/test_shebang.rs b/tests/test_shebang.rs index 4c2a204573..843916180f 100644 --- a/tests/test_shebang.rs +++ b/tests/test_shebang.rs @@ -18,7 +18,9 @@ fn test_basic() { generics: Generics, output: ReturnType::Default, }, - block: Block, + block: Block { + stmts: [], + }, }, ], } @@ -55,7 +57,9 @@ fn test_comment() { generics: Generics, output: ReturnType::Default, }, - block: Block, + block: Block { + stmts: [], + }, }, ], } diff --git a/tests/test_stmt.rs b/tests/test_stmt.rs index b27ee581ed..6223a6dfaa 100644 --- a/tests/test_stmt.rs +++ b/tests/test_stmt.rs @@ -78,7 +78,9 @@ fn test_none_group() { generics: Generics, output: ReturnType::Default, }, - block: Block, + block: Block { + stmts: [], + }, }) "###); } @@ -251,7 +253,9 @@ fn test_early_parse_loop() { [ Stmt::Expr( Expr::Loop { - body: Block, + body: Block { + stmts: [], + }, }, None, ), @@ -278,7 +282,9 @@ fn test_early_parse_loop() { ident: "a", }, }), - body: Block, + body: Block { + stmts: [], + }, }, None, ),