aboutsummaryrefslogtreecommitdiff
path: root/rtic-macros/src/syntax
diff options
context:
space:
mode:
authorJohannes Cornelis Draaijer <johannes.draaijer@kiteshield.com>2025-09-03 13:53:50 +0200
committerHenrik Tjäder <henrik@tjaders.com>2025-09-17 19:40:38 +0200
commit3ba1632f8d8e4c5564de282ad359e33151956bb6 (patch)
tree6866e77ac14cfd12b124fa564c0faa9c180d1c29 /rtic-macros/src/syntax
parentfa2c8c1dcdd74bd7e4268845a671e2ed146d0c1b (diff)
rtic-macros: forward attributes applied to app module
Instead of ignoring additional attributes applied to the app module, we can forward them to the generated code.
Diffstat (limited to 'rtic-macros/src/syntax')
-rw-r--r--rtic-macros/src/syntax/ast.rs5
-rw-r--r--rtic-macros/src/syntax/parse.rs9
-rw-r--r--rtic-macros/src/syntax/parse/app.rs1
3 files changed, 13 insertions, 2 deletions
diff --git a/rtic-macros/src/syntax/ast.rs b/rtic-macros/src/syntax/ast.rs
index ad73a89..44c1385 100644
--- a/rtic-macros/src/syntax/ast.rs
+++ b/rtic-macros/src/syntax/ast.rs
@@ -1,6 +1,6 @@
//! Abstract Syntax Tree
-use syn::{Attribute, Expr, Ident, Item, ItemUse, Pat, PatType, Path, Stmt, Type};
+use syn::{Attribute, Expr, Ident, Item, ItemUse, Meta, Pat, PatType, Path, Stmt, Type};
use crate::syntax::{backend::BackendArgs, Map};
@@ -11,6 +11,9 @@ pub struct App {
/// The arguments to the `#[app]` attribute
pub args: AppArgs,
+ /// All attributes applied to the `#[app]` module (meta only)
+ pub attribute_metas: Vec<Meta>,
+
/// The name of the `const` item on which the `#[app]` attribute has been placed
pub name: Ident,
diff --git a/rtic-macros/src/syntax/parse.rs b/rtic-macros/src/syntax/parse.rs
index aae8a50..ea7ff29 100644
--- a/rtic-macros/src/syntax/parse.rs
+++ b/rtic-macros/src/syntax/parse.rs
@@ -11,7 +11,7 @@ use syn::{
braced,
parse::{self, Parse, ParseStream, Parser},
token::Brace,
- Ident, Item, LitInt, Token,
+ Attribute, Ident, Item, LitInt, Meta, Token,
};
use crate::syntax::{
@@ -28,6 +28,7 @@ pub fn app(args: TokenStream2, input: TokenStream2) -> parse::Result<App> {
}
pub(crate) struct Input {
+ pub attribute_metas: Vec<Meta>,
_mod_token: Token![mod],
pub ident: Ident,
_brace_token: Brace,
@@ -48,12 +49,18 @@ impl Parse for Input {
let content;
+ let mut attributes = input.call(Attribute::parse_outer)?;
let _mod_token = input.parse()?;
let ident = input.parse()?;
let _brace_token = braced!(content in input);
+ let inner_attributes = content.call(Attribute::parse_inner)?;
let items = content.call(parse_items)?;
+ attributes.extend(inner_attributes);
+ let attribute_metas = attributes.into_iter().map(|a| a.meta).collect();
+
Ok(Input {
+ attribute_metas,
_mod_token,
ident,
_brace_token,
diff --git a/rtic-macros/src/syntax/parse/app.rs b/rtic-macros/src/syntax/parse/app.rs
index 469bcb8..50ef12b 100644
--- a/rtic-macros/src/syntax/parse/app.rs
+++ b/rtic-macros/src/syntax/parse/app.rs
@@ -531,6 +531,7 @@ impl App {
}
Ok(App {
+ attribute_metas: input.attribute_metas,
args,
name: input.ident,
init,