rust/syn/scan_expr.rs

Source file repositories/reference/linux-study-clean/rust/syn/scan_expr.rs

File Facts

System
Linux kernel
Corpus path
rust/syn/scan_expr.rs
Extension
.rs
Size
9307 bytes
Lines
268
Domain
Rust Kernel Layer
Bucket
Rust API Membrane
Inferred role
Rust Kernel Layer: implementation source
Status
source implementation candidate

Why This File Exists

Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.

Dependency Surface

Detected Declarations

Annotated Snippet

for (i, ch) in expected.chars().enumerate() {
                        match cursor.punct() {
                            Some((punct, _)) if punct.as_char() != ch => break,
                            Some((_, rest)) if i == expected.len() - 1 => {
                                return Ok((true, rest));
                            }
                            Some((punct, rest)) if punct.spacing() == Spacing::Joint => {
                                cursor = rest;
                            }
                            _ => break,
                        }
                    }
                    Ok((false, begin))
                })?,
                Input::ConsumeAny => input.parse::<Option<TokenTree>>()?.is_some(),
                Input::ConsumeBinOp => input.parse::<BinOp>().is_ok(),
                Input::ConsumeBrace | Input::ConsumeNestedBrace => {
                    (matches!(rule.0, Input::ConsumeBrace) || depth > 0)
                        && input.step(|cursor| match cursor.group(Delimiter::Brace) {
                            Some((_inside, _span, rest)) => Ok((true, rest)),
                            None => Ok((false, *cursor)),
                        })?
                }
                Input::ConsumeDelimiter => input.step(|cursor| match cursor.any_group() {
                    Some((_inside, _delimiter, _span, rest)) => Ok((true, rest)),
                    None => Ok((false, *cursor)),
                })?,
                Input::ConsumeIdent => input.parse::<Option<Ident>>()?.is_some(),
                Input::ConsumeLifetime => input.parse::<Option<Lifetime>>()?.is_some(),
                Input::ConsumeLiteral => input.parse::<Option<Lit>>()?.is_some(),
                Input::ExpectPath => {
                    input.parse::<ExprPath>()?;
                    true
                }
                Input::ExpectTurbofish => {
                    if input.peek(Token![::]) {
                        input.parse::<AngleBracketedGenericArguments>()?;
                    }
                    true
                }
                Input::ExpectType => {
                    Type::without_plus(input)?;
                    true
                }
                Input::CanBeginExpr => Expr::peek(input),
                Input::Otherwise => true,
                Input::Empty => input.is_empty() || input.peek(Token![,]),
            } {
                state = match rule.1 {
                    Action::SetState(next) => next,
                    Action::IncDepth => (depth += 1, &INIT).1,
                    Action::DecDepth => (depth -= 1, &POSTFIX).1,
                    Action::Finish => return if depth == 0 { Ok(()) } else { break },
                };
                continue 'table;
            }
        }
        return Err(input.error("unsupported expression"));
    }
}

Annotation

Implementation Notes