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 Type parameter out of range when substituting #57781

Closed
zsinskri opened this issue Jan 20, 2019 · 1 comment · Fixed by #58743
Closed

ICE Type parameter out of range when substituting #57781

zsinskri opened this issue Jan 20, 2019 · 1 comment · Fixed by #58743
Labels
A-type-system Area: Type system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@zsinskri
Copy link

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.

@estebank estebank added A-type-system Area: Type system 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 Jan 20, 2019
@hellow554
Copy link
Contributor

hellow554 commented Feb 12, 2019

Crashes on stable and beta but not on nightly anymore. Here's an MCVE.

use std::cell::UnsafeCell;
use std::collections::HashMap;

struct OnceCell<T> {
    _value: UnsafeCell<Option<T>>,
}

impl<T> OnceCell<T> {
    const INIT: OnceCell<T> = OnceCell {
        _value: UnsafeCell::new(None),
    };
}

pub fn crash<K, T>() {
    let _ = OnceCell::<HashMap<K, T>>::INIT;
}

One might want to add an test to the collection.

Also this test is very specific to the HashMap type. I tried it with struct Foo<K, V>(K, V) and it did not crash.

@varkor varkor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 23, 2019
varkor added a commit to varkor/rust that referenced this issue Feb 26, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
…hton

Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes rust-lang#10876.
Closes rust-lang#22892.
Closes rust-lang#26448.
Closes rust-lang#26577.
Closes rust-lang#26619.
Closes rust-lang#27054.
Closes rust-lang#28587.
Closes rust-lang#44127.
Closes rust-lang#44255.
Closes rust-lang#55731.
Closes rust-lang#57781.
varkor added a commit to varkor/rust that referenced this issue Feb 27, 2019
pietroalbini added a commit to pietroalbini/rust that referenced this issue Mar 1, 2019
…hton

Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes rust-lang#10876.
Closes rust-lang#22892.
Closes rust-lang#26448.
Closes rust-lang#26577.
Closes rust-lang#26619.
Closes rust-lang#27054.
Closes rust-lang#28587.
Closes rust-lang#44127.
Closes rust-lang#44255.
Closes rust-lang#55731.
Closes rust-lang#57781.
Centril added a commit to Centril/rust that referenced this issue Mar 9, 2019
…hton

Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes rust-lang#10876.
Closes rust-lang#22892.
Closes rust-lang#26448.
Closes rust-lang#26577.
Closes rust-lang#26619.
Closes rust-lang#27054.
Closes rust-lang#28587.
Closes rust-lang#44127.
Closes rust-lang#44255.
Closes rust-lang#55731.
Closes rust-lang#57781.
Centril added a commit to Centril/rust that referenced this issue Mar 9, 2019
…hton

Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes rust-lang#10876.
Closes rust-lang#22892.
Closes rust-lang#26448.
Closes rust-lang#26577.
Closes rust-lang#26619.
Closes rust-lang#27054.
Closes rust-lang#28587.
Closes rust-lang#44127.
Closes rust-lang#44255.
Closes rust-lang#55731.
Closes rust-lang#57781.
varkor added a commit to varkor/rust that referenced this issue Mar 11, 2019
bors added a commit that referenced this issue Mar 12, 2019
Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes #10876.
Closes #26448.
Closes #26577.
Closes #26619.
Closes #27054.
Closes #44127.
Closes #44255.
Closes #55731.
Closes #57781.
varkor added a commit to varkor/rust that referenced this issue Mar 12, 2019
pietroalbini added a commit to pietroalbini/rust that referenced this issue Mar 12, 2019
…hton

Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes rust-lang#10876.
Closes rust-lang#26448.
Closes rust-lang#26577.
Closes rust-lang#26619.
Closes rust-lang#27054.
Closes rust-lang#44127.
Closes rust-lang#44255.
Closes rust-lang#55731.
Closes rust-lang#57781.
bors added a commit that referenced this issue Mar 12, 2019
Add tests for several E-needstest issues

This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise.

Closes #10876.
Closes #26448.
Closes #26577.
Closes #26619.
Closes #27054.
Closes #44127.
Closes #44255.
Closes #55731.
Closes #57781.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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