Skip to content

Commit

Permalink
Merge pull request #1540 from dtolnay/blockempty
Browse files Browse the repository at this point in the history
Include empty `stmts = []` in snapshots
  • Loading branch information
dtolnay authored Dec 11, 2023
2 parents fbd9809 + e2f5d4a commit da0d4da
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion codegen/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/debug/gen.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions tests/test_asyncness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ fn test_async_fn() {
generics: Generics,
output: ReturnType::Default,
},
block: Block,
block: Block {
stmts: [],
},
}
"###);
}
Expand All @@ -32,7 +34,9 @@ fn test_async_closure() {
asyncness: Some,
output: ReturnType::Default,
body: Expr::Block {
block: Block,
block: Block {
stmts: [],
},
},
}
"###);
Expand Down
4 changes: 3 additions & 1 deletion tests/test_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ fn test_fn_precedence_in_where_clause() {
},
output: ReturnType::Default,
},
block: Block,
block: Block {
stmts: [],
},
}
"###);

Expand Down
8 changes: 6 additions & 2 deletions tests/test_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ fn test_macro_variable_attr() {
generics: Generics,
output: ReturnType::Default,
},
block: Block,
block: Block {
stmts: [],
},
}
"###);
}
Expand Down Expand Up @@ -320,7 +322,9 @@ fn test_impl_trait_trailing_plus() {
},
),
},
block: Block,
block: Block {
stmts: [],
},
}
"###);
}
8 changes: 6 additions & 2 deletions tests/test_shebang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ fn test_basic() {
generics: Generics,
output: ReturnType::Default,
},
block: Block,
block: Block {
stmts: [],
},
},
],
}
Expand Down Expand Up @@ -55,7 +57,9 @@ fn test_comment() {
generics: Generics,
output: ReturnType::Default,
},
block: Block,
block: Block {
stmts: [],
},
},
],
}
Expand Down
12 changes: 9 additions & 3 deletions tests/test_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ fn test_none_group() {
generics: Generics,
output: ReturnType::Default,
},
block: Block,
block: Block {
stmts: [],
},
})
"###);
}
Expand Down Expand Up @@ -251,7 +253,9 @@ fn test_early_parse_loop() {
[
Stmt::Expr(
Expr::Loop {
body: Block,
body: Block {
stmts: [],
},
},
None,
),
Expand All @@ -278,7 +282,9 @@ fn test_early_parse_loop() {
ident: "a",
},
}),
body: Block,
body: Block {
stmts: [],
},
},
None,
),
Expand Down

0 comments on commit da0d4da

Please sign in to comment.