diff --git a/crates/rune/src/compile/mod.rs b/crates/rune/src/compile/mod.rs index a98953912..d45ab7723 100644 --- a/crates/rune/src/compile/mod.rs +++ b/crates/rune/src/compile/mod.rs @@ -46,7 +46,7 @@ pub(crate) use self::unit_builder::UnitBuilder; pub(crate) mod v1; mod options; -#[cfg(any(all(test, feature = "fmt"), feature = "languageserver"))] +#[cfg(any(feature = "fmt", feature = "languageserver"))] pub(crate) use self::options::FmtOptions; pub use self::options::{Options, ParseOptionError}; diff --git a/crates/rune/src/fmt/format.rs b/crates/rune/src/fmt/format.rs index 120938a77..f308a05c4 100644 --- a/crates/rune/src/fmt/format.rs +++ b/crates/rune/src/fmt/format.rs @@ -1419,39 +1419,21 @@ fn tuple_body<'a>(o: &mut Output<'a>, p: &mut Stream<'a>) -> Result<()> { fn item_fn<'a>(o: &mut Output<'a>, p: &mut Stream<'a>) -> Result<()> { o.write(p.expect(K![fn])?)?; - let mut has_arguments = false; - let mut has_body = false; - - for node in p.by_ref() { - match node.kind() { - K![ident] => { - o.ws()?; - o.write(node)?; - } - FnArgs => { - has_arguments = true; - node.parse(|p| fn_args(o, p))?; - } - Block => { - if !has_arguments { - o.lit("()")?; - has_arguments = true; - } - - has_body = true; - - o.ws()?; - node.parse(|p| block(o, p))?; - } - _ => {} - } + if matches!(p.peek(), K![ident]) { + o.ws()?; + o.write(p.pump()?)?; } - if !has_arguments { + if let Some(node) = p.try_pump(FnArgs)? { + node.parse(|p| fn_args(o, p))?; + } else { o.lit("()")?; } - if !has_body { + if let Some(node) = p.try_pump(Block)? { + o.ws()?; + node.parse(|p| block(o, p))?; + } else { o.ws()?; o.lit("{")?; o.nl(1)?;