Skip to content

Compiler gives internal error during macro expansion. #68605

Closed
@MichaelBurge

Description

@MichaelBurge

Steps to replicate:

  1. Create two files a.rs and b.rs in the same directory with the following content:
// a.rs
pub struct ProjectileCreated;
pub struct NotificationChannel<E>(std::marker::PhantomData<E>);

macro_rules! define_trigger_system {
    ($(( $field:ident, $ty:ident, $channel:ident )),* $(,)?) => {
        #[macro_export]
        macro_rules! all_trigger_fields {
            ($submacro:ident) => { $submacro!($( ( $field, $ty, $channel ) ),*) }
        }
    }
}

define_trigger_system!(
    ( projectile_created,   ProjectileCreated,   NotificationChannel ),
);
// b.rs
extern crate a;
use a::*;

macro_rules! make_event_subscription {
    ($(( $field:ident, $ty:ident, $channel:ident)),*) => {
        pub struct EventSubscription (
            $($channel<a::$ty>::ReaderId),*
        );
    }
}

all_trigger_fields!(make_event_subscription);
  1. Compile both files
$ rustc a.rs --crate-type=lib
$ rustc b.rs --extern a=liba.rlib --crate-type=lib
  1. Observe the following error
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: DistinctSources(DistinctSources { begin: (Real("b.rs"), BytePos(0)), end: (Macros("::a::all_trigger_fields"), BytePos(6695205)) })', src/librustc_errors/emitter.rs:2106:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.42.0-nightly (c2d141df5 2020-01-24) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

error: aborting due to previous error

I note that the (Macros("::a::all_trigger_fields"), BytePos(6695205)) looks quite suspicious, since there are fewer than 6695205 bytes in the source text.

This issue has been assigned to @MichaelBurge via this comment.

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.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.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions