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

ICE when using cfg_if and defining a macro with macro_rules twice. #58490

Closed
theypsilon opened this issue Feb 15, 2019 · 4 comments · Fixed by #69966
Closed

ICE when using cfg_if and defining a macro with macro_rules twice. #58490

theypsilon opened this issue Feb 15, 2019 · 4 comments · Fixed by #69966
Labels
A-resolve Area: Path resolution C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been 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.

Comments

@theypsilon
Copy link
Contributor

Compiler crash when using cfg_if and defining a macro with macro_rules twice.

I tried this code:

// file lib.rs
#[macro_use]
extern crate cfg_if;

mod test;
mod foo;

// file foo.rs
cfg_if! {
    if #[cfg(unix)] {
#[macro_export]
macro_rules! foo {
    ( $x:expr, $y:expr ) => {
        ($x + $y)
    };
}
    }
}

#[macro_export]
macro_rules! foo {
    ( $x:expr, $y:expr ) => {
        ($x + $y)
    };
}

//file test.rs
use crate::foo;

#[test]
fn test_true() {
    assert_eq!(foo!(1, 2), 3);
}

In a repo: https://github.com/theypsilon/rust-bug-crash-cfg-if-macro

I expected to see this happen:

error: a macro namedfoohas already been exported

Instead, this happened:

error: internal compiler error: unexpected panic

Meta

rustc --version --verbose:

rustc 1.32.0-beta.1 (eb53c1039 2018-12-05)
binary: rustc
commit-hash: eb53c1039300a8bc8f8e4b29659ddc80b1e81b68
commit-date: 2018-12-05
host: x86_64-unknown-linux-gnu
release: 1.32.0-beta.1
LLVM version: 8.0

Backtrace:

   Compiling rust-bug v0.1.0 (/mnt/c/Users/Jose/Documents/Workspace/rust-bug)
thread 'rustc' panicked at 'src/librustc_resolve/resolve_imports.rs:941: inconsistent resolution for an import', src/librustc/util/bug.rs:47:26
thread 'rustc' panicked at 'src/librustc_resolve/resolve_imports.rs:941: inconsistent resolution for an import', src/librustc/util/bug.rs:47:26
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:211
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:495
   6: std::panicking::begin_panic
   7: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   8: rustc::ty::context::tls::with_opt::{{closure}}
   9: rustc::ty::context::tls::with_context_opt
  10: rustc::ty::context::tls::with_opt
  11: rustc::util::bug::opt_span_bug_fmt
  12: rustc::util::bug::span_bug_fmt
  13: rustc_resolve::resolve_imports::ImportResolver::finalize_import::{{closure}}
  14: rustc_resolve::resolve_imports::ImportResolver::finalize_imports
  15: rustc_resolve::Resolver::resolve_crate
  16: rustc::util::common::time
  17: rustc_driver::driver::phase_2_configure_and_expand
  18: rustc_driver::driver::compile_input
  19: rustc_driver::run_compiler_with_pool
  20: <scoped_tls::ScopedKey<T>>::set
  21: rustc_driver::run_compiler
  22: rustc_driver::monitor::{{closure}}
  23: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  24: <F as alloc::boxed::FnBox<A>>::call_box
  25: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/eb53c1039300a8bc8f8e4b29659ddc80b1e81b68/src/liballoc/boxed.rs:683
             at src/libstd/sys_common/thread.rs:24
             at src/libstd/sys/unix/thread.rs:90
  26: start_thread
  27: __clone
query stack during panic:
end of query stack

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.32.0-beta.1 (eb53c1039 2018-12-05) running on x86_64-unknown-linux-gnu

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

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

error: Could not compile `rust-bug`.
warning: build failed, waiting for other jobs to finish...
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:211
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:495
   6: std::panicking::begin_panic
   7: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   8: rustc::ty::context::tls::with_opt::{{closure}}
   9: rustc::ty::context::tls::with_context_opt
  10: rustc::ty::context::tls::with_opt
  11: rustc::util::bug::opt_span_bug_fmt
  12: rustc::util::bug::span_bug_fmt
  13: rustc_resolve::resolve_imports::ImportResolver::finalize_import::{{closure}}
  14: rustc_resolve::resolve_imports::ImportResolver::finalize_imports
  15: rustc_resolve::Resolver::resolve_crate
  16: rustc::util::common::time
  17: rustc_driver::driver::phase_2_configure_and_expand
  18: rustc_driver::driver::compile_input
  19: rustc_driver::run_compiler_with_pool
  20: <scoped_tls::ScopedKey<T>>::set
  21: rustc_driver::run_compiler
  22: rustc_driver::monitor::{{closure}}
  23: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  24: <F as alloc::boxed::FnBox<A>>::call_box
  25: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/eb53c1039300a8bc8f8e4b29659ddc80b1e81b68/src/liballoc/boxed.rs:683
             at src/libstd/sys_common/thread.rs:24
             at src/libstd/sys/unix/thread.rs:90
  26: start_thread
  27: __clone
query stack during panic:
end of query stack

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.32.0-beta.1 (eb53c1039 2018-12-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental

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

error: Could not compile `rust-bug`.

To learn more, run the command again with --verbose.
@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. A-resolve Area: Path resolution labels Feb 15, 2019
@theypsilon theypsilon changed the title Compiler crash when using cfg_if and defining a macro with macro_rules twice. ICE when using cfg_if and defining a macro with macro_rules twice. Feb 16, 2019
@jethrogb
Copy link
Contributor

jethrogb commented Mar 2, 2019

Regression from stable to stable (works in 1.30).

Reduced test case:

#![allow(duplicate_macro_exports)]
macro_rules! a {
    ( @1 $i:item ) => {
        a! { @2 $i }
    };
    ( @2 $i:item ) => {
        $i
    };
}
mod b {
    a! {
        @1
        #[macro_export]
        macro_rules! b { () => () }
    }
    #[macro_export]
    macro_rules! b { () => () }
}
mod c {
    use crate::b;
}

@petrochenkov
Copy link
Contributor

#![allow(duplicate_macro_exports)] mode is implemented on best effort basis, generally unsupported and will be removed in some time.

@petrochenkov
Copy link
Contributor

Ah, I see, the original issue doesn't have it.
I'll investigate.

@petrochenkov petrochenkov self-assigned this Mar 2, 2019
@Centril
Copy link
Contributor

Centril commented Mar 10, 2020

Reproducer in #58490 (comment) no longer ICEs.

@Centril Centril added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Mar 10, 2020
Centril added a commit to Centril/rust that referenced this issue Mar 13, 2020
@bors bors closed this as completed in 93da9d7 Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Path resolution C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants