bon_macros/util/
expr.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::util::prelude::*;

pub(crate) trait ExprExt {
    fn require_path_mod_style(&self) -> Result<&syn::Path>;
}

impl ExprExt for syn::Expr {
    fn require_path_mod_style(&self) -> Result<&syn::Path> {
        let expr = match self {
            Self::Path(expr) => expr,
            _ => bail!(self, "expected a simple path, like `foo::bar`"),
        };

        crate::parsing::reject_syntax("attribute", &expr.attrs.first())?;
        crate::parsing::reject_syntax("<T as Trait> syntax", &expr.qself)?;

        expr.path.require_mod_style()?;

        Ok(&expr.path)
    }
}