File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
askama_derive/src/generator Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -409,7 +409,7 @@ impl<'a> Generator<'a, '_> {
409409 Expr :: Call ( ref v) if !matches ! ( * * v. path, Expr :: Path ( _) ) => {
410410 self . visit_expr ( ctx, & mut buf, arg) ?;
411411 let buf = buf. into_token_stream ( ) ;
412- quote_spanned ! ( span=> { #buf } )
412+ quote_spanned ! ( span=> #buf)
413413 }
414414 _ => {
415415 self . visit_expr ( ctx, & mut buf, arg) ?;
Original file line number Diff line number Diff line change @@ -407,3 +407,33 @@ mod test_deref_method_arg {
407407 assert_eq ! ( x. render( ) . unwrap( ) , "3322 6677" ) ;
408408 }
409409}
410+
411+ mod sub_test {
412+ use std:: borrow:: Borrow ;
413+
414+ use askama:: Template ;
415+
416+ pub fn bar ( x : & String ) -> String {
417+ format ! ( "bar: {x}" )
418+ }
419+
420+ // This test ensures that temporary variables behind references (like one generated
421+ // from `.borrow()`) still work.
422+ //
423+ // Regression test for <https://github.com/askama-rs/askama/issues/683>.
424+ #[ test]
425+ fn test_borrow ( ) {
426+ #[ derive( Template ) ]
427+ #[ template(
428+ source = r#"
429+ {{- crate::sub_test::bar(b.to_string().borrow()) -}}
430+ "# ,
431+ ext = "txt"
432+ ) ]
433+ struct Foo {
434+ b : u32 ,
435+ }
436+
437+ assert_eq ! ( Foo { b: 0 } . render( ) . unwrap( ) , "bar: 0" ) ;
438+ }
439+ }
You can’t perform that action at this time.
0 commit comments