Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive Enums with Doc comments hit recursion limit #354

Open
DasLixou opened this issue Feb 20, 2025 · 11 comments
Open

Recursive Enums with Doc comments hit recursion limit #354

DasLixou opened this issue Feb 20, 2025 · 11 comments

Comments

@DasLixou
Copy link

Reprod:

#[derive(Debug, Template)]
pub enum Test {
    /// ```rinja
    /// {% for x in self.0 %}
    /// {{ x }}
    /// {% endfor %}
    /// ```
    #[template(ext = "html", in_doc = true)]
    A(Vec<Test>),
    /// ```rinja
    /// B
    /// ```
    #[template(ext = "html", in_doc = true)]
    B,
}

latest commit on main (c3fac0ca99579dd2ad73f53c231e56a7dd1c0074)

Error:

error: reached the recursion limit while instantiating `filters::escape::_::_::<impl FastWritable for &Test>::write_into::<filters::escape::EscapeWriter<&mut filters::escape::EscapeWriter<..., ...>, ...>>`
   --> /home/lixou/.cargo/git/checkouts/rinja-b4465ea47ea6e29f/c3fac0c/rinja/src/filters/escape.rs:514:17
    |
514 |                 <T>::write_into(self, dest)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: `filters::escape::_::_::<impl FastWritable for &T>::write_into` defined here
   --> /home/lixou/.cargo/git/checkouts/rinja-b4465ea47ea6e29f/c3fac0c/rinja/src/filters/escape.rs:513:13
    |
513 |             fn write_into<W: fmt::Write + ?Sized>(&self, dest: &mut W) -> crate::Result<()> {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: the full type name has been written to '/home/lixou/spade-lang/spadedoc/target/debug/deps/spadedoc-6d2618e2fa5f617c.long-type.txt'
@Kijewski
Copy link
Collaborator

Thank you for opening the issue! That is a known issue: https://rinja.readthedocs.io/en/latest/template_syntax.html#recursive-structures.

Strangely enough, sometimes it seems to work without adding .render(). I guess in some cases FastWritable calls itself in a(n indirect?) recursion. I don't know if we can properly track the problem to give the user a better error message, or better yet: add .render()? automatically.

@DasLixou
Copy link
Author

Oh I was searching that, thanks! But what is meant by a custom iterator with a plain loop?

@Kijewski
Copy link
Collaborator

But what is meant by a custom iterator with a plain loop?

Actually, I have no idea. :) @GuillaumeGomez?

@GuillaumeGomez
Copy link
Contributor

I have absolutely no idea either. 😅

@DasLixou
Copy link
Author

But is there a nicer way without doing allocations? Or is it at least planned?

@Kijewski
Copy link
Collaborator

Yea, I'm not happy that is shortcoming exists.

Could you please create an MRE that produces this error? The best way would probably if you would create a new repo that I could clone and experiment with.

@DasLixou
Copy link
Author

Isn't the reprod in the issue description already minimal? How could I make that shorter? LUL

@Kijewski
Copy link
Collaborator

When I tried your example yesterday it "worked for me", i.e. it does not reproduce the error. Could be that I copied something wrong or into the wrong place. If you tell me, that it actually does not work, i.e. that it produces the error, then I'll try it again.

@DasLixou
Copy link
Author

Okay, I'll try to make a repo

@DasLixou
Copy link
Author

...
Tried to reprod on windows, now I get this error:

error: expected item, found `..`
 --> C:\Users\lixou\.cargo\git\checkouts\rinja-b4465ea47ea6e29f\c3fac0c\rinja_derive\src\html.rs:1:1
  |
1 | ../../rinja/src/html.rs
  | ^^ expected item
  |
  = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>

error[E0432]: unresolved import `crate::html::write_escaped_str`
  --> C:\Users\lixou\.cargo\git\checkouts\rinja-b4465ea47ea6e29f\c3fac0c\rinja_derive\src\generator.rs:18:5
   |
18 | use crate::html::write_escaped_str;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `write_escaped_str` in `html`

For more information about this error, try `rustc --explain E0432`.

repo here: https://github.com/DasLixou/rinja-recursion-reprod

@Kijewski
Copy link
Collaborator

Hehe, I like the commit message. :)

I'll have look if I can find a fix. (But possibly not very soon.)

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

No branches or pull requests

3 participants