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

RA crashes with stack overflow when using this macros #18910

Open
Rexagon opened this issue Jan 10, 2025 · 2 comments · May be fixed by #18929
Open

RA crashes with stack overflow when using this macros #18910

Rexagon opened this issue Jan 10, 2025 · 2 comments · May be fixed by #18929
Labels
C-bug Category: bug

Comments

@Rexagon
Copy link

Rexagon commented Jan 10, 2025

Image

rust-analyzer version: 0.3.2257-standalone

rustc version: rustc 1.84.0 (9fc6b4312 2025-01-07)
editor or extension: VSCode (VSCodium), rust-analyzer extension v0.3.2257

relevant settings: default env, but these are my settings from settings.json just in case:

{
    ...
    "rust-analyzer.imports.granularity.enforce": true,
    "rust-analyzer.imports.granularity.group": "module",
    "rust-analyzer.imports.prefix": "self",
    "rust-analyzer.semanticHighlighting.strings.enable": true,
    "rust-analyzer.hover.actions.references.enable": true,
    "rust-analyzer.workspace.symbol.search.kind": "all_symbols",
    "rust-analyzer.workspace.symbol.search.scope": "workspace_and_dependencies",
    "rust-analyzer.testExplorer": true,
    "rust-analyzer.inlayHints.discriminantHints.enable": "always",
    "rust-analyzer.procMacro.ignored": {
      "tokio-macros": ["main"],
      "async-trait": ["async_trait"]
    },
    "rust-analyzer.rustfmt.extraArgs": ["+nightly"],
    ...
}

repository link (if public, optional): none, just a new project with cargo init --lib is enough.

code snippet to reproduce:

#[cfg(test)]
#[macro_export]
macro_rules! boom {
    (
        $($code:literal),+,
        $(param: $param:expr,)?
    ) => {{
        let _ = $crate::boom!(@param $($param)*);
    }};
    (@param) => { () };
    (@param $param:expr) => { $param };
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        // NOTE: there is an error, but RA crashes before showing it
        boom!("RAND", param: c7.clone());
    }
}

Rust-analyzer tries to index a project with the only lib.rs file containing the code above and fails:

thread 'PrimeCaches#4' has overflowed its stack
fatal runtime error: stack overflow
[Error - 3:29:29 PM] Server process exited with signal SIGABRT.
[Info  - 3:29:29 PM] Connection to server got closed. Server will restart.
true

thread 'PrimeCaches#6' has overflowed its stack
fatal runtime error: stack overflow
[Error - 3:29:30 PM] Server process exited with signal SIGABRT.
[Info  - 3:29:30 PM] Connection to server got closed. Server will restart.
true

thread 'PrimeCaches#2' has overflowed its stack
fatal runtime error: stack overflow
[Error - 3:29:32 PM] Server process exited with signal SIGABRT.
[Info  - 3:29:32 PM] Connection to server got closed. Server will restart.
true

thread 'PrimeCaches#4' has overflowed its stack
fatal runtime error: stack overflow
[Error - 3:29:34 PM] Server process exited with signal SIGABRT.
[Info  - 3:29:34 PM] Connection to server got closed. Server will restart.
true

thread 'PrimeCaches#4' has overflowed its stack
fatal runtime error: stack overflow
[Error - 3:29:36 PM] Server process exited with signal SIGABRT.
[Error - 3:29:36 PM] The Rust Analyzer Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

Sometimes it manages to highlight the code and show "Run test" labels and other stuff, but then it crashes again when I write something.

It starts working again if I fix the macro invocation:

...

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        boom!("RAND", param: 123, );
    }
}
@Rexagon Rexagon added the C-bug Category: bug label Jan 10, 2025
@Veykril
Copy link
Member

Veykril commented Jan 10, 2025

This should be fixed on the latest nightly

@Rexagon
Copy link
Author

Rexagon commented Jan 10, 2025

I tried a pre-release version (0.4.2260), but the crash still appears.

Is there any way I can increase the log level to somehow show the error trace on overflow? For some reason setting "RA_LOG": "lsp_server=debug" or "rust-analyzer.trace.server": "verbose" does nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
2 participants