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

Compiler sometimes crashes with stack overflow when html! is used inside Render impl #183

Closed
FinnStokes opened this issue Mar 8, 2020 · 4 comments

Comments

@FinnStokes
Copy link

FinnStokes commented Mar 8, 2020

Sometimes, using the html macro inside an impl can cause rustc to crash with a stack overflow. A simplified example that reproduces the crash is

use maud::{html, Markup, Render, DOCTYPE};

pub struct Theme;

impl Render for Theme {
    fn render(&self) -> Markup {
        html! {}
    }
}

pub struct Note;

impl Note {
    pub fn render_html(&self) -> Markup {
        html! {
            (DOCTYPE)
        }
    }
}
@FinnStokes
Copy link
Author

FinnStokes commented Mar 8, 2020

This seems to be because the html macro inserts extern crate maud, triggering rust-lang/rust#55779. It is very sensitive to the other code around the problem impl. I'm not sure there is anything to be done other than wait for the underlying bug to be fixed, but I thought it would be useful to post here so others running into the same issue would know what was going on.

In my case I am solving it by putting the problem impl inside its own submodule. In the simplified example, this becomes:

use maud::{html, Markup, DOCTYPE};

mod theme {
    use maud::{html, Markup, Render};

    pub struct Theme;

    impl Render for Theme {
        fn render(&self) -> Markup {
            html! {}
        }
    }
}

pub use theme::Theme;

pub struct Note;

impl Note {
    pub fn render_html(&self) -> Markup {
        html! {
            (DOCTYPE)
        }
    }
}

@lambda-fairy lambda-fairy changed the title Compiler sometimes crashes with stack oveflow when html! is used inside Render impl Compiler sometimes crashes with stack overflow when html! is used inside Render impl May 22, 2020
@mbr
Copy link

mbr commented Feb 13, 2021

I ran into the same issue, but the suggested workaround at rust-lang/rust#55779 (comment) (adding extern crate maud to the root) fixes it for me.

@kevlarr
Copy link

kevlarr commented Mar 4, 2021

Was wrestling with this for an hour and thought I was crazy. extern crate maud at root was a perfect fix, thanks @mbr

@lambda-fairy lambda-fairy pinned this issue Oct 29, 2021
@lambda-fairy
Copy link
Owner

Looks like this was fixed upstream.

It still reproduces on stable 1.56.0, but works fine on the latest nightly.

$ rustc --version
rustc 1.58.0-nightly (c390d69a6 2021-10-28)

I'll go ahead and close this issue, but leave it pinned for visibility.

@lambda-fairy lambda-fairy unpinned this issue Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants