Skip to main content

MAX_EXPRESSION_DEPTH

Constant MAX_EXPRESSION_DEPTH 

Source
pub const MAX_EXPRESSION_DEPTH: usize = 64;
Expand description

Maximum permitted AST nesting depth.

Applied during structural validation (parse phase) and during evaluation to prevent stack exhaustion on pathological inputs such as ((((...1...)))) or long left-associative binop chains like 1+1+...+1 that produce a deep AST even when the source is short.

A limit of 64 is well above any legitimate template expression: the spec already caps list nesting at 2 and list comprehensions at a single generator, and real-world expressions rarely exceed ~10 levels of nesting. Exceeding this limit raises ExpressionErrorKind::ExpressionTooDeep.

See specs/expr/parser.md (Depth limit) and specs/expr/evaluator.md (Depth limit) for the rationale.