Skip to content

Compiler crashes on malformed macro #23389

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

Closed
Binero opened this issue Mar 15, 2015 · 3 comments
Closed

Compiler crashes on malformed macro #23389

Binero opened this issue Mar 15, 2015 · 3 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Binero
Copy link
Contributor

Binero commented Mar 15, 2015

A simple malformed macro makes the compiler crash.

Code:

macro_rules! code_block {
    $c:block => $c
}

Playpen error:

<anon>:1:1: 3:2 error: internal compiler error: wrong-structured lhs for follow check (didn't find a TtDelimited or TtSequence)
<anon>:1 macro_rules! code_block {
<anon>:2     $c:block => $c
<anon>:3 }
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:130

Playpen: http://is.gd/COoZe7

@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 16, 2015
@jdm jdm added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Mar 26, 2015
@vi
Copy link
Contributor

vi commented Apr 12, 2015

Another case:
macro_rules! q { ($($w:ident,$t:$ident)*) => {}} q!();

Playpen: http://is.gd/CYZPiW

@ehiggs
Copy link

ehiggs commented Apr 12, 2015

I had a crash in a bad macro which hits the same bug as @vi. Note that his/her error has the following which is a different stack trace:

error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Cannot fill in a NT', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/ext/tt/macro_parser.rs:236


playpen: application terminated with error code 101

I'm on the latest beta; not nightly.

@Nashenas88
Copy link
Contributor

@ehiggs I think you and I are getting a different panic from this bug. I've opened #27092 since the panic is in a different location in the code.

bossmc added a commit to bossmc/rust that referenced this issue Jul 24, 2015
bors added a commit that referenced this issue Jul 25, 2015
…matsakis

This introduces a test for #23389 and improves the error behaviour to treat the malformed LHS as an error, not a compiler bug.

The parse phase that precedes the call to `check_lhs_nt_follows` could possibly be enhanced to police the format itself (which the old code suggests was the original intention), but I'm not sure that's any nicer than just parsing the matcher as generic rust code and then policing the specific requirements for being a macro matcher afterwards (as this does).

Fixes #23389
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, ..) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants