Skip to content

nested macro repetions can cause fatal OOM #30561

Closed
@colin-kiegel

Description

@colin-kiegel

oom in two lines

macro_rules! oom { ( $($( ),*)* ) => { } }
oom!( );

=> fatal out-of-memory (warning: DON'T try to compile this without sufficient precautions - my computer runs out of RAM in 2 seconds with 16GB RAM installed). It doesn't matter what inside or outside of the brackets .. $($( .. ),*)* ...

Tested on LINUX, reproducible with stable-1.5, beta-1.6 and nightly.

This modified version is caught by the compiler and safe

macro_rules! no_oom { ( $($( ),*);* ) => { } }
no_oom!( );
src/main.rs:5:1: 5:10 error: ambiguity: multiple successful parses
src/main.rs:5 no_oom!( );
              ^~~~~~~~~

It would be nice if the compiler could check for anything that might oom like this. I think the safe version gives a hint at what is going wrong with the first version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions