aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/validation/match_armlist.rs
blob: c43ed70922413e9012f6273bfb213f55ec3277e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::{
    ast::{self, AttrsOwner, AstNode},
    syntax_node::{
        SyntaxError,
        SyntaxErrorKind::*,
        Direction,
    },
};

pub(crate) fn validate_match_armlist(node: &ast::MatchArmList, errors: &mut Vec<SyntaxError>) {
    // Report errors for any inner attribute
    // which has a preceding matcharm or an outer attribute
    for inner_attr in node.attrs().filter(|s| s.is_inner()) {
        let any_errors = inner_attr.syntax().siblings(Direction::Prev).any(|s| {
            match (ast::MatchArm::cast(s), ast::Attr::cast(s)) {
                (Some(_), _) => true,
                // Outer attributes which preceed an inner attribute are not allowed
                (_, Some(a)) if !a.is_inner() => true,
                (_, Some(_)) => false,
                (None, None) => false,
            }
        });

        if any_errors {
            errors.push(SyntaxError::new(InvalidMatchInnerAttr, inner_attr.syntax().range()));
        }
    }
}