Closed
Description
Compiler panicks when there is function with both #[proc_macro_attribute]
and pub(super)
defined in module (not in the root of the crate).
lib.rs
:
mod m;
m.rs
:
// This function makes compiler panick:
#[proc_macro_attribute]
pub(super) fn pub_super() {}
All following functions successfully does not compile (which is fine):
// error: functions tagged with `#[proc_macro_attribute]` must currently reside in the root of the crate
#[proc_macro_attribute]
pub(crate) fn pub_crate() {}
#[proc_macro_attribute]
pub fn just_pub() {}
#[proc_macro_attribute]
fn nothing() {}
$ rustc --crate-type proc-macro lib.rs
thread 'rustc' panicked at 'path resolved multiple times (PartialRes { base_res: Def(Mod, DefId(0:0)), unresolved_segments: 0 } before, PartialRes { base_res: Def(Mod, DefId(0:0)), unresolved_segments: 0 } now)', src/librustc_resolve/lib.rs:2414:13
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.43.0-nightly (58b834344 2020-02-05) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type proc-macro
RUST_BACKTRACE=1
thread 'rustc' panicked at 'path resolved multiple times (PartialRes { base_res: Def(Mod, DefId(0:0)), unresolved_segments: 0 } before, PartialRes { base_res: Def(Mod, DefId(0:0)), unresolved_segments: 0 } now)', src/librustc_resolve/lib.rs:2414:13
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:77
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1052
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1428
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:204
9: std::panicking::default_hook
at src/libstd/panicking.rs:224
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:474
12: rust_begin_unwind
at src/libstd/panicking.rs:378
13: std::panicking::begin_panic_fmt
at src/libstd/panicking.rs:332
14: rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor::resolve_visibility_speculative
15: rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor::define_macro
16: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor as syntax::visit::Visitor>::visit_item
17: syntax::visit::walk_item
18: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor as syntax::visit::Visitor>::visit_item
19: syntax::visit::walk_item
20: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor as syntax::visit::Visitor>::visit_item
21: rustc_expand::expand::AstFragment::visit_with
22: rustc_resolve::macros::<impl rustc_expand::base::Resolver for rustc_resolve::Resolver>::visit_ast_fragment_with_placeholders
23: rustc_expand::expand::MacroExpander::collect_invocations
24: rustc_expand::expand::MacroExpander::fully_expand_fragment
25: rustc_expand::expand::MacroExpander::expand_crate
26: rustc_session::utils::<impl rustc_session::session::Session>::time
27: rustc_interface::passes::configure_and_expand_inner
28: rustc_interface::passes::configure_and_expand::{{closure}}
29: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
30: rustc_interface::passes::configure_and_expand
31: rustc_interface::queries::Queries::expansion
32: rustc_interface::interface::run_compiler_in_existing_thread_pool
33: scoped_tls::ScopedKey<T>::set
34: syntax::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.43.0-nightly (58b834344 2020-02-05) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type proc-macro
query stack during panic:
end of query stack
RUST_BACKTRACE=full
log is available here: https://gist.github.com/iliakonnov/8dbf25041e46c3861f4e1cf2237315f8#file-backtrace-full-log
I expected to see error: functions tagged with `#[proc_macro_attribute]` must currently reside in the root of the crate
instead of ICE
$ rustc --version --verbose
rustc 1.43.0-nightly (58b834344 2020-02-05)
binary: rustc
commit-hash: 58b834344fc7b9185e7a50db1ff24e5eb07dae5e
commit-date: 2020-02-05
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
UPD: Also reproduces without --crate-type proc-macro
. Just rustc lib.rs
is enough