Skip to content

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

Closed
@KamilaBorowska

Description

@KamilaBorowska

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]

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