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

A simple macro with "///" hangs #112342

Closed
mempler opened this issue Jun 6, 2023 · 1 comment · Fixed by #112345
Closed

A simple macro with "///" hangs #112342

mempler opened this issue Jun 6, 2023 · 1 comment · Fixed by #112345
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.

Comments

@mempler
Copy link

mempler commented Jun 6, 2023

Code:

#[macro_export]
macro_rules! memory_leak {
    (
        $(
            /// <-- causes the memory leak
        )*
    ) => {};
}

// must call at least once
memory_leak! {}

fn main() {}

Here are some playground links at which it also doesn't compile. (also does not work on release)
Playground (2021; stable; debug)
Playground (2021; nightly; debug)

Steps to reproduce

  • Save the code as memory_leak.rs
  • Run rustc memory_leak.rs

Expected Behavior:

Raise an repetition matches empty token tree compiler error, like a normal comment would, as an example:

#[macro_export]
macro_rules! works {
    (
        $(
            // <-- notice the missing slash
        )*
    ) => {};
}

works! {}

fn main() {}

What happened:

It entered an infinite loop and allocated infinite amount of memory. I have 16 GB of ram and 8 GB swap, at one point it got killed by the oom killer.

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (e6d4725c7 2023-06-05)
binary: rustc
commit-hash: e6d4725c76f3b526c74454bc51afdf6daf133506
commit-date: 2023-06-05
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.4

No backtrace available, as it gets killed by the oom killer

@mempler mempler added the C-bug Category: This is a bug. label Jun 6, 2023
@Noratrieb Noratrieb changed the title A simple macro with "///" causes a memory leak A simple macro with "///" hangs Jun 6, 2023
@Noratrieb Noratrieb added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. labels Jun 6, 2023
@est31
Copy link
Member

est31 commented Jun 6, 2023

cc #95390 and #95267 , they are related.

@bors bors closed this as completed in 42cf6da Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants