Skip to content

Regression related to temporary values within an expression #661

@AMDmi3

Description

@AMDmi3

Describe the bug
There seems to be a regression in 0.15 related to temporary values within a single expression. See example below, which works fine with askama 0.14.0, and demostrates that a given expression is a valid rust code, but fails on 0.15.1 with the following error:

error[E0716]: temporary value dropped while borrowed
 --> src/main.rs:6:25
  |
6 |     source = r#"{{ Some("x".to_string().as_str()).unwrap() }}"#
  |                    ---- ^^^^           - temporary value is freed at the end of this statement
  |                    |    |
  |                    |    creates a temporary value which is freed while still in use
  |                    borrow later used here
  |
  = note: consider using a `let` binding to create a longer lived value

To Reproduce

use askama::Template;

#[derive(Template)]
#[template(
    ext = "html",
    source = r#"{{ Some("x".to_string().as_str()).unwrap() }}"#
)]
struct Tpl {
}

fn main() {
    eprintln!("{}", Tpl{}.render().unwrap());
    eprintln!("{}", Some("x".to_string().as_str()).unwrap());
}

Askama version
Ok on 0.14.0, compiler error on 0.15.1

Rust version
rustc 1.94.0-nightly (4f14395c3 2025-12-22)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions