diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index e2438da3..6b415493 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -87,7 +87,7 @@ struct Generator<'a, 'h> { /// Set of called macros we are currently in. Used to prevent (indirect) recursions. seen_macros: Vec<(&'a Macro<'a>, Option>)>, /// Set of callers to forward into the macro. - seen_callers: Vec<&'a Call<'a>>, + current_caller: Option<&'a Call<'a>>, } impl<'a, 'h> Generator<'a, 'h> { @@ -113,7 +113,7 @@ impl<'a, 'h> Generator<'a, 'h> { }, is_in_filter_block, seen_macros: Vec::new(), - seen_callers: Vec::new(), + current_caller: None, } } diff --git a/askama_derive/src/generator/node.rs b/askama_derive/src/generator/node.rs index 9df94ef2..b2e65d5f 100644 --- a/askama_derive/src/generator/node.rs +++ b/askama_derive/src/generator/node.rs @@ -649,7 +649,7 @@ impl<'a> Generator<'a, '_> { } else { self.seen_macros.push((def, ctx.file_info_of(call.span()))); } - self.seen_callers.push(call); + self.current_caller = Some(call); self.flush_ws(ws1); // Cannot handle_ws() here: whitespace from macro definition comes first let size_hint = self.push_locals(|this| { macro_call_ensure_arg_count(call, def, ctx)?; @@ -773,7 +773,7 @@ impl<'a> Generator<'a, '_> { })?; self.prepare_ws(ws1); self.seen_macros.pop(); - self.seen_callers.pop(); + self.current_caller = None; Ok(size_hint) } @@ -1119,9 +1119,10 @@ impl<'a> Generator<'a, '_> { if ***path == Expr::Var("super") { return self.write_block(ctx, buf, None, ws, s.span()); } else if ***path == Expr::Var("caller") { - let def = self.seen_callers.pop().ok_or_else(|| { + let def = self.current_caller.ok_or_else(|| { ctx.generate_error(format_args!("block is not defined for caller"), s.span()) })?; + self.current_caller = None; self.handle_ws(ws); let size_hint = self.push_locals(|this| { this.write_buf_writable(ctx, buf)?; @@ -1188,7 +1189,7 @@ impl<'a> Generator<'a, '_> { buf.write('}'); Ok(size_hint) })?; - self.seen_callers.push(def); + self.current_caller = Some(def); return Ok(size_hint); } }