Skip to content

Const generic type parameter in trait declaration ICE #60503

Closed
@scooter-dangle

Description

@scooter-dangle

Const generic type parameter in trait declaration causes ICE.

Looks similar to #44580 (comment)

I tried this code:

trait Blarg<const T: ()> {}

I don't know enough about the const generics plan to know whether they'll be supported for traits, but I got internal compiler errors on Nightly and Beta with the above line.

Meta

Nightly

rustc +nightly --version --verbose:

rustc 1.36.0-nightly (08bfe1612 2019-05-02)
binary: rustc
commit-hash: 08bfe16129b0621bc90184f8704523d4929695ef
commit-date: 2019-05-02
host: x86_64-unknown-linux-gnu
release: 1.36.0-nightly
LLVM version: 8.0

Backtrace (running echo 'trait Blarg<const T: ()> {}' > blarg.rs; env RUST_BACKTRACE=full rustc +nightly blarg.rs --verbose):

error[E0658]: const generics are unstable
 --> blarg.rs:1:19
  |
1 | trait Blarg<const T: ()> {}
  |                   ^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/44580
  = help: add #![feature(const_generics)] to the crate attributes to enable

error[E0601]: `main` function not found in crate `blarg`
  |
  = note: consider adding a `main` function to `blarg.rs`

error: internal compiler error: src/librustc/ty/subst.rs:581: Const parameter `T/#1` (Const { ty: (), val: Param(T/#1) }/1) out of range when substituting (root type=None) substs=[[type error], [type error]]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:578:9
stack backtrace:
   0:     0x7fbb4b457e03 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h75ed5e865cdebc75
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:     0x7fbb4b44fc8b - std::sys_common::backtrace::_print::h654b06bdc2b75c8d
                               at src/libstd/sys_common/backtrace.rs:71
   2:     0x7fbb4b454066 - std::panicking::default_hook::{{closure}}::hfe6e5dcc8fbd91f3
                               at src/libstd/sys_common/backtrace.rs:59
                               at src/libstd/panicking.rs:197
   3:     0x7fbb4b453df9 - std::panicking::default_hook::h4f9e2851764cc35e
                               at src/libstd/panicking.rs:211
   4:     0x7fbb4878d330 - rustc::util::common::panic_hook::hfaa59e30d20c7e40
   5:     0x7fbb4b454858 - std::panicking::rust_panic_with_hook::ha8510f1c8796bf60
                               at src/libstd/panicking.rs:478
   6:     0x7fbb487a7cbc - std::panicking::begin_panic::h65c416bcbeacff99
   7:     0x7fbb484f5bbc - rustc_errors::Handler::span_bug::h82cc068d77f40b2c
   8:     0x7fbb484e1dbd - rustc::util::bug::opt_span_bug_fmt::{{closure}}::hcf74c8c5fb308c55
   9:     0x7fbb484e0bb9 - rustc::ty::context::tls::with_opt::{{closure}}::h40bddc1770f7e8f4
  10:     0x7fbb484e0ad4 - rustc::ty::context::tls::with_context_opt::hf3e530b00cfbe185
  11:     0x7fbb484e0b66 - rustc::ty::context::tls::with_opt::hd1bcd52cc494ec61
  12:     0x7fbb484e1cc7 - rustc::util::bug::opt_span_bug_fmt::h1e54df0d932dca8c
  13:     0x7fbb484e1c79 - rustc::util::bug::span_bug_fmt::hfeb6ba79623b7bbf
  14:     0x7fbb484e0a57 - <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const::h11ebabc9dd507b4b
  15:     0x7fbb45845412 - rustc::ty::fold::TypeFoldable::fold_with::h618f18db8c4f0b87
  16:     0x7fbb459c222f - <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter::hac59ccc0d1c77cf5
  17:     0x7fbb457f8fba - rustc::ty::fold::TypeFoldable::fold_with::h1c0d132df40c48d0
  18:     0x7fbb457fd468 - rustc::ty::subst::Subst::subst::hc0d88dfcb25bf13b
  19:     0x7fbb45986712 - <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next::h91ec133947d44dd4
  20:     0x7fbb4598a40f - rustc_typeck::check::wfcheck::check_where_clauses::h5a6af835ccd1bcdb
  21:     0x7fbb459135a8 - rustc::ty::context::GlobalCtxt::enter_local::h162a93e9f9e3cac3
  22:     0x7fbb45989af9 - rustc_typeck::check::wfcheck::check_trait::h44f16dde15b3ca3c
  23:     0x7fbb459885ba - rustc_typeck::check::wfcheck::check_item_well_formed::h0932b737e0fd6357
  24:     0x7fbb45799c9d - rustc::ty::query::__query_compute::check_item_well_formed::h63842f73f6b4f101
  25:     0x7fbb4588930c - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute::h7232de0245253e2e
  26:     0x7fbb4585b441 - rustc::dep_graph::graph::DepGraph::with_task_impl::hadc746ef53090285
  27:     0x7fbb458ca587 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h73b34b270331c245
  28:     0x7fbb4598cff6 - <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_item::hde9438c5ee95839d
  29:     0x7fbb4b465629 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  30:     0x7fbb457bab58 - rustc_data_structures::sync::par_for_each_in::hfcb30dde557e9e6c
  31:     0x7fbb4b465629 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  32:     0x7fbb459748c2 - rustc::hir::Crate::par_visit_all_item_likes::h3e67b619fa7268ad
  33:     0x7fbb45826a9c - rustc::util::common::time::heb79af6f211cfde0
  34:     0x7fbb4595c2ae - rustc_typeck::check_crate::h56e505c02581a4d2
  35:     0x7fbb4a64d8b1 - rustc_interface::passes::analysis::h0f69f13457d31dbe
  36:     0x7fbb4b71b6c5 - rustc::ty::query::__query_compute::analysis::h92b170307e89c76f
  37:     0x7fbb4b772568 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute::h896f266638f083f3
  38:     0x7fbb4b744d17 - rustc::dep_graph::graph::DepGraph::with_task_impl::h8c15abd90ae4100a
  39:     0x7fbb4b778380 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::he8b2155d5bd6653b
  40:     0x7fbb4b71bce5 - rustc::ty::context::tls::enter_global::h93036bb038b9e308
  41:     0x7fbb4b734846 - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::h91d09e4478429b07
  42:     0x7fbb4a6a0044 - rustc_interface::passes::create_global_ctxt::{{closure}}::hd2e3a526a3c011f9
  43:     0x7fbb4b736407 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h57c99d988ccdcb18
  44:     0x7fbb4b7b5ee5 - std::thread::local::LocalKey<T>::with::hdf016f5152b1473c
  45:     0x7fbb4b781514 - scoped_tls::ScopedKey<T>::set::h9ce6ab2eb2a93f76
  46:     0x7fbb4b7b1651 - syntax::with_globals::hb7c01dcd2cbb66f0
  47:     0x7fbb4b70dfa4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1016d7a01d215890
  48:     0x7fbb4b465629 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  49:     0x7fbb4b728958 - core::ops::function::FnOnce::call_once{{vtable.shim}}::he3b870301f0c15eb
  50:     0x7fbb4b43676e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h9b629b591fe21293
                               at /rustc/08bfe16129b0621bc90184f8704523d4929695ef/src/liballoc/boxed.rs:704
  51:     0x7fbb4b46429f - std::sys::unix::thread::Thread::new::thread_start::h8866c00e15df9ebd
                               at /rustc/08bfe16129b0621bc90184f8704523d4929695ef/src/liballoc/boxed.rs:704
                               at src/libstd/sys_common/thread.rs:13
                               at src/libstd/sys/unix/thread.rs:79
  52:     0x7fbb4b1d36da - start_thread
  53:     0x7fbb4aaf088e - __clone
  54:                0x0 - <unknown>
query stack during panic:
#0 [check_item_well_formed] processing `Blarg`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.

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.36.0-nightly (08bfe1612 2019-05-02) running on x86_64-unknown-linux-gnu

Beta

rustc +beta --version --verbose:

rustc 1.35.0-beta.3 (c13114dc8 2019-04-27)
binary: rustc
commit-hash: c13114dc86968bdabfdaa1d9585a3907d94e9bf6
commit-date: 2019-04-27
host: x86_64-unknown-linux-gnu
release: 1.35.0-beta.3
LLVM version: 8.0

Backtrace (running echo 'trait Blarg<const T: ()> {}' > blarg.rs; env RUST_BACKTRACE=full rustc +beta blarg.rs --verbose):

error[E0658]: const generics are unstable (see issue #44580)
 --> blarg.rs:1:19
  |
1 | trait Blarg<const T: ()> {}
  |                   ^

error[E0601]: `main` function not found in crate `blarg`
  |
  = note: consider adding a `main` function to `blarg.rs`

error: internal compiler error: src/librustc/ty/subst.rs:572: Const parameter `T/#1` (Const { ty: (), val: Param(T/#1) }/1) out of range when substituting (root type=None) substs=[[type error], [type error]]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:570:9
stack backtrace:
   0:     0x7f8aaea37d63 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h1fe7d24a7f381a54
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:     0x7f8aaea2fbeb - std::sys_common::backtrace::_print::h1d2c17a93337bccc
                               at src/libstd/sys_common/backtrace.rs:71
   2:     0x7f8aaea33fc6 - std::panicking::default_hook::{{closure}}::h30b58ce6856e47b8
                               at src/libstd/sys_common/backtrace.rs:59
                               at src/libstd/panicking.rs:197
   3:     0x7f8aaea33d59 - std::panicking::default_hook::h12c248c832647f2e
                               at src/libstd/panicking.rs:211
   4:     0x7f8aabff4bf0 - rustc::util::common::panic_hook::h9d01aae5f4212d42
   5:     0x7f8aaea347b8 - std::panicking::rust_panic_with_hook::h35a529ee15f5e49c
                               at src/libstd/panicking.rs:478
   6:     0x7f8aabf784ac - std::panicking::begin_panic::h30ed580cf40b4858
   7:     0x7f8aabd144ec - rustc_errors::Handler::span_bug::heb3c5f97b151cb55
   8:     0x7f8aabe746ac - rustc::util::bug::opt_span_bug_fmt::{{closure}}::hb6769dec8aaef110
   9:     0x7f8aabe71c69 - rustc::ty::context::tls::with_opt::{{closure}}::hde5d2d50cdd04f16
  10:     0x7f8aabe71b84 - rustc::ty::context::tls::with_context_opt::he2edfd84e2cc7603
  11:     0x7f8aabe71c16 - rustc::ty::context::tls::with_opt::h7183578713516120
  12:     0x7f8aabe745b4 - rustc::util::bug::opt_span_bug_fmt::h4eb7491604cbb872
  13:     0x7f8aabe7455f - rustc::util::bug::span_bug_fmt::hffb4138d529ffc5b
  14:     0x7f8aabe71343 - <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const::h45ac45ac81e6b5a4
  15:     0x7f8aa8fa7282 - rustc::ty::fold::TypeFoldable::fold_with::h232c1dc2f4447527
  16:     0x7f8aa8d8daff - <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter::h94b91fef76025e0e
  17:     0x7f8aa8e0197a - rustc::ty::fold::TypeFoldable::fold_with::h5d298e1bac722225
  18:     0x7f8aa8e0381d - rustc::ty::subst::Subst::subst::h0bd5e773f048bcdb
  19:     0x7f8aa8d79515 - <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next::h0c0aed736f7865ae
  20:     0x7f8aa8d7b9ca - rustc_typeck::check::wfcheck::check_where_clauses::h169196d137a03a00
  21:     0x7f8aa8f29fd4 - rustc::ty::context::GlobalCtxt::enter_local::h17bd7f463c513654
  22:     0x7f8aa8d7af27 - rustc_typeck::check::wfcheck::check_trait::h4ce399524684b5c4
  23:     0x7f8aa8d79a57 - rustc_typeck::check::wfcheck::check_item_well_formed::h1d6f94eea5f50c85
  24:     0x7f8aa8dbdb7a - rustc::ty::query::__query_compute::check_item_well_formed::h4eab0c298ec65356
  25:     0x7f8aa8eb860c - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute::h3e2299d72b2aad48
  26:     0x7f8aa8e49638 - rustc::dep_graph::graph::DepGraph::with_task_impl::h94d38b8f9a070345
  27:     0x7f8aa8f2781f - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hfb5e7c0bf915757b
  28:     0x7f8aa8d7e8e6 - <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_item::h930ed4f33e28ab38
  29:     0x7f8aaea45499 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:87
  30:     0x7f8aa8df74e8 - rustc_data_structures::sync::par_for_each_in::h43475358ad3e972c
  31:     0x7f8aaea45499 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:87
  32:     0x7f8aa8d76602 - rustc::hir::Crate::par_visit_all_item_likes::ha3a4404802aad0ed
  33:     0x7f8aa8f6d66c - rustc::util::common::time::hd369a3ae77180251
  34:     0x7f8aa8fb0df0 - rustc_typeck::check_crate::hba0df245a599b5ad
  35:     0x7f8aadc791d3 - rustc_interface::passes::analysis::h6620eb2daf0ea7ee
  36:     0x7f8aaed13752 - rustc::ty::query::__query_compute::analysis::hc11459207dd25cc1
  37:     0x7f8aaed45b68 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute::hf1d2252137960320
  38:     0x7f8aaed22491 - rustc::dep_graph::graph::DepGraph::with_task_impl::h8e83ea9513be6300
  39:     0x7f8aaed49ede - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::he57acd908a535262
  40:     0x7f8aaed0a669 - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::h2b9a08ace81c16ad
  41:     0x7f8aadcbbf04 - rustc_interface::passes::create_global_ctxt::{{closure}}::ha119471bc1cd9106
  42:     0x7f8aaed0d068 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h3686706017e53193
  43:     0x7f8aaeced9d3 - std::thread::local::LocalKey<T>::with::h29fea351b8a6a0bf
  44:     0x7f8aaed53064 - scoped_tls::ScopedKey<T>::set::hd828ed607a6f00e9
  45:     0x7f8aaed83b2f - syntax::with_globals::haa40f606fc8eeb46
  46:     0x7f8aaecef547 - std::sys_common::backtrace::__rust_begin_short_backtrace::h6985801c284bced5
  47:     0x7f8aaea45499 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:87
  48:     0x7f8aaed0ea18 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h3d7f9f83fa16a1fd
  49:     0x7f8aaea16eee - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h399fb300870ce527
                               at /rustc/c13114dc86968bdabfdaa1d9585a3907d94e9bf6/src/liballoc/boxed.rs:702
  50:     0x7f8aaea441ff - std::sys::unix::thread::Thread::new::thread_start::h64c93d02c3f56b92
                               at /rustc/c13114dc86968bdabfdaa1d9585a3907d94e9bf6/src/liballoc/boxed.rs:702
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:80
  51:     0x7f8aae7b46da - start_thread
  52:     0x7f8aae0d188e - __clone
  53:                0x0 - <unknown>
query stack during panic:
#0 [check_item_well_formed] processing `Blarg`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors occurred: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.

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.35.0-beta.3 (c13114dc8 2019-04-27) running on x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

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) ❄️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