Skip to content

Using associated constant as array size leads to ICE #53067

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

Closed
rizakrko opened this issue Aug 4, 2018 · 1 comment
Closed

Using associated constant as array size leads to ICE #53067

rizakrko opened this issue Aug 4, 2018 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@rizakrko
Copy link
Contributor

rizakrko commented Aug 4, 2018

This is a repro case for #52462.
Following code:

trait T {
    const SIZE: usize;
    fn convert(self) -> [u8; T::SIZE];
}

impl T for u64 {
    const SIZE: usize = 8;
    fn convert(self) -> [u8; u64::SIZE] {
        unimplemented!()
    }
}
fn main() {}

causes compilation error:

error[E0283]: type annotations required: cannot resolve `_: T`
 --> src/main.rs:3:30
  |
3 |     fn convert(self) -> [u8; T::SIZE];
  |                              ^^^^^^^
  |
note: required by `T::SIZE`
 --> src/main.rs:2:5
  |
2 |     const SIZE: usize;
  |     ^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

However, change from

fn convert(self) -> [u8; u64::SIZE] {

to

fn convert(self) -> [u8; T::SIZE] {

causes following ICE:

error: internal compiler error: librustc/traits/codegen/mod.rs:63: Encountered ambiguity selecting `Binder(<[type error] as T>)` during codegen, presuming due to overflow

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:578:9

This can be reproduced on stable, beta and nightly. Playground

Meta

rustc 1.30.0-nightly (3edb355 2018-08-03)
binary: rustc
commit-hash: 3edb355
commit-date: 2018-08-03
host: x86_64-unknown-linux-gnu
release: 1.30.0-nightly
LLVM version: 7.0

Backtrace ``` thread 'main' panicked at 'Box', librustc_errors/lib.rs:578:9 stack backtrace: 0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::print at libstd/sys_common/backtrace.rs:71 at libstd/sys_common/backtrace.rs:59 2: std::panicking::default_hook::{{closure}} at libstd/panicking.rs:211 3: std::panicking::default_hook at libstd/panicking.rs:227 4: rustc::util::common::panic_hook 5: std::panicking::rust_panic_with_hook at libstd/panicking.rs:479 6: std::panicking::begin_panic 7: rustc_errors::Handler::bug 8: rustc::session::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::session::opt_span_bug_fmt 13: rustc::session::bug_fmt 14: rustc::ty::context::tls::with_related_context 15: rustc::traits::codegen::codegen_fulfill_obligation 16: rustc::ty::query::__query_compute::codegen_fulfill_obligation 17: rustc::ty::query:: for rustc::ty::query::queries::codegen_fulfill_obligation<'tcx>>::compute 18: rustc::ty::context::tls::with_context 19: rustc::dep_graph::graph::DepGraph::with_task_impl 20: rustc::ty::context::tls::with_related_context 21: rustc::ty::query::plumbing::>::force_query_with_job 22: rustc::ty::query::plumbing::>::get_query 23: rustc::ty::instance::Instance::resolve 24: >::resolve 25: >::const_to_value 26: rustc_mir::transform::const_prop::ConstPropagator::eval_constant 27: as rustc::mir::visit::Visitor<'tcx>>::visit_statement 28: ::run_pass 29: rustc_mir::transform::optimized_mir::{{closure}} 30: rustc_mir::transform::optimized_mir 31: rustc::ty::query::__query_compute::optimized_mir 32: rustc::ty::query:: for rustc::ty::query::queries::optimized_mir<'tcx>>::compute 33: rustc::ty::context::tls::with_context 34: rustc::dep_graph::graph::DepGraph::with_task_impl 35: rustc::ty::context::tls::with_related_context 36: rustc::ty::query::plumbing::>::force_query_with_job 37: rustc::ty::query::plumbing::>::try_get_query 38: rustc::ty::>::maybe_optimized_mir 39: >::load_mir 40: rustc_mir::interpret::const_eval::eval_body_using_ecx 41: rustc_mir::interpret::const_eval::const_eval_provider 42: rustc::ty::query::__query_compute::const_eval 43: rustc::ty::query:: for rustc::ty::query::queries::const_eval<'tcx>>::compute 44: rustc::ty::context::tls::with_context 45: rustc::dep_graph::graph::DepGraph::with_task_impl 46: rustc::ty::context::tls::with_related_context 47: rustc::ty::query::plumbing::>::force_query_with_job 48: rustc::ty::query::plumbing::>::get_query 49: as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const 50: rustc::ty::structural_impls:: for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with 51: as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty 52: as core::iter::traits::FromIterator<::Element>>::from_iter 53: rustc::ty::fold::TypeFoldable::fold_with 54: rustc::infer::InferCtxt::partially_normalize_associated_types_in 55: rustc::ty::context::tls::with_related_context 56: rustc::infer::InferCtxtBuilder::enter 57: rustc_typeck::check::wfcheck::check_associated_item 58: rustc_typeck::check::wfcheck::check_impl_item 59: rustc::ty::query:: for rustc::ty::query::queries::check_impl_item_well_formed<'tcx>>::compute 60: rustc::ty::context::tls::with_context 61: rustc::dep_graph::graph::DepGraph::with_task_impl 62: rustc::ty::context::tls::with_related_context 63: rustc::ty::query::plumbing::>::force_query_with_job 64: rustc::ty::query::plumbing::>::get_query 65: rustc::ty::query::plumbing::>::ensure_query 66: rustc::session::Session::track_errors 67: rustc::util::common::time 68: rustc_typeck::check_crate 69: rustc::ty::context::tls::enter_context 70: >::with 71: rustc::ty::context::TyCtxt::create_and_enter 72: rustc_driver::driver::compile_input 73: rustc_driver::run_compiler_with_pool 74: >::set 75: syntax::with_globals 76: as core::ops::function::FnOnce<()>>::call_once 77: __rust_maybe_catch_panic at libpanic_unwind/lib.rs:105 78: rustc_driver::run 79: rustc_driver::main 80: std::rt::lang_start::{{closure}} 81: std::panicking::try::do_call at libstd/rt.rs:59 at libstd/panicking.rs:310 82: __rust_maybe_catch_panic at libpanic_unwind/lib.rs:105 83: std::rt::lang_start_internal at libstd/panicking.rs:289 at libstd/panic.rs:392 at libstd/rt.rs:58 84: main 85: __libc_start_main 86: query stack during panic: #0 [codegen_fulfill_obligation] checking if `T` fulfills its obligations #1 [optimized_mir] processing `::convert::{{constant}}` #2 [const_eval] const-evaluating `::convert::{{constant}}` #3 [check_impl_item_well_formed] processing `::convert` end of query stack ```
@estebank estebank added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-associated-items Area: Associated items (types, constants & functions) labels Aug 7, 2018
@dtolnay
Copy link
Member

dtolnay commented Aug 13, 2018

Duplicate of #48027.

@dtolnay dtolnay closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants