Skip to content

ICE Type parameter out of range when substituting #57781

Closed
@zsinskri

Description

@zsinskri

Both nightly and stable ICE on this code:

use once_cell::sync::OnceCell;
use std::collections::HashMap;

type Cache<K, T> = OnceCell<HashMap<K, T>>;

trait Provider<K, T> {
    fn new_cache() -> Cache<K, T> {
        OnceCell::INIT
    }
}

struct Fib;

impl Provider<u32, u32> for Fib {}

fn main() {
    let _ = Fib::new_cache();
}

I expected to see this happen:
This should either compile or throw an Error explaining why it is invalid.

Instead, this happened:
Both cargo build and cargo +nightly build throw an ICE.

Meta

installed dependencies:

once_cell = "0.1.7"

rustc --version --verbose:
rustc 1.32.0 (9fda7c2 2019-01-16)
binary: rustc
commit-hash: 9fda7c2
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 8.0

rustc +nightly --version --verbose:
rustc 1.33.0-nightly (0c0c585 2019-01-19)
binary: rustc
commit-hash: 0c0c585
commit-date: 2019-01-19
host: x86_64-unknown-linux-gnu
release: 1.33.0-nightly
LLVM version: 8.0

Backtrace:

error: internal compiler error: src/librustc/ty/subst.rs:491: Type parameter `K/#1` (K/1) out of range when substituting (root type=Some(std::option::Option<std::collections::HashMap<K, T>>)) substs=[std::collections::HashMap<K, T>]

thread 'main' panicked at 'Box<Any>', src/librustc_errors/lib.rs:538:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:211
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:495
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::span_bug_fmt
  14: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  15: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  16: rustc::ty::fold::TypeFoldable::fold_with
  17: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  18: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  19: rustc::ty::fold::TypeFoldable::fold_with
  20: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  21: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  22: rustc::ty::fold::TypeFoldable::fold_with
  23: rustc::traits::codegen::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::subst_and_normalize_erasing_regions
  24: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::resolve
  25: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::run
  26: rustc_mir::const_eval::eval_body_using_ecx
  27: rustc_mir::const_eval::const_eval_raw_provider
  28: rustc::ty::query::__query_compute::const_eval_raw
  29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval_raw<'tcx>>::compute
  30: rustc::ty::context::tls::with_context
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  35: rustc::ty::query::TyCtxtAt::const_eval_raw
  36: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_eval_raw
  37: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_value_to_op
  38: rustc_mir::const_eval::const_to_op
  39: rustc_mir::transform::const_prop::ConstPropagator::eval_constant
  40: <rustc_mir::transform::const_prop::ConstPropagator<'b, 'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_statement
  41: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
  42: rustc_mir::transform::run_passes::{{closure}}
  43: rustc_mir::transform::run_passes
  44: rustc_mir::transform::optimized_mir
  45: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::optimized_mir<'tcx>>::compute
  46: rustc::ty::context::tls::with_context
  47: rustc::dep_graph::graph::DepGraph::with_task_impl
  48: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  49: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  50: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query
  51: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir
  52: rustc_mir::monomorphize::collector::collect_items_rec
  53: rustc_mir::monomorphize::collector::collect_items_rec
  54: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  55: rustc::util::common::time
  56: rustc_mir::monomorphize::collector::collect_crate_mono_items
  57: rustc::util::common::time
  58: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  59: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute
  60: rustc::ty::context::tls::with_context
  61: rustc::dep_graph::graph::DepGraph::with_task_impl
  62: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  63: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  64: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  65: rustc_codegen_ssa::base::codegen_crate
  66: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  67: rustc::util::common::time
  68: rustc_driver::driver::phase_4_codegen
  69: rustc_driver::driver::compile_input::{{closure}}
  70: rustc::ty::context::tls::enter_context
  71: <std::thread::local::LocalKey<T>>::with
  72: rustc::ty::context::TyCtxt::create_and_enter
  73: rustc_driver::driver::compile_input
  74: rustc_driver::run_compiler_with_pool
  75: <scoped_tls::ScopedKey<T>>::set
  76: rustc_driver::run_compiler
  77: rustc_driver::monitor::{{closure}}
  78: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  79: rustc_driver::run
  80: rustc_driver::main
  81: std::rt::lang_start::{{closure}}
  82: std::panicking::try::do_call
             at src/libstd/rt.rs:59
             at src/libstd/panicking.rs:310
  83: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  84: std::rt::lang_start_internal
             at src/libstd/panicking.rs:289
             at src/libstd/panic.rs:398
             at src/libstd/rt.rs:58
  85: main
  86: __libc_start_main
  87: <unknown>
query stack during panic:
#0 [const_eval_raw] const-evaluating `<once_cell::imp::OnceCell<T>>::INIT`
 --> src/main.rs:8:9
  |
8 |         OnceCell::INIT
  |         ^^^^^^^^^^^^^^
#1 [optimized_mir] processing `Provider::new_cache`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

Note:
There are multiple issues with similar titles, sorry if this is a duplicate.
Most other issues I could find seem to only affect nightly, this crashes on stable, too. #57700 panics during mir_borrowck, this in optimized_mir.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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