aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src
diff options
context:
space:
mode:
authorLibravatar vallentin <mail@vallentin.dev>2021-06-23 18:20:56 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2021-06-23 21:34:17 +0200
commite70e8f7c1d4a5266a998a57b0bb9746ce9396769 (patch)
tree9d465f32da64f80df8d2e64f676148f5e42a2ccc /askama_shared/src
parent49252d2457f280026c020d0df46733578eb959a5 (diff)
downloadaskama-e70e8f7c1d4a5266a998a57b0bb9746ce9396769.tar.gz
askama-e70e8f7c1d4a5266a998a57b0bb9746ce9396769.tar.bz2
askama-e70e8f7c1d4a5266a998a57b0bb9746ce9396769.zip
Fixed loop generator when accessing field (fixes 494)
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs6
1 files changed, 6 insertions, 0 deletions
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()) {{",