Skip to content

Fix askama template when called from within a macro in a different crate#728

Merged
GuillaumeGomez merged 3 commits intoaskama-rs:mainfrom
GuillaumeGomez:template-in-macro-from-other-crate
Apr 12, 2026
Merged

Fix askama template when called from within a macro in a different crate#728
GuillaumeGomez merged 3 commits intoaskama-rs:mainfrom
GuillaumeGomez:template-in-macro-from-other-crate

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

@GuillaumeGomez GuillaumeGomez commented Apr 11, 2026

Fixes #706.

This is a "two parts" problem:

  1. Span::call_site gives the actual file where the macro is called, so not where the macro containing is called but where it's defined. Super weird but nothing we can do from our side.
  2. To greatly improve reproducibility, we generate relative paths for include_bytes! statements we generate (so rustc rebuilds when needed) as much as possible.

So the fix here is: "if this doesn't seem to come from the same crate, then we provide the absolute path we have instead of trying to make it nicer".

If you could confirm it fixed the problem for you @cipriancraciun, it'd be super appreciated. :)

@GuillaumeGomez GuillaumeGomez force-pushed the template-in-macro-from-other-crate branch from 70c5e07 to 556018a Compare April 11, 2026 23:39
@GuillaumeGomez GuillaumeGomez force-pushed the template-in-macro-from-other-crate branch from 556018a to 3733a9d Compare April 11, 2026 23:44
@GuillaumeGomez GuillaumeGomez merged commit 9532987 into askama-rs:main Apr 12, 2026
51 checks passed
@GuillaumeGomez GuillaumeGomez deleted the template-in-macro-from-other-crate branch April 12, 2026 00:03
@cipriancraciun
Copy link
Copy Markdown
Contributor

I can confirm that the latest main branch solves this issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression introduced by #546 when the derive macro is called from within another macro

2 participants