Closed
Description
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 named
foohas 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.
Metadata
Metadata
Assignees
Labels
Area: Name/path resolution done by `rustc_resolve` specificallyCategory: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.