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

Compiler hangs and eats memory on malformed macro extension #37234

Closed
caryoscelus opened this issue Oct 17, 2016 · 2 comments
Closed

Compiler hangs and eats memory on malformed macro extension #37234

caryoscelus opened this issue Oct 17, 2016 · 2 comments

Comments

@caryoscelus
Copy link

macro_rules! failed {
    () => {{
        let x = 5 "";
    }}
}

fn main() {
    failed!();
//    let x = 5 ""; //fails normally
}

rustc successfully detects error, but then never returns and starts eating memory

error: expected one of `.`, `;`, `?`, or an operator, found `""`
 --> fail.rs:3:19
  |
3 |         let x = 5 "";
  |                   ^^

Version info:

rustc 1.12.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.12.0

I'm using version from Debian (unstable) repository.

@TimNN
Copy link
Contributor

TimNN commented Oct 17, 2016

Likely related to #37113 and #33136.

bors added a commit that referenced this issue Nov 11, 2016
Don't spin expanding stmt macros.

If we can't make progress when parsing a macro expansion as a statement then we should just bail.

This alleviates the symptoms shown in e.g. #37113 and #37234 but it doesn't fix the problem that parsing invalid enum bodies (and others) leaves the parser in a crappy state.

I'm not sold on this strategy (checking `tokens_consumed`), so if anyone has a better idea, I'm all ears!
@Mark-Simulacrum
Copy link
Member

Closing.

error: expected one of `.`, `;`, `?`, or an operator, found `""`
 --> test.rs:3:19
  |
3 |         let x = 5 "";
  |                  -^^ unexpected token
  |                  |
  |                  expected one of `.`, `;`, `?`, or an operator here

error: macro expansion ignores token `}` and any following
 --> test.rs:4:5
  |
4 |     }}
  |     ^
  |
note: caused by the macro expansion here; the usage of `failed!` is likely invalid in statement context
 --> test.rs:8:5
  |
8 |     failed!();
  |     ^^^^^^^^^^

error: aborting due to 2 previous errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants