Skip to content

declarative macro results in rustc entering infinite loop #68228

Open
@carllerche

Description

@carllerche

Rustc: rustc 1.40.0 (73528e339 2019-12-16)

uname -a: Darwin Carls-MacBook-Pro-2.local 18.7.0 Darwin Kernel Version 18.7.0: Sun Dec 1 18:59:03 PST 2019; root:xnu-4903.278.19~1/RELEASE_X86_64 x86_64

I have crafted a declarative macro that results in rustc entering an infinite loop and never completing.

Repro:

#[macro_export]
macro_rules! lock {
    // Done normalizing
    (@ { $($t:tt)* }) => {
    };
    (@ { $($t:tt)* } $a:pat, $b:expr, $c:block $($r:tt)* ) => {
        $crate:lock!(@{ $($t)* $a,$b, $c, } $($r)*)

    };
    ( $($t:tt)* ) => {
        $crate::lock!(@{} $($t:tt)*)
    }
}

fn main() {
    lock! {
        foo, bar(), {
            println!("WAT!");
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions