Skip to content

Unwrap on a None value #93125

Closed
Closed
@dsxmachina

Description

@dsxmachina

Code

The project is >5000 lines of rust code + some protobuf definitions, so I can not include it here.
The error happened when I removed an branch from a match block in an async function:

    #[instrument(skip_all, name = "network-command")]
    async fn handle_command(&mut self, command: NetworkCommand) {
        match command {
          /* one field of NetworkCommand was missing here */
        }
    }

Meta

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/compiler/rustc_hir/src/definitions.rs:452:14
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
   2: core::panicking::panic
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:50:5
   3: <rustc_query_impl::on_disk_cache::OnDiskCache as rustc_middle::ty::context::OnDiskCache>::def_path_hash_to_def_id
   4: rustc_middle::dep_graph::dep_node::<impl rustc_query_system::dep_graph::dep_node::DepNodeParams<rustc_middle::ty::context::TyCtxt> for rustc_span::def_id::DefId>::recover
   5: rustc_query_system::query::plumbing::force_query
   6: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
   7: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
   8: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
   9: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  11: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  12: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  13: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  14: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory
  15: rustc_query_system::query::plumbing::get_query
  16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
  17: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  18: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  19: rustc_trait_selection::traits::fulfill::FulfillProcessor::process_trait_obligation
  20: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  21: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
  22: rustc_trait_selection::traits::fulfill::FulfillmentContext::select
  23: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_with_constness_or_error
  24: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  25: rustc_typeck::check::wfcheck::check_false_global_bounds
  26: rustc_infer::infer::InferCtxtBuilder::enter
  27: rustc_typeck::check::wfcheck::check_item_well_formed
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::try_execute_query
  31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_item_well_formed
  32: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::intravisit::Visitor>::visit_item
  33: std::panicking::try
  34: rustc_data_structures::sync::par_for_each_in
  35: rustc_session::session::Session::track_errors
  36: rustc_typeck::check_crate
  37: rustc_interface::passes::analysis
  38: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  39: rustc_data_structures::stack::ensure_sufficient_stack
  40: rustc_query_system::query::plumbing::try_execute_query
  41: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  42: rustc_interface::passes::QueryContext::enter
  43: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  44: rustc_span::with_source_map
  45: scoped_tls::ScopedKey<T>::set
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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `std::collections::hash::map::HashMap<libp2p_core::peer_id::PeerId, smallvec::SmallVec<[libp2p_request_response::handler::protocol::RequestProtocol<network::behaviour::UpdateCodec>; 10]>>: core::marker::Send`  |  = note: this failure-note originates in the derive macro `NetworkBehaviour` (in Nightly builds, run with -Z macro-backtrace for more info)

#1 [check_item_well_formed] checking that `network::behaviour::<impl at src/network/behaviour.rs:24:10: 24:26>` is well-formed
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `core-node`

I do not know what happened at all. There was an unhandled enum option somewhere in my code, but i was trying to compile anyway to view some warnings. After I added the missing enum field, everything worked fine.

Hope this helps somehow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions