Skip to content

ICE: expected const for .. but found Type(..) when substituting #111397

Closed
@matthiaskrgr

Description

@matthiaskrgr

Code

rustc treereduce.out -Zdump-mir=all

#![feature(inherent_associated_types, generic_const_exprs)]

struct Parent<const O: usize>;

impl<const O: usize> Parent<O> {
    type Mapping<const I: usize> = Store<{ O + I }>
    where
        [(); O + I]:
    ;
}

struct Store<const N: usize>;

impl<const N: usize> Store<N> {
    fn reify() -> usize {
        N
    }
}

fn main() {
    let _ = Parent::<1>::Mapping::<{ 2 * 5 }>::reify();
}

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (f7b831ac8 2023-05-09)
binary: rustc
commit-hash: f7b831ac8a897273f78b9f47165cf8e54066ce4b
commit-date: 2023-05-09
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Error output

<output>
Backtrace

warning: the feature `inherent_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> treereduce.out:1:12
  |
1 | #![feature(inherent_associated_types, generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> treereduce.out:1:39
  |
1 | #![feature(inherent_associated_types, generic_const_exprs)]
  |                                       ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:920:9: expected const for `O/#0` (Const { ty: usize, kind: Param(O/#0) }/0) but found Type(Parent<1>) when substituting substs=[Parent<1>]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/compiler/rustc_errors/src/lib.rs:1650:9
stack backtrace:
   0:     0x7f4ad6b694d1 - std::backtrace_rs::backtrace::libunwind::trace::hf22881449f4c68af
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f4ad6b694d1 - std::backtrace_rs::backtrace::trace_unsynchronized::h417481a63a93417b
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f4ad6b694d1 - std::sys_common::backtrace::_print_fmt::h5cc94e0371544b1c
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f4ad6b694d1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6d4cf29c389416a4
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f4ad6bc987f - core::fmt::rt::Argument::fmt::h88c7f669523ab3d4
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/rt.rs:138:9
   5:     0x7f4ad6bc987f - core::fmt::write::hba6d4469c94dff09
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f4ad6b5c731 - std::io::Write::write_fmt::h03fb3302511e0a07
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/io/mod.rs:1712:15
   7:     0x7f4ad6b692e5 - std::sys_common::backtrace::_print::h2774acb74125ebca
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f4ad6b692e5 - std::sys_common::backtrace::print::h24788cefb69f6c5e
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f4ad6b6bf77 - std::panicking::default_hook::{{closure}}::h83831eb75dbc7abb
  10:     0x7f4ad6b6bd64 - std::panicking::default_hook::haabe5769614bc6ad
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/panicking.rs:288:9
  11:     0x7f4ad9de6e9b - rustc_driver_impl[c6ed467a5333ba7a]::install_ice_hook::{closure#0}
  12:     0x7f4ad6b6c697 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hf6cbf19e675e5bec
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/alloc/src/boxed.rs:1999:9
  13:     0x7f4ad6b6c697 - std::panicking::rust_panic_with_hook::he447f218b926b874
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/panicking.rs:695:13
  14:     0x7f4ada2d56f1 - std[67990bb9926e756e]::panicking::begin_panic::<rustc_errors[65753a741d5cdd19]::ExplicitBug>::{closure#0}
  15:     0x7f4ada2d1ea6 - std[67990bb9926e756e]::sys_common::backtrace::__rust_end_short_backtrace::<std[67990bb9926e756e]::panicking::begin_panic<rustc_errors[65753a741d5cdd19]::ExplicitBug>::{closure#0}, !>
  16:     0x7f4ada2d1d96 - std[67990bb9926e756e]::panicking::begin_panic::<rustc_errors[65753a741d5cdd19]::ExplicitBug>
  17:     0x7f4ada2cc924 - <rustc_errors[65753a741d5cdd19]::HandlerInner>::bug::<alloc[7c1d58d8972e9afb]::string::String>
  18:     0x7f4ada2cc436 - <rustc_errors[65753a741d5cdd19]::Handler>::bug::<alloc[7c1d58d8972e9afb]::string::String>
  19:     0x7f4ada35926c - rustc_middle[6e1fd99800ba9ae7]::util::bug::opt_span_bug_fmt::<rustc_span[21b0d36d0183fdef]::span_encoding::Span>::{closure#0}
  20:     0x7f4ada358a3a - rustc_middle[6e1fd99800ba9ae7]::ty::context::tls::with_opt::<rustc_middle[6e1fd99800ba9ae7]::util::bug::opt_span_bug_fmt<rustc_span[21b0d36d0183fdef]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f4ada358a0a - rustc_middle[6e1fd99800ba9ae7]::ty::context::tls::with_context_opt::<rustc_middle[6e1fd99800ba9ae7]::ty::context::tls::with_opt<rustc_middle[6e1fd99800ba9ae7]::util::bug::opt_span_bug_fmt<rustc_span[21b0d36d0183fdef]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f4ad80febfd - rustc_middle[6e1fd99800ba9ae7]::util::bug::bug_fmt
  23:     0x7f4ada2df002 - <rustc_middle[6e1fd99800ba9ae7]::ty::subst::SubstFolder>::const_param_expected
  24:     0x7f4ad7dac35a - <rustc_middle[6e1fd99800ba9ae7]::ty::subst::GenericArg as rustc_type_ir[6de004e23d25d05]::fold::TypeFoldable<rustc_middle[6e1fd99800ba9ae7]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[6e1fd99800ba9ae7]::ty::subst::SubstFolder>
  25:     0x7f4ad7daa056 - <rustc_middle[6e1fd99800ba9ae7]::ty::Ty as rustc_type_ir[6de004e23d25d05]::fold::TypeSuperFoldable<rustc_middle[6e1fd99800ba9ae7]::ty::context::TyCtxt>>::super_fold_with::<rustc_middle[6e1fd99800ba9ae7]::ty::subst::SubstFolder>
  26:     0x7f4ad801694b - <rustc_middle[6e1fd99800ba9ae7]::ty::print::pretty::FmtPrinter as rustc_middle[6e1fd99800ba9ae7]::ty::print::Printer>::print_def_path
  27:     0x7f4ad80162c6 - <rustc_middle[6e1fd99800ba9ae7]::ty::print::pretty::FmtPrinter as rustc_middle[6e1fd99800ba9ae7]::ty::print::Printer>::print_def_path
  28:     0x7f4ad801646c - <rustc_middle[6e1fd99800ba9ae7]::ty::print::pretty::FmtPrinter as rustc_middle[6e1fd99800ba9ae7]::ty::print::Printer>::print_def_path
  29:     0x7f4ad8013a2b - <rustc_middle[6e1fd99800ba9ae7]::ty::print::pretty::FmtPrinter as rustc_middle[6e1fd99800ba9ae7]::ty::print::pretty::PrettyPrinter>::pretty_print_type
  30:     0x7f4ad801302c - <rustc_middle[6e1fd99800ba9ae7]::ty::Ty as core[58897794ec39d39e]::fmt::Display>::fmt
  31:     0x7f4ada378fa8 - <rustc_middle[6e1fd99800ba9ae7]::ty::Ty as core[58897794ec39d39e]::fmt::Debug>::fmt
  32:     0x7f4ad6bc64f9 - core::fmt::builders::DebugStruct::field::{{closure}}::h1b5711af9127a301
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:141:17
  33:     0x7f4ad6bc64f9 - core::result::Result<T,E>::and_then::hf6cb78cbc9b86fd8
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/result.rs:1319:22
  34:     0x7f4ad6bc64f9 - core::fmt::builders::DebugStruct::field::h6d1f5b7ebb59c1db
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:124:35
  35:     0x7f4ad6bca75f - core::fmt::Formatter::debug_struct_field2_finish::h5a977166d5337886
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:1892:9
  36:     0x7f4ada2d90e8 - <&rustc_middle[6e1fd99800ba9ae7]::ty::subst::UserSelfTy as core[58897794ec39d39e]::fmt::Debug>::fmt
  37:     0x7f4ad6bc678c - core::fmt::builders::DebugTuple::field::{{closure}}::hd9f6bf7ecf71f62e
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:322:17
  38:     0x7f4ad6bc678c - core::result::Result<T,E>::and_then::hb7129ea632b5a35e
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/result.rs:1319:22
  39:     0x7f4ad6bc678c - core::fmt::builders::DebugTuple::field::he2df6437bada7158
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:309:35
  40:     0x7f4ad6bcac9b - core::fmt::Formatter::debug_tuple_field1_finish::h002916c2201e1156
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:2023:9
  41:     0x7f4ada342b57 - <&core[58897794ec39d39e]::option::Option<rustc_middle[6e1fd99800ba9ae7]::ty::subst::UserSelfTy> as core[58897794ec39d39e]::fmt::Debug>::fmt
  42:     0x7f4ad6bc64f9 - core::fmt::builders::DebugStruct::field::{{closure}}::h1b5711af9127a301
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:141:17
  43:     0x7f4ad6bc64f9 - core::result::Result<T,E>::and_then::hf6cb78cbc9b86fd8
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/result.rs:1319:22
  44:     0x7f4ad6bc64f9 - core::fmt::builders::DebugStruct::field::h6d1f5b7ebb59c1db
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:124:35
  45:     0x7f4ad6bca75f - core::fmt::Formatter::debug_struct_field2_finish::h5a977166d5337886
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:1892:9
  46:     0x7f4ada2d9148 - <&rustc_middle[6e1fd99800ba9ae7]::ty::subst::UserSubsts as core[58897794ec39d39e]::fmt::Debug>::fmt
  47:     0x7f4ad6bc678c - core::fmt::builders::DebugTuple::field::{{closure}}::hd9f6bf7ecf71f62e
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:322:17
  48:     0x7f4ad6bc678c - core::result::Result<T,E>::and_then::hb7129ea632b5a35e
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/result.rs:1319:22
  49:     0x7f4ad6bc678c - core::fmt::builders::DebugTuple::field::he2df6437bada7158
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:309:35
  50:     0x7f4ad6bcad78 - core::fmt::Formatter::debug_tuple_field2_finish::h3b28de4e053bb763
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:2039:9
  51:     0x7f4ada28c3e2 - <rustc_middle[6e1fd99800ba9ae7]::ty::typeck_results::UserType as core[58897794ec39d39e]::fmt::Debug>::fmt
  52:     0x7f4ad6bc64f9 - core::fmt::builders::DebugStruct::field::{{closure}}::h1b5711af9127a301
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:141:17
  53:     0x7f4ad6bc64f9 - core::result::Result<T,E>::and_then::hf6cb78cbc9b86fd8
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/result.rs:1319:22
  54:     0x7f4ad6bc64f9 - core::fmt::builders::DebugStruct::field::h6d1f5b7ebb59c1db
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/builders.rs:124:35
  55:     0x7f4ad6bca816 - core::fmt::Formatter::debug_struct_field3_finish::h6e1213564da9e75a
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:1911:9
  56:     0x7f4ada31f8ad - <rustc_middle[6e1fd99800ba9ae7]::infer::canonical::Canonical<rustc_middle[6e1fd99800ba9ae7]::ty::typeck_results::UserType> as core[58897794ec39d39e]::fmt::Debug>::fmt
  57:     0x7f4ad6bc987f - core::fmt::rt::Argument::fmt::h88c7f669523ab3d4
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/rt.rs:138:9
  58:     0x7f4ad6bc987f - core::fmt::write::hba6d4469c94dff09
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/core/src/fmt/mod.rs:1094:21
  59:     0x7f4ada4a06b0 - <std[67990bb9926e756e]::io::buffered::bufwriter::BufWriter<std[67990bb9926e756e]::fs::File> as std[67990bb9926e756e]::io::Write>::write_fmt
  60:     0x7f4ada2b740b - rustc_middle[6e1fd99800ba9ae7]::mir::pretty::write_user_type_annotations
  61:     0x7f4ada47ff1e - rustc_middle[6e1fd99800ba9ae7]::mir::pretty::dump_matched_mir_node::<rustc_mir_transform[31de03d9ff6cd65]::pass_manager::dump_mir_for_phase_change::{closure#0}>
  62:     0x7f4ad8e60b26 - rustc_mir_transform[31de03d9ff6cd65]::mir_const
  63:     0x7f4ad8e5e3b3 - rustc_query_system[d6abf6a541e94d]::query::plumbing::try_execute_query::<rustc_query_impl[9e8d88dd882a1237]::queries::mir_const, rustc_query_impl[9e8d88dd882a1237]::plumbing::QueryCtxt>
  64:     0x7f4ad8e5e055 - rustc_query_impl[9e8d88dd882a1237]::get_query::mir_const
  65:     0x7f4ad8c75a71 - rustc_mir_transform[31de03d9ff6cd65]::mir_promoted
  66:     0x7f4ad87bfdfa - rustc_query_system[d6abf6a541e94d]::query::plumbing::try_execute_query::<rustc_query_impl[9e8d88dd882a1237]::queries::mir_promoted, rustc_query_impl[9e8d88dd882a1237]::plumbing::QueryCtxt>
  67:     0x7f4ad87bf16c - rustc_borrowck[a0259e2eb90fe2e2]::mir_borrowck
  68:     0x7f4ad87bd958 - rustc_query_system[d6abf6a541e94d]::query::plumbing::try_execute_query::<rustc_query_impl[9e8d88dd882a1237]::queries::mir_borrowck, rustc_query_impl[9e8d88dd882a1237]::plumbing::QueryCtxt>
  69:     0x7f4ad9211946 - rustc_data_structures[e1401ea5d1349582]::sync::par_for_each_in::<&[rustc_span[21b0d36d0183fdef]::def_id::LocalDefId], <rustc_middle[6e1fd99800ba9ae7]::hir::map::Map>::par_body_owners<rustc_interface[aaea7ef87a85e665]::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  70:     0x7f4ad920c540 - rustc_interface[aaea7ef87a85e665]::passes::analysis
  71:     0x7f4ad9555727 - rustc_query_system[d6abf6a541e94d]::query::plumbing::try_execute_query::<rustc_query_impl[9e8d88dd882a1237]::queries::analysis, rustc_query_impl[9e8d88dd882a1237]::plumbing::QueryCtxt>
  72:     0x7f4ad9555443 - rustc_query_impl[9e8d88dd882a1237]::get_query::analysis
  73:     0x7f4ad8fd4aaf - <rustc_middle[6e1fd99800ba9ae7]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[c6ed467a5333ba7a]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>>
  74:     0x7f4ad8fd3b8f - <rustc_interface[aaea7ef87a85e665]::interface::Compiler>::enter::<rustc_driver_impl[c6ed467a5333ba7a]::run_compiler::{closure#1}::{closure#2}, core[58897794ec39d39e]::result::Result<core[58897794ec39d39e]::option::Option<rustc_interface[aaea7ef87a85e665]::queries::Linker>, rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>>
  75:     0x7f4ad8fd122b - std[67990bb9926e756e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[aaea7ef87a85e665]::util::run_in_thread_pool_with_globals<rustc_interface[aaea7ef87a85e665]::interface::run_compiler<core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>, rustc_driver_impl[c6ed467a5333ba7a]::run_compiler::{closure#1}>::{closure#0}, core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>>
  76:     0x7f4ad96bbf95 - <<std[67990bb9926e756e]::thread::Builder>::spawn_unchecked_<rustc_interface[aaea7ef87a85e665]::util::run_in_thread_pool_with_globals<rustc_interface[aaea7ef87a85e665]::interface::run_compiler<core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>, rustc_driver_impl[c6ed467a5333ba7a]::run_compiler::{closure#1}>::{closure#0}, core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[58897794ec39d39e]::result::Result<(), rustc_span[21b0d36d0183fdef]::ErrorGuaranteed>>::{closure#1} as core[58897794ec39d39e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  77:     0x7f4ad6b76b45 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h75a0f7a2d96fc847
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/alloc/src/boxed.rs:1985:9
  78:     0x7f4ad6b76b45 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4f2621012beea0ce
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/alloc/src/boxed.rs:1985:9
  79:     0x7f4ad6b76b45 - std::sys::unix::thread::Thread::new::thread_start::h2acc7d12a3234e8d
                               at /rustc/f7b831ac8a897273f78b9f47165cf8e54066ce4b/library/std/src/sys/unix/thread.rs:108:17
  80:     0x7f4ad6913bb5 - <unknown>
  81:     0x7f4ad6995d90 - <unknown>
  82:                0x0 - <unknown>

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.71.0-nightly (f7b831ac8 2023-05-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir=all

query stack during panic:
#0 [mir_const] preparing `main` for borrow checking
#1 [mir_promoted] promoting constants in MIR for `main`
#2 [mir_borrowck] borrow-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 2 warnings emitted

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`F-inherent_associated_types`#![feature(inherent_associated_types)]`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.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions