djc / askama

Type-safe, compiled Jinja-like templates for Rust
Apache License 2.0
3.25k stars 213 forks source link

if let chain has a weird behaviour #1033

Closed GuillaumeGomez closed 2 months ago

GuillaumeGomez commented 2 months ago

I expected this code:

{%- if let Some(query) = search_query && !query.is_empty() %}

To either emit an error about the && after if let Some or to work, instead it generated:

if let Some(query,) = &(search_query && !self.query.is_empty()) {

Which is a very unexpected in-between.

I think it should generate if let Some(query) = search_query && !self.query.is_empty(). What do you think?

djc commented 2 months ago

I think it should generate if let Some(query) = search_query && !self.query.is_empty(). What do you think?

That certainly looks more sensible!

GuillaumeGomez commented 2 months ago

Another interesting bug coming from if let: the binding var (query in this case) is not recognized as such.