mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Improve handling of *
and &
operators in functions/methods arguments
This commit is contained in:
parent
bd0940bb7d
commit
0f9c5a0281
@ -1957,7 +1957,23 @@ impl<'a> Generator<'a> {
|
|||||||
buf: &mut Buffer,
|
buf: &mut Buffer,
|
||||||
arg: &WithSpan<'_, Expr<'_>>,
|
arg: &WithSpan<'_, Expr<'_>>,
|
||||||
) -> Result<(), CompileError> {
|
) -> Result<(), CompileError> {
|
||||||
let borrow = !is_copyable(arg);
|
self._visit_arg_inner(ctx, buf, arg, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _visit_arg_inner(
|
||||||
|
&mut self,
|
||||||
|
ctx: &Context<'_>,
|
||||||
|
buf: &mut Buffer,
|
||||||
|
arg: &WithSpan<'_, Expr<'_>>,
|
||||||
|
// This variable is needed because `Expr::Unary` is not copyable but since we might
|
||||||
|
// skip a few levels.
|
||||||
|
need_borrow: bool,
|
||||||
|
) -> Result<(), CompileError> {
|
||||||
|
if let Expr::Unary(expr @ ("*" | "&"), ref arg) = **arg {
|
||||||
|
buf.write(expr);
|
||||||
|
return self._visit_arg_inner(ctx, buf, arg, true);
|
||||||
|
}
|
||||||
|
let borrow = need_borrow || !is_copyable(arg);
|
||||||
if borrow {
|
if borrow {
|
||||||
buf.write("&(");
|
buf.write("&(");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user