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 static global allocator is defined in main function #58072

Closed
WildCryptoFox opened this issue Feb 2, 2019 · 1 comment · Fixed by #62735
Closed

ICE when static global allocator is defined in main function #58072

WildCryptoFox opened this issue Feb 2, 2019 · 1 comment · Fixed by #62735
Labels
A-allocators Area: Custom and system allocators A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. 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

@WildCryptoFox
Copy link
Contributor

While writing some doctests for a custom allocator this popped up. Easy fix for the doc test, just add # fn main() {} after the static.

playground

fn main() {
    #[global_allocator]
    static A: usize = 0;
}
Compiling playground v0.0.1 (/playground)
error[E0432]: unresolved import `super::A`
 --> src/main.rs:3:5
  |
3 |     static A: usize = 0;
  |     ^^^^^^^^^^^^^^^^^^^^ no `A` in the root

thread 'rustc' panicked at 'assertion failed: prev.is_none()', src/librustc/middle/region.rs:442:13
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::begin_panic
   7: <rustc::middle::region::RegionResolutionVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_stmt
   8: <rustc::middle::region::RegionResolutionVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_block
   9: rustc::middle::region::resolve_expr
  10: <rustc::middle::region::RegionResolutionVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body
  11: rustc::middle::region::region_scope_tree
  12: rustc::ty::query::__query_compute::region_scope_tree
  13: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::region_scope_tree<'tcx>>::compute
  14: rustc::dep_graph::graph::DepGraph::with_task_impl
  15: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  16: rustc_typeck::check::regionck::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::regionck_item
  17: rustc::ty::context::GlobalCtxt::enter_local
  18: rustc_typeck::check::wfcheck::check_item_well_formed
  19: rustc::ty::query::__query_compute::check_item_well_formed
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_item_well_formed<'tcx>>::compute
  21: rustc::dep_graph::graph::DepGraph::with_task_impl
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  24: rustc::hir::Crate::visit_all_item_likes
  25: rustc::util::common::time
  26: rustc_typeck::check_crate
  27: <std::thread::local::LocalKey<T>>::with
  28: rustc::ty::context::TyCtxt::create_and_enter
  29: rustc_driver::driver::compile_input
  30: rustc_driver::run_compiler_with_pool
  31: <scoped_tls::ScopedKey<T>>::set
  32: rustc_driver::run_compiler
  33: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
#0 [region_scope_tree] processing `main`
#1 [check_item_well_formed] processing `main`
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.

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.34.0-nightly (852701ad6 2019-02-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@Havvy Havvy added A-attributes Area: Attributes (`#[…]`, `#![…]`) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-allocators Area: Custom and system allocators labels Feb 2, 2019
@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 2, 2019
@petrochenkov
Copy link
Contributor

Fixed in #62735.

Centril added a commit to Centril/rust that referenced this issue Jul 24, 2019
Turn `#[global_allocator]` into a regular attribute macro

It was a 99% macro with exception of some diagnostic details.

As a result of the change, `#[global_allocator]` now works in nested modules and even in nameless blocks.

Fixes rust-lang#44113
Fixes rust-lang#58072
Centril added a commit to Centril/rust that referenced this issue Jul 24, 2019
Turn `#[global_allocator]` into a regular attribute macro

It was a 99% macro with exception of some diagnostic details.

As a result of the change, `#[global_allocator]` now works in nested modules and even in nameless blocks.

Fixes rust-lang#44113
Fixes rust-lang#58072
Centril added a commit to Centril/rust that referenced this issue Jul 25, 2019
Turn `#[global_allocator]` into a regular attribute macro

It was a 99% macro with exception of some diagnostic details.

As a result of the change, `#[global_allocator]` now works in nested modules and even in nameless blocks.

Fixes rust-lang#44113
Fixes rust-lang#58072
Centril added a commit to Centril/rust that referenced this issue Jul 25, 2019
Turn `#[global_allocator]` into a regular attribute macro

It was a 99% macro with exception of some diagnostic details.

As a result of the change, `#[global_allocator]` now works in nested modules and even in nameless blocks.

Fixes rust-lang#44113
Fixes rust-lang#58072
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-allocators Area: Custom and system allocators A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. 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.

4 participants