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

thread 'rustc' panicked at 'internal error: entered unreachable code', src/libsyntax/ext/expand.rs:289:18 #59191

Closed
KamilaBorowska opened this issue Mar 14, 2019 · 3 comments · Fixed by #68758
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@KamilaBorowska
Copy link
Contributor

This is nonsense code, but it probably shouldn't ICE.

$ cargo run --example example
   Compiling no_main v0.1.0 (/home/xfix/kod/no_main)
error[E0658]: non-builtin inner attributes are unstable (see issue #54726)
 --> examples/example.rs:1:1
  |
1 | #![no_main::no_main]
  | ^^^^^^^^^^^^^^^^^^^^

error[E0658]: custom attributes cannot be applied to modules (see issue #54727)
 --> examples/example.rs:1:1
  |
1 | #![no_main::no_main]
  | ^^^^^^^^^^^^^^^^^^^^

error[E0468]: an `extern crate` loading macros must be at the crate root

thread 'rustc' panicked at 'internal error: entered unreachable code', src/libsyntax/ext/expand.rs:289:18
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to 3 previous errors

Some errors occurred: E0468, E0658.
For more information about an error, try `rustc --explain E0468`.

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: rustc 1.33.0 (2aa4c46cf 2019-02-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `no_main`.

To learn more, run the command again with --verbose.

Cargo.toml

[package]
name = "no_main"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

src/lib.rs

extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};

#[proc_macro_attribute]
pub fn no_main(_attrs: TokenStream, input: TokenStream) -> TokenStream {
    let mut ts = TokenStream::new();
    ts.extend(vec![
        TokenTree::Ident(Ident::new("fn", Span::call_site())),
        TokenTree::Ident(Ident::new("main", Span::call_site())),
        TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
        TokenTree::Group(Group::new(Delimiter::Brace, input)),
    ]);
    ts
}

examples/example.rs

#![no_main::no_main]
@jonas-schievink jonas-schievink added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 14, 2019
@petrochenkov petrochenkov self-assigned this Mar 15, 2019
@petrochenkov
Copy link
Contributor

Crate level macro attributes are generally unsupported (see #54726 for some explanations), but they certainly shouldn't ICE.

@estebank
Copy link
Contributor

This line should emit an actual error and use FatalError.raise(); to stop compilation.

_ => unreachable!(),

@estebank estebank added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Dec 14, 2019
KamilaBorowska added a commit to KamilaBorowska/glacier that referenced this issue Jan 13, 2020
KamilaBorowska added a commit to KamilaBorowska/glacier that referenced this issue Jan 14, 2020
JohnTitor added a commit to rust-lang/glacier that referenced this issue Jan 14, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 14, 2020
@daboross
Copy link
Contributor

daboross commented Feb 2, 2020

Just submitted a PR to fix this - #68758

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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants