diff --git a/Cargo.lock b/Cargo.lock index 38f5129..00d9fb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,7 +292,7 @@ dependencies = [ [[package]] name = "genemichaels" -version = "0.3.2" +version = "0.3.3" dependencies = [ "aargvark 0.2.2", "cargo-manifest", diff --git a/Cargo.toml b/Cargo.toml index 13ae164..d354215 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "genemichaels" -version = "0.3.2" +version = "0.3.3" edition = "2021" license = "ISC" description = "Makes your code formatty" diff --git a/src/sg_expr.rs b/src/sg_expr.rs index 0dacb01..8de43d8 100644 --- a/src/sg_expr.rs +++ b/src/sg_expr.rs @@ -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( diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs index 38667f9..92c3d3c 100644 --- a/tests/roundtrip.rs +++ b/tests/roundtrip.rs @@ -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: { } +} +"#); +}