Skip to content

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

Closed

Description

@sugar700

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]

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Mar 14, 2019
  2. self-assigned this
    on Mar 15, 2019
  3. petrochenkov commented on Mar 15, 2019

    @petrochenkov
    Contributor

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

  4. estebank commented on Dec 14, 2019

    @estebank
    Contributor

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

    _ => unreachable!(),

  5. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Dec 14, 2019
  6. added a commit that references this issue on Jan 14, 2020
  7. daboross commented on Feb 2, 2020

    @daboross
    Contributor

    Just submitted a PR to fix this - #68758

  8. added a commit that references this issue on Feb 4, 2020
    48ea0fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions