askama/testing/tests/ui/macro-recursion.rs
René Kijewski 9336435859 derive: keep track of called macros
Recursive macro calls, direct and indirect, would cause a stackoverflow.

This PR lets the macro call handler keep track of the stack of called
macros we are currently in, so we can abort with an error message
instead of panicking.
2024-12-29 07:52:21 +01:00

42 lines
862 B
Rust

use rinja::Template;
#[derive(Template)]
#[template(
source = "
{% macro one %}{% call one %}{% endmacro %}
{% call one %}
",
ext = "html"
)]
struct Direct;
#[derive(Template)]
#[template(
source = "
{% macro one %}{% call two %}{% endmacro %}
{% macro two %}{% call three %}{% endmacro %}
{% macro three %}{% call four %}{% endmacro %}
{% macro four %}{% call five %}{% endmacro %}
{% macro five %}{% call one %}{% endmacro %}
{% call one %}
",
ext = "html"
)]
struct Indirect;
#[derive(Template)]
#[template(
source = r#"
{% import "macro-recursion-1.html" as next %}
{% macro some_macro %}
{% call next::some_macro %}
{% endmacro %}
{% call some_macro %}
"#,
ext = "html"
)]
struct AcrossImports;
fn main() {
}