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

rustc hangs on malformed format!() w/ first arg being a macro invocation declaring a type with a #[derive] #47188

Closed
ben0x539 opened this issue Jan 4, 2018 · 3 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times.

Comments

@ben0x539
Copy link
Contributor

ben0x539 commented Jan 4, 2018

macro_rules! foo {
    () => {
        {
            #[derive(Clone)]
            struct Ty;

            ""
        }
    }
}

fn main() {
    format!(foo!());
}

rustc seems to sit there consuming 100% CPU indefinitely. This code isn't valid because format!() wants a string literal as first argument, but it doesn't seem to get around to complaining about it, so I assume it's getting stuck somewhere formatting an error message.

@Mark-Simulacrum Mark-Simulacrum added I-compiletime Issue: Problems and improvements with respect to compile times. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. labels Jan 10, 2018
@steffengy
Copy link
Contributor

Duplicate/Related to #44692

@steffengy
Copy link
Contributor

Seems like this causes an infinite loop in libsyntax_pos/lib.rs#macro_backtrace.

The loop referenced above results in the same span for each iteration:

ExpnInfo { call_site: Span { lo: BytePos(86), hi: BytePos(96), ctxt: #4 }, 
callee: NameAndSpan { format: MacroAttribute(derive(Clone)), allow_internal_unstable: true, 
allow_internal_unsafe: false, span: None } }
ExpnInfo { call_site: Span { lo: BytePos(86), hi: BytePos(96), ctxt: #4 }, 
callee: NameAndSpan { format: MacroAttribute(derive(Clone)), allow_internal_unstable: true, 
allow_internal_unsafe: false, span: None } }
ExpnInfo { call_site: Span { lo: BytePos(86), hi: BytePos(96), ctxt: #4 }, 
callee: NameAndSpan { format: MacroAttribute(derive(Clone)), allow_internal_unstable: true, 
allow_internal_unsafe: false, span: None } }
ExpnInfo { call_site: Span { lo: BytePos(86), hi: BytePos(96), ctxt: #4 }, 
callee: NameAndSpan { format: MacroAttribute(derive(Clone)), allow_internal_unstable: true, 
allow_internal_unsafe: false, span: None } }

This seems to be related to the #[derive(Clone)] invocation, omitting it doesn't yield this error
and results in:

ExpnInfo { call_site: Span { lo: BytePos(5505012), hi: BytePos(5505043), ctxt: #2 }, 
callee: NameAndSpan { format: MacroBang(format_args), allow_internal_unstable: true, 
allow_internal_unsafe: false, span: None } }
ExpnInfo { call_site: Span { lo: BytePos(156), hi: BytePos(172), ctxt: #0 }, 
callee: NameAndSpan { format: MacroBang(format), allow_internal_unstable: false, 
allow_internal_unsafe: false, 
span: Some(Span { lo: BytePos(5504957), hi: BytePos(5505047), ctxt: #0 }) } }
ExpnInfo { call_site: Span { lo: BytePos(5505012), hi: BytePos(5505043), ctxt: #2 }, 
callee: NameAndSpan { format: MacroBang(format_args), allow_internal_unstable: true, 
allow_internal_unsafe: false, span: None } }
ExpnInfo { call_site: Span { lo: BytePos(156), hi: BytePos(172), ctxt: #0 }, 
callee: NameAndSpan { format: MacroBang(format), allow_internal_unstable: false, 
allow_internal_unsafe: false, 
span: Some(Span { lo: BytePos(5504957), hi: BytePos(5505047), ctxt: #0 }) } }

Notably, using the expanded version of #[derive(Clone)] generated with --pretty=expanded in the macro declaration, also doesn't lead to the bug mentioned here.

Therefore it's possible, this is actually an issue with proc_macros/derive generating unexpected (in this case possibly self-referencing?) spans in an macro-invocation?

@dtolnay
Copy link
Member

dtolnay commented Feb 19, 2019

Closing as a duplicate of #44692.

@dtolnay dtolnay closed this as completed Feb 19, 2019
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-compiletime Issue: Problems and improvements with respect to compile times.
Projects
None yet
Development

No branches or pull requests

4 participants