Skip to content

Commit

Permalink
Merge pull request #179 from GuillaumeGomez/rust-macro-not-prepended
Browse files Browse the repository at this point in the history
Do not prepend rust macro calls with `&`
  • Loading branch information
Kijewski authored Sep 18, 2024
2 parents 3269b3f + 40d10ce commit 77931a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rinja_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,7 @@ fn is_copyable_within_op(expr: &Expr<'_>, within_op: bool) -> bool {
// The result of a call likely doesn't need to be borrowed,
// as in that case the call is more likely to return a
// reference in the first place then.
Expr::Call(..) | Expr::Path(..) | Expr::Filter(..) => true,
Expr::Call(..) | Expr::Path(..) | Expr::Filter(..) | Expr::RustMacro(..) => true,
// If the `expr` is within a `Unary` or `BinOp` then
// an assumption can be made that the operand is copy.
// If not, then the value is moved and adding `.clone()`
Expand Down
23 changes: 23 additions & 0 deletions testing/tests/let.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use rinja::Template;

#[derive(Template)]
#[template(
source = r#"{%- let x -%}
{%- if y -%}
{%- let x = String::new() %}
{%- else -%}
{%- let x = format!("blob") %}
{%- endif -%}
{{ x }}"#,
ext = "html"
)]
struct A {
y: bool,
}

// This test ensures that rust macro calls in `let`/`set` statements are not prepended with `&`.
#[test]
fn let_macro() {
let template = A { y: false };
assert_eq!(template.render().unwrap(), "blob")
}

0 comments on commit 77931a7

Please sign in to comment.