diff --git a/firmware/defmt-test/macros/src/lib.rs b/firmware/defmt-test/macros/src/lib.rs index 2c376841..1889d908 100644 --- a/firmware/defmt-test/macros/src/lib.rs +++ b/firmware/defmt-test/macros/src/lib.rs @@ -34,6 +34,7 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result parse::Result { + imports.push(u); + } + _ => { return Err(parse::Error::new( item.span(), - "only function items are allowed", + "only `#[test]` functions and imports (`use`) are allowed in this scope", )); } } @@ -194,6 +199,7 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result>(); Ok(quote!(mod #ident { + #(#imports)* // TODO use `cortex-m-rt::entry` here to get the `static mut` transform #[export_name = "main"] unsafe extern "C" fn __defmt_test_entry() -> ! { diff --git a/parser/src/lib.rs b/parser/src/lib.rs index afe0817c..9e052b7f 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -72,10 +72,7 @@ pub enum Type { } fn is_digit(c: Option) -> bool { - match c.unwrap_or('\0') { - '0'..='9' => true, - _ => false, - } + matches!(c.unwrap_or('\0'), '0'..='9') } fn parse_range(mut s: &str) -> Option<(Range, usize /* consumed */)> { @@ -283,7 +280,7 @@ pub fn parse<'f>(format_string: &'f str) -> Result>, Cow<'stati } // Peek at the next char. - if chars.as_str().chars().next() == Some('{') { + if chars.as_str().starts_with('{') { // Escaped `{{`, also part of a literal fragment. chars.next(); // Move after both `{`s. continue;