Closed
Description
I get a compiler crash when running the following code.
I get the crash with or without #![feature(associated_consts)]
at the top of the file, but I don't get it if I generate a normal constant, if I replace the stringify!(abc)
with a string literal, or if I write the code the macro generates directly into the source instead of generating it through a macro.
I tried this code:
trait MyTrait {
const MY_CONST: &'static str;
}
macro_rules! my_macro {
() => {
struct MyStruct;
impl MyTrait for MyStruct {
// Note the stringify here, without it I don't get a crash.
const MY_CONST: &'static str = stringify!(abc);
}
}
}
my_macro!();
fn main() {}
Error message:
thread 'rustc' panicked at 'adding a def'n for node-id NodeId(3) and data Initializer but a previous def'n exists: DefData { key: DefKey { parent: Some(DefIndex(0)), disambiguated_data: DisambiguatedDefPathData { data: TypeNs("std"), disambiguator: 0 } }, node_id: NodeId(3) }', ../src/librustc/hir/map/definitions.rs:279
Meta
rustc --version --verbose
:
rustc 1.15.0-nightly (c80c31a50 2016-12-02)
binary: rustc
commit-hash: c80c31a502c838f9ec06f1003d7c61cf9de9d551
commit-date: 2016-12-02
host: x86_64-apple-darwin
release: 1.15.0-nightly
LLVM version: 3.9
Backtrace:
stack backtrace:
1: 0x1102ed0da - std::sys::imp::backtrace::tracing::imp::write::hbea47d9dd19b523c
2: 0x1102fa3cf - std::panicking::default_hook::{{closure}}::h6875a2976258b020
3: 0x1102f9f7d - std::panicking::default_hook::h88ffbc5922643264
4: 0x1102fa896 - std::panicking::rust_panic_with_hook::hc790e47d4ecc86cd
5: 0x1102fa734 - std::panicking::begin_panic::hc066339e2fdc17d1
6: 0x1102fa652 - std::panicking::begin_panic_fmt::h5912b2d2df332044
7: 0x10cbdc3c5 - rustc::hir::map::definitions::Definitions::create_def_with_parent::h9f915077b7729a67
8: 0x10cbd7275 - <rustc::hir::map::def_collector::DefCollector<'a> as syntax::visit::Visitor>::visit_impl_item::hfd39f06fd36cebc4
9: 0x10cb68201 - syntax::visit::walk_item::hf2d1c4f2e66576d9
10: 0x10cbd6c75 - <rustc::hir::map::def_collector::DefCollector<'a> as syntax::visit::Visitor>::visit_item::{{closure}}::hd7b5b0a8a329ace5
11: 0x10cbd65c2 - <rustc::hir::map::def_collector::DefCollector<'a> as syntax::visit::Visitor>::visit_item::h763ef3a101744485
12: 0x10ca5a41e - rustc_resolve::macros::<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::visit_expansion::h7d935db3784368ad
13: 0x10fd0717e - syntax::ext::expand::MacroExpander::collect_invocations::h67e2a1c913dc4591
14: 0x10fd0632e - syntax::ext::expand::MacroExpander::expand::hd3e73837bd4e019c
15: 0x10fd05456 - syntax::ext::expand::MacroExpander::expand_crate::hdb654461100f1c42
16: 0x10bae5ceb - rustc_driver::driver::phase_2_configure_and_expand::{{closure}}::h78edc3698ca57871
17: 0x10badec60 - rustc_driver::driver::phase_2_configure_and_expand::hb40d70b49cec9f8f
18: 0x10bad8840 - rustc_driver::driver::compile_input::h8e119234b60571d5
19: 0x10bb20f8b - rustc_driver::run_compiler::h57c4f233cd1a0c04
20: 0x10ba3fce8 - std::panicking::try::do_call::hf679f17bf3b43b0b
21: 0x1102fce4a - __rust_maybe_catch_panic
22: 0x10ba62bdf - <F as alloc::boxed::FnBox<A>>::call_box::h21b5b32059700da6
23: 0x1102f9514 - std::sys::imp::thread::Thread::new::thread_start::h8084b1107992ae5b
24: 0x7fff99c7eaaa - _pthread_body
25: 0x7fff99c7e9f6 - _pthread_start
error: Could not compile `BugDemo`.