rtic_syntax/parse/
monotonic.rs

1use proc_macro2::Span;
2use syn::Attribute;
3use syn::{parse, spanned::Spanned, ItemType, Visibility};
4
5use crate::parse::util::FilterAttrs;
6use crate::{
7    ast::{Monotonic, MonotonicArgs},
8    parse::util,
9};
10
11impl MonotonicArgs {
12    pub(crate) fn parse(attr: Attribute) -> parse::Result<Self> {
13        crate::parse::monotonic_args(attr.path, attr.tokens)
14    }
15}
16
17impl Monotonic {
18    pub(crate) fn parse(args: MonotonicArgs, item: &ItemType, span: Span) -> parse::Result<Self> {
19        if item.vis != Visibility::Inherited {
20            return Err(parse::Error::new(
21                span,
22                "this field must have inherited / private visibility",
23            ));
24        }
25
26        let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs.clone());
27
28        if !attrs.is_empty() {
29            return Err(parse::Error::new(
30                attrs[0].path.span(),
31                "Monotonic does not support attributes other than `#[cfg]`",
32            ));
33        }
34
35        Ok(Monotonic {
36            cfgs,
37            ident: item.ident.clone(),
38            ty: item.ty.clone(),
39            args,
40        })
41    }
42}