Skip to content

thread 'rustc' panicked at 'called Option::unwrap() on a None value', compiler/rustc_middle/src/hir/mod.rs:79:55 #90873

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

Closed
Badel2 opened this issue Nov 13, 2021 · 2 comments · Fixed by #91111
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@Badel2
Copy link
Contributor

Badel2 commented Nov 13, 2021

I'm seeing an internal compiler error on the following input, found by fuzz-rustc:

Code

#![u=||{static d=||1;}]

Error output

error: unexpected token: `||
    {
        static d: _ = || 1;
    }`
 --> src/lib.rs:1:6
  |
1 | #![u=||{static d=||1;}]
  |      ^^^^^^^^^^^^^^^^^

error: cannot find attribute `u` in this scope
 --> src/lib.rs:1:4
  |
1 | #![u=||{static d=||1;}]
  |    ^

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/mod.rs:79:55
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The ICE happens after correctly reporting a few other errors, because the code is nonsense, so low priority. Affected versions: I tried nightly 2021-11-12 and stable 1.56.1 and they both show the same ICE.

Backtrace

   Compiling playground v0.0.1 (/playground)
error: unexpected token: `||
    {
        static d: _ = || 1;
    }`
 --> src/lib.rs:1:6
  |
1 | #![u=||{static d=||1;}]
  |      ^^^^^^^^^^^^^^^^^

error: cannot find attribute `u` in this scope
 --> src/lib.rs:1:4
  |
1 | #![u=||{static d=||1;}]
  |    ^

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/mod.rs:79:55
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/core/src/panicking.rs:106:14
   2: core::panicking::panic
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/core/src/panicking.rs:47:5
   3: <rustc_middle::hir::provide::{closure#4} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
   4: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, rustc_hir::hir_id::HirId>>
   5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::hir_owner_parent
   6: <rustc_middle::ty::context::TyCtxt>::lint_level_at_node
   7: <rustc_typeck::check::fn_ctxt::FnCtxt>::analyze_closure
   8: rustc_hir::intravisit::walk_body::<rustc_typeck::check::upvar::InferBorrowKindVisitor>
   9: <rustc_typeck::check::fn_ctxt::FnCtxt>::closure_analyze
  10: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::diagnostic_only_typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  11: <rustc_typeck::check::inherited::InheritedBuilder>::enter::<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::diagnostic_only_typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>
  12: rustc_typeck::check::diagnostic_only_typeck
  13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  14: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::diagnostic_only_typeck, rustc_query_impl::plumbing::QueryCtxt>
  15: rustc_typeck::collect::type_of::infer_placeholder_type
  16: rustc_typeck::collect::type_of::type_of
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  18: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), <rustc_typeck::check::inherited::InheritedBuilder>::enter<<rustc_typeck::check::wfcheck::CheckWfFcxBuilder>::with_fcx<rustc_typeck::check::wfcheck::check_item_type::{closure#0}>::{closure#0}, ()>::{closure#0}>
  19: rustc_typeck::check::wfcheck::check_item_type
  20: rustc_typeck::check::wfcheck::check_item_well_formed
  21: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_item_well_formed
  23: rustc_data_structures::sync::par_for_each_in::<&alloc::vec::Vec<core::option::Option<rustc_hir::hir::OwnerInfo>>, <rustc_middle::hir::map::Map>::par_visit_all_item_likes<rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor>::{closure#0}>
  24: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#5}, ()>
  25: rustc_typeck::check_crate
  26: rustc_interface::passes::analysis
  27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  28: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  29: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  30: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  31: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  32: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  33: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.58.0-nightly (e90c5fbbc 2021-11-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [hir_owner_parent] HIR parent of `{closure#0}::d`
#1 [diagnostic_only_typeck] type-checking `{closure#0}::d`
#2 [type_of] computing type of `{closure#0}::d`
#3 [check_item_well_formed] checking that `{closure#0}::d` is well-formed
#4 [analysis] running analysis passes on this crate
end of query stack
error: missing type for `static` item
 --> src/lib.rs:1:16
  |
1 | #![u=||{static d=||1;}]
  |                ^ help: provide a type for the item: `d: <type>`

error: could not compile `playground` due to 3 previous errors

Also note how there is one additional error below the backtrace, not sure if that's expected.

@Badel2 Badel2 added 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. labels Nov 13, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Nov 14, 2021
@michaelwoerister
Copy link
Member

Thanks for the bug report, @Badel2!

@cjgillot, could this be related to the recent HIR map/lowering refactorings?

@cjgillot cjgillot self-assigned this Nov 15, 2021
@Badel2
Copy link
Contributor Author

Badel2 commented Nov 20, 2021

This issue looks very similar to #81886, but the examples from there don't panic anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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