Fixed loop generator when accessing field (fixes 494)

This commit is contained in:
vallentin 2021-06-23 18:20:56 +02:00 committed by Dirkjan Ochtman
parent 49252d2457
commit e70e8f7c1d

View File

@ -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()) {{",