Skip to content

ICE on Rust 1.51 with min const generics and Deref<Target=[T; N]> #83704

Closed
@jgallagher

Description

@jgallagher

Hi! I ran into an ICE experimenting with a wrapper that would hold a Vec's length. I've tried to minimize it and made it this far:

Code

use std::ops::Deref;

struct VecWrapper<T, const N: usize>(Vec<T>);

impl<T, const N: usize> VecWrapper<T, N> {
    pub fn new() -> Self {
        todo!()
    }
}

impl<T, const N: usize> Deref for VecWrapper<T, N> {
    type Target = [T; N];

    fn deref(&self) -> &Self::Target {
        todo!()
    }
}

fn foo() -> VecWrapper<i32, 10> {
    let tv = VecWrapper::new();
    let _ = tv.len(); // required to trigger ICE?
    tv
}

Meta

1.51, beta, and nightly all ICE for me:

rustc --version --verbose:

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1

rustup run beta rustc --version --verbose:

rustc 1.52.0-beta.2 (4f27db695 2021-03-26)
binary: rustc
commit-hash: 4f27db6956dbd50bb3ce92a73e344d1d02bb1a63
commit-date: 2021-03-26
host: x86_64-apple-darwin
release: 1.52.0-beta.2
LLVM version: 12.0.0

rustup run nightly rustc --version --verbose:

rustc 1.53.0-nightly (07e0e2ec2 2021-03-24)
binary: rustc
commit-hash: 07e0e2ec268c140e607e1ac7f49f145612d0f597
commit-date: 2021-03-24
host: x86_64-apple-darwin
release: 1.53.0-nightly
LLVM version: 12.0.0

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 9 but the index is 13', /Users/runner/.cargo/registry/src/6github.com-1ecc6299db9ec823/ena-0.14.0/src/snapshot_vec.rs:199:10
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.51.0 (2fd73fabe 2021-03-23) running on x86_64-apple-darwin

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

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

query stack during panic:
#0 [typeck] type-checking `foo`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: could not compile `reproduce-ice`
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 9 but the index is 13', /Users/runner/.cargo/registry/src/6github.com-1ecc6299db9ec823/ena-0.14.0/src/snapshot_vec.rs:199:10
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: rustc_infer::infer::type_variable::TypeVariableTable::probe
   4: rustc_infer::infer::type_variable::TypeVariableTable::replace_if_possible
   5: <rustc_infer::infer::sub::Sub as rustc_middle::ty::relate::TypeRelation>::tys
   6: rustc_middle::ty::relate::super_relate_tys
   7: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::super_combine_tys
   8: <rustc_infer::infer::sub::Sub as rustc_middle::ty::relate::TypeRelation>::tys
   9: rustc_middle::ty::relate::super_relate_tys
  10: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::super_combine_tys
  11: <rustc_infer::infer::sub::Sub as rustc_middle::ty::relate::TypeRelation>::tys
  12: rustc_infer::infer::at::At::sub_exp
  13: rustc_typeck::check::method::confirm::ConfirmContext::confirm
  14: rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method
  15: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_coercable_to_type
  18: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_decl_local
  19: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  20: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  24: rustc_typeck::check::check::check_fn
  25: rustc_infer::infer::InferCtxtBuilder::enter
  26: rustc_typeck::check::typeck
  27: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  28: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  29: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  30: rustc_data_structures::stack::ensure_sufficient_stack
  31: rustc_query_system::query::plumbing::force_query_with_job
  32: rustc_query_system::query::plumbing::get_query_impl
  33: rustc_query_system::query::plumbing::ensure_query_impl
  34: rustc_typeck::check::typeck_item_bodies
  35: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  36: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  37: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  38: rustc_data_structures::stack::ensure_sufficient_stack
  39: rustc_query_system::query::plumbing::force_query_with_job
  40: rustc_query_system::query::plumbing::get_query_impl
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  44: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  45: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  46: rustc_data_structures::stack::ensure_sufficient_stack
  47: rustc_query_system::query::plumbing::force_query_with_job
  48: rustc_query_system::query::plumbing::get_query_impl
  49: rustc_interface::passes::QueryContext::enter
  50: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  51: rustc_span::with_source_map
  52: rustc_interface::interface::create_compiler_and_run
  53: rustc_span::with_session_globals
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.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-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