From e70e8f7c1d4a5266a998a57b0bb9746ce9396769 Mon Sep 17 00:00:00 2001 From: vallentin Date: Wed, 23 Jun 2021 18:20:56 +0200 Subject: Fixed loop generator when accessing field (fixes 494) --- askama_shared/src/generator.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'askama_shared') diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index b0489ec..0ce7df3 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -658,6 +658,12 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { ", _loop_item) in ::askama::helpers::TemplateLoop::new(((&{}).into_iter())) {{", expr_code )), + // If accessing a field then it most likely needs to be + // borrowed, to prevent an attempt of moving. + Expr::Attr(..) => buf.writeln(&format!( + ", _loop_item) in ::askama::helpers::TemplateLoop::new(((&{}).into_iter())) {{", + expr_code + )), // Otherwise, we borrow `iter` assuming that it implements `IntoIterator`. _ => buf.writeln(&format!( ", _loop_item) in ::askama::helpers::TemplateLoop::new(({}).into_iter()) {{", -- cgit