Skip to content

Commit

Permalink
Allow variables to be inherited in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 22, 2024
1 parent 0edbca2 commit a873960
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rinja_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,11 +1157,19 @@ impl<'a> Generator<'a> {
self.input,
self.contexts,
Some(heritage),
// FIXME: Fix the broken lifetimes.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
//
// `transmute` is here to fix the lifetime nightmare around `&self.locals` not
// living long enough. The correct solution would be to make `MapChain` take two
// lifetimes `&'a MapChain<'a, 'b, K, V>`. Except... compiler is triggered because then
// the `'b` lifetime is marked as unused.
MapChain::with_parent(unsafe { mem::transmute(&self.locals) }),
// lifetimes `&'a MapChain<'a, 'b, K, V>`, making the `parent` field take
// `<'b, 'b, ...>`. Except... it doesn't work because `self` still doesn't live long
// enough here for some reason...
MapChain::with_parent(unsafe {
mem::transmute::<
&MapChain<'_, Cow<'_, str>, LocalMeta>,
&MapChain<'_, Cow<'_, str>, LocalMeta>,
>(&self.locals)
}),
self.buf_writable.discard,
self.is_in_filter_block,
);
Expand Down
2 changes: 2 additions & 0 deletions testing/templates/base-decl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{%- let variable = 42 -%}
{%- block extended %}{% endblock -%}
1 change: 1 addition & 0 deletions testing/templates/use-var.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ variable }}

0 comments on commit a873960

Please sign in to comment.