Skip to content

Commit

Permalink
Handle labeled blocks; release
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jul 5, 2024
1 parent 4e38b9e commit 3b240c3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "genemichaels"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
license = "ISC"
description = "Makes your code formatty"
Expand Down
26 changes: 17 additions & 9 deletions src/sg_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,23 @@ impl Formattable for &Expr {
base_indent,
&e.attrs,
|out: &mut MakeSegsState, base_indent: &Alignment| {
new_sg_block(
out,
base_indent,
e.block.brace_token.span.start(),
"{",
Some(&e.attrs),
&e.block.stmts,
e.block.brace_token.span.end().prev(),
)
let mut sg = new_sg(out);
if let Some(l) = &e.label {
append_whitespace(out, base_indent, &mut sg, l.name.apostrophe.start());
sg.seg(out, &format!("{}: ", l.name));
}
sg.child(
new_sg_block(
out,
base_indent,
e.block.brace_token.span.start(),
"{",
Some(&e.attrs),
&e.block.stmts,
e.block.brace_token.span.end().prev(),
),
);
sg.build(out)
},
),
Expr::Box(e) => new_sg_outer_attrs(
Expand Down
8 changes: 8 additions & 0 deletions tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,11 @@ fn rt_static_mut1() {
rt(r#"static mut X: Y = Y(7);
"#);
}

#[test]
fn rt_labeled_block() {
rt(r#"fn main() {
'label: { }
}
"#);
}

0 comments on commit 3b240c3

Please sign in to comment.