Repository: aptos-labs/aptos-core
File: third_party/move/move-compiler-v2/legacy-move-compiler/src/parser/syntax.rs (Rust)

Code before:
//   - `behavior_keyword < ...`               (without pre-state label)
fn is_behavior_predicate(context: &mut Context) -> bool {
    // Behavior predicates are only available in V2_4 and later
    if context.env.flags().language_version() < LanguageVersion::V2_4 {
        return false;
    }
    if context.tokens.peek() != Tok::Identifier {
        return false;
    }

    let content = context.tokens.content();

    // Check for direct behavior keyword followed by `<`
    if behavior_kind_from_str(content).is_some() {
        return matches!(context.tokens.lookahead(), Ok(Tok::Less));
    }

    // Check for `label @ behavior_keyword < ...` pattern
    match context.tokens.lookahead2() {
        Ok((Tok::AtSign, Tok::Identifier)) => {
            // Need to check the third token - it should be a behavior keyword
            // We can't easily lookahead 3, so we accept this pattern and validate during parse
            true
        },
        _ => false,
    }
}

// Parses a behavior predicate expression:
//   [pre_label@]behavior_kind<fn_exp>(args)[@post_label]
fn parse_behavior(context: &mut Context) -> Result<Exp_, Box<Diagnostic>> {
    // Parse optional pre-state label
    let pre_label = if context.tokens.peek() == Tok::Identifier
        && matches!(context.tokens.lookahead(), Ok(Tok::AtSign))
        && behavior_kind_from_str(context.tokens.content()).is_none()
    {
        let label_name = parse_identifier(context)?;
        let label = Label(label_name);
        consume_token(context.tokens, Tok::AtSign)?;
        Some(label)
    } else {
        None
    };

    // Parse behavior kind
    let kind_content = context.tokens.content();
    let kind = behavior_kind_from_str(kind_content).ok_or_else(|| {
        Box::new(
            diag!(
                Syntax::UnexpectedToken,
                (

Review comment (suggestion):
nit: This could be another `matches!`:

```rust
matches!(context.tokens.lookahead2(), Ok((Tok::AtSign, Tok::Identifier)))
```

Code after:
//   - `behavior_keyword < ...`               (without pre-state label)
fn is_behavior_predicate(context: &mut Context) -> bool {
    // Behavior predicates are only available in V2_4 and later
    if context.env.flags().language_version() < LanguageVersion::V2_4 {
        return false;
    }
    if context.tokens.peek() != Tok::Identifier {
        return false;
    }

    let content = context.tokens.content();

    // Check for direct behavior keyword followed by `<`
    if behavior_kind_from_str(content).is_some() {
        return matches!(context.tokens.lookahead(), Ok(Tok::Less));
    }

    // Check for `label @ behavior_keyword < ...` pattern
    match context.tokens.lookahead2() {
        Ok((Tok::AtSign, Tok::Identifier)) => {
            // Need to check the third token - it should be a behavior keyword
            // We can't easily lookahead 3, so we accept this pattern and validate during parse
            true
        },
        _ => false,
    }
}

// Parses a behavior predicate expression:
//   [pre_label@]behavior_kind<fn_exp>(args)[@post_label]
fn parse_behavior(context: &mut Context) -> Result<Exp_, Box<Diagnostic>> {
    // Parse optional pre-state label
    let pre_label = if context.tokens.peek() == Tok::Identifier
        && matches!(context.tokens.lookahead(), Ok(Tok::AtSign))
    {
        let label_name = parse_identifier(context)?;
        let label = Label(label_name);
        consume_token(context.tokens, Tok::AtSign)?;
        Some(label)
    } else {
        None
    };

    // Parse behavior kind
    let kind_content = context.tokens.content();
    let kind = behavior_kind_from_str(kind_content).ok_or_else(|| {
        Box::new(
            diag!(
                Syntax::UnexpectedToken,
                (
                    current_token_loc(context.tokens),