Skip to content

ICE (const generics) with const generics in trait #62504

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Aloso opened this issue Jul 8, 2019 · 5 comments · Fixed by #69966
Closed

ICE (const generics) with const generics in trait #62504

Aloso opened this issue Jul 8, 2019 · 5 comments · Fixed by #69966
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aloso
Copy link
Contributor

Aloso commented Jul 8, 2019

#![feature(const_generics)]

trait HasSize {
    const SIZE: usize;
}

impl<const X: usize> HasSize for ArrayHolder<{X}> {
    const SIZE: usize = X;
}

struct ArrayHolder<const X: usize>([u32; X]);

impl<const X: usize> ArrayHolder<{X}> {
    pub const fn new() -> Self {
        ArrayHolder([0; Self::SIZE])
    }
}

fn main() {
    let mut array = ArrayHolder::new();
}

When executed in the playground:

Compiler output
error: internal compiler error: src/librustc/ty/subst.rs:597: const parameter `X/#0` (Const { ty: usize, val: Param(X/#0) }/0) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:584:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
   8: std::panicking::begin_panic
   9: rustc_errors::Handler::span_bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::span_bug_fmt
  16: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const
  17: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  18: rustc::ty::fold::TypeFoldable::fold_with
  19: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
  20: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
  21: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  22: rustc::ty::fold::TypeFoldable::fold_with
  23: rustc::traits::codegen::<impl rustc::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  24: rustc_mir::interpret::eval_context::InterpCx<M>::resolve
  25: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_const_to_op
  26: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
  27: rustc_mir::const_eval::eval_body_using_ecx
  28: rustc_mir::const_eval::const_eval_raw_provider
  29: rustc::ty::query::__query_compute::const_eval_raw
  30: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  33: rustc_mir::const_eval::const_eval_provider
  34: rustc::ty::query::__query_compute::const_eval
  35: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  36: rustc::dep_graph::graph::DepGraph::with_task_impl
  37: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  38: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  39: rustc_typeck::check::FnCtxt::check_argument_types
  40: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  41: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  42: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  43: rustc_typeck::check::FnCtxt::check_block_with_expected
  44: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  45: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  46: rustc_typeck::check::check_fn
  47: rustc::ty::context::GlobalCtxt::enter_local
  48: rustc_typeck::check::typeck_tables_of
  49: rustc::ty::query::__query_compute::typeck_tables_of
  50: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  51: rustc::dep_graph::graph::DepGraph::with_task_impl
  52: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  53: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  54: rustc_typeck::check::typeck_item_bodies
  55: rustc::ty::query::__query_compute::typeck_item_bodies
  56: rustc::dep_graph::graph::DepGraph::with_task_impl
  57: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  58: rustc::util::common::time
  59: rustc_typeck::check_crate
  60: rustc_interface::passes::analysis
  61: rustc::ty::query::__query_compute::analysis
  62: rustc::dep_graph::graph::DepGraph::with_task_impl
  63: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  64: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  65: rustc_interface::passes::create_global_ctxt::{{closure}}
  66: rustc_interface::interface::run_compiler_in_existing_thread_pool
  67: std::thread::local::LocalKey<T>::with
  68: scoped_tls::ScopedKey<T>::set
  69: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [const_eval_raw] const-evaluating `ArrayHolder::<X>::new::{{constant}}#0`
#1 [const_eval] const-evaluating + checking `ArrayHolder::<X>::new::{{constant}}#0`
#2 [typeck_tables_of] processing `ArrayHolder::<X>::new`
#3 [typeck_item_bodies] type-checking all item bodies
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.38.0-nightly (6e310f2ab 2019-07-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

EDIT: Here's the updated playground link and the new stack trace as of Jan 7, 2020:

Compiler output
error: internal compiler error: src/librustc_codegen_llvm/context.rs:886: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:889:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1057
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:195
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:215
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:476
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::bug_fmt
  20: <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of::{{closure}}
  21: <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of
  22: rustc_codegen_ssa::mir::analyze::non_ssa_locals
  23: rustc_codegen_ssa::mir::codegen_mir
  24: <rustc::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  25: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  26: rustc::dep_graph::graph::DepGraph::with_task
  27: rustc_codegen_llvm::base::compile_codegen_unit
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  30: rustc_interface::passes::start_codegen::{{closure}}
  31: rustc::util::common::time
  32: rustc_interface::passes::start_codegen
  33: rustc::ty::context::tls::enter_global
  34: rustc_interface::queries::Queries::ongoing_codegen
  35: rustc_interface::interface::run_compiler_in_existing_thread_pool
  36: scoped_tls::ScopedKey<T>::set
  37: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.42.0-nightly (da3629b05 2019-12-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden
@Centril Centril added A-const-generics Area: const generics (parameters and arguments) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 9, 2019
@Centril
Copy link
Contributor

Centril commented Jul 9, 2019

cc @davidtwco

@Centril Centril added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 9, 2019
@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-const_generics `#![feature(const_generics)]` labels Aug 6, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Aug 6, 2019
@varkor
Copy link
Member

varkor commented Sep 26, 2019

I think this is another instance of #43408. However, we can leave this issue open to remember to add a test case when it's fixed.

@varkor
Copy link
Member

varkor commented Jan 5, 2020

The original issue no longer ICEs and instead errors with:

error[E0282]: type annotations needed for `ArrayHolder<_: usize>`

which is essentially correct. However, providing the type annotations produces a new ICE:

error: internal compiler error: src/librustc_codegen_llvm/context.rs:886: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout

@chrissimpkins
Copy link
Member

In #62504 (comment)

However, providing the type annotations produces a new ICE

ICE

Source: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=bf015b5bc8498e649ed450f8413fd08b

Stack trace

   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: src/librustc_codegen_llvm/context.rs:905: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:883:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1052
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::bug_fmt
  20: <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of::{{closure}}
  21: <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of
  22: rustc_codegen_ssa::mir::analyze::non_ssa_locals
  23: rustc_codegen_ssa::mir::codegen_mir
  24: <rustc::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  25: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  26: rustc::dep_graph::graph::DepGraph::with_task
  27: rustc_codegen_llvm::base::compile_codegen_unit
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  30: rustc_session::utils::<impl rustc_session::session::Session>::time
  31: rustc_interface::passes::QueryContext::enter
  32: rustc_interface::queries::Queries::ongoing_codegen
  33: rustc_interface::interface::run_compiler_in_existing_thread_pool
  34: scoped_tls::ScopedKey<T>::set
  35: syntax::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.43.0-nightly (07a34df18 2020-02-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
end of query stack
error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@JohnTitor
Copy link
Member

Now ICE no longer occurs. I think it's fixed by #69859.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 12, 2020
Centril added a commit to Centril/rust that referenced this issue Mar 13, 2020
@bors bors closed this as completed in 93da9d7 Mar 13, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

7 participants