Skip to content

Internal compiler error on implementation with 'complex' constant trait bounds #86953

Closed
@cs-t1

Description

@cs-t1

Code

The code fragment is located here : code

I narrowed down the error to the following block :

Code fragment

impl<const N: usize, const M: usize> Add<&StackBitSet<M>> for StackBitSet<N>
where
    [(); usize_count(N)]: Sized,
    [(); usize_count(M)]: Sized,
    [(); usize_count(const_min(N, M))]: Sized,
{
    type Output = StackBitSet<{ const_min(N, M) }>;

    fn add(self, other: &StackBitSet<M>) -> StackBitSet<{ const_min(N, M) }> {
        self.union(other)
    }
}

Context

I am experimenting with a naive implementation of bitsets, relying heavily on some (as I discovered) unstable features : const_evaluatable_checked and const_generics. My implementation of the Add trait is probably terribly wrong!

NB: I only get the error with the Debug preset. When building on the Release preset I don't get any error.

Meta

I only provide the data for the nightly compiler, as unstable features are not enabled on the release version.

rustc --version --verbose:

rustc 1.55.0-nightly (952fdf2a1 2021-07-05)
binary: rustc
commit-hash: 952fdf2a1119affa1b37bcacb0c49cf9f0168ac8
commit-date: 2021-07-05
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

Error output

error: internal compiler error: compiler/rustc_middle/src/ich/impls_ty.rs:94:17: StableHasher: unexpected region '_#1r

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1006:9
Backtrace

stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext> for rustc_middle::ty::sty::RegionKind>::hash_stable
   8: std::thread::local::LocalKey<T>::with
   9: rustc_query_system::dep_graph::dep_node::DepNode<K>::construct
  10: rustc_query_system::query::plumbing::get_query_impl
  11: rustc_query_system::query::plumbing::get_query
  12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_unify_abstract_consts
  13: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  14: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
  15: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  16: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_or_error
  17: rustc_infer::infer::InferCtxtBuilder::enter
  18: rustc_typeck::check::compare_method::compare_impl_method
  19: rustc_typeck::check::check::check_item_type
  20: rustc_middle::hir::map::Map::visit_item_likes_in_module
  21: rustc_typeck::check::check::check_mod_item_types
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::force_query_with_job
  25: rustc_query_system::query::plumbing::get_query_impl
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  27: rustc_session::utils::<impl rustc_session::session::Session>::time
  28: rustc_typeck::check_crate
  29: rustc_interface::passes::analysis
  30: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::force_query_with_job
  35: rustc_query_system::query::plumbing::get_query_impl
  36: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  38: rustc_span::with_source_map
  39: rustc_interface::interface::create_compiler_and_run
  40: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`F-generic_const_exprs`#![feature(generic_const_exprs)]`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.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions