Skip to content

ICE: assertion failed: key.param_env.is_const()' -Zmir-opt-level=3 #102124

Closed
@matthiaskrgr

Description

@matthiaskrgr

Code

// run-pass

const L: usize = 4;

pub trait Print<const N: usize> {
    fn print(&self) -> usize {
        N
    }
}

pub struct Printer;
impl Print<L> for Printer {}

fn main() {
    let p = Printer;
    assert_eq!(p.print(), 4);
}

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (cd8cc9104 2022-09-20)
binary: rustc
commit-hash: cd8cc91045281f7f1924ecc101f2c6002f6a1eee
commit-date: 2022-09-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0

Error output

rustc 0027cd46a519f921742e5a1a61aaa3d6b40784e3.rs -Zmir-opt-level=3

<output>
Backtrace

thread 'rustc' panicked at 'assertion failed: key.param_env.is_const()', compiler/rustc_const_eval/src/const_eval/eval_queries.rs:270:5
stack backtrace:
   0:     0x7f1281289d50 - std::backtrace_rs::backtrace::libunwind::trace::hb57001d1608b3744
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f1281289d50 - std::backtrace_rs::backtrace::trace_unsynchronized::h2721dca23531e866
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1281289d50 - std::sys_common::backtrace::_print_fmt::h6fe93401ab116dbb
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f1281289d50 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd384424304aeacd4
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f12812e4aae - core::fmt::write::hac21243a5944c5fa
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f128127a965 - std::io::Write::write_fmt::h5d81e47baafcbfe9
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/io/mod.rs:1679:15
   6:     0x7f128128ca03 - std::sys_common::backtrace::_print::h0d5495cb869245ae
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f128128ca03 - std::sys_common::backtrace::print::hdb234f41dcbdb5fa
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f128128ca03 - std::panicking::default_hook::{{closure}}::haf708b9ccfcadcbf
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/panicking.rs:295:22
   9:     0x7f128128c6ef - std::panicking::default_hook::h3ee124fa566d13a8
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/panicking.rs:314:9
  10:     0x7f1283a9aca1 - rustc_driver[a090673f82e083ee]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f128128d23d - std::panicking::rust_panic_with_hook::h23bc5763c4849995
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/panicking.rs:702:17
  12:     0x7f128128d051 - std::panicking::begin_panic_handler::{{closure}}::h1a1dd60e8f8800be
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/panicking.rs:586:13
  13:     0x7f128128a1fc - std::sys_common::backtrace::__rust_end_short_backtrace::hcd4996d4e038378e
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7f128128cdb2 - rust_begin_unwind
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/panicking.rs:584:5
  15:     0x7f12812e1683 - core::panicking::panic_fmt::h8c54af9db1268da2
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/core/src/panicking.rs:142:14
  16:     0x7f12812e14cd - core::panicking::panic::h7667474f2b12d914
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/core/src/panicking.rs:48:5
  17:     0x7f1282b8698c - rustc_const_eval[5fcfc11a8ec3c326]::const_eval::eval_queries::eval_to_allocation_raw_provider
  18:     0x7f12833f24a9 - rustc_query_system[805b36373ad9fc78]::query::plumbing::try_execute_query::<rustc_query_impl[b2bb6402dd535588]::plumbing::QueryCtxt, rustc_query_system[805b36373ad9fc78]::query::caches::DefaultCache<rustc_middle[859647a78c131592]::ty::ParamEnvAnd<rustc_middle[859647a78c131592]::mir::interpret::GlobalId>, core[9f866f05454cf730]::result::Result<rustc_middle[859647a78c131592]::mir::interpret::value::ConstAlloc, rustc_middle[859647a78c131592]::mir::interpret::error::ErrorHandled>>>
  19:     0x7f12839dfaf6 - <rustc_query_impl[b2bb6402dd535588]::Queries as rustc_middle[859647a78c131592]::ty::query::QueryEngine>::eval_to_allocation_raw
  20:     0x7f128375083f - rustc_const_eval[5fcfc11a8ec3c326]::const_eval::eval_to_valtree
  21:     0x7f1283750710 - <rustc_const_eval[5fcfc11a8ec3c326]::provide::{closure#0} as core[9f866f05454cf730]::ops::function::FnOnce<(rustc_middle[859647a78c131592]::ty::context::TyCtxt, rustc_middle[859647a78c131592]::ty::ParamEnvAnd<rustc_middle[859647a78c131592]::mir::interpret::GlobalId>)>>::call_once
  22:     0x7f12836fdffa - rustc_query_system[805b36373ad9fc78]::query::plumbing::try_execute_query::<rustc_query_impl[b2bb6402dd535588]::plumbing::QueryCtxt, rustc_query_system[805b36373ad9fc78]::query::caches::DefaultCache<rustc_middle[859647a78c131592]::ty::ParamEnvAnd<rustc_middle[859647a78c131592]::mir::interpret::GlobalId>, core[9f866f05454cf730]::result::Result<core[9f866f05454cf730]::option::Option<rustc_middle[859647a78c131592]::ty::consts::valtree::ValTree>, rustc_middle[859647a78c131592]::mir::interpret::error::ErrorHandled>>>
  23:     0x7f12836fdba1 - rustc_query_system[805b36373ad9fc78]::query::plumbing::get_query::<rustc_query_impl[b2bb6402dd535588]::queries::eval_to_valtree, rustc_query_impl[b2bb6402dd535588]::plumbing::QueryCtxt>
  24:     0x7f12836fdac1 - <rustc_query_impl[b2bb6402dd535588]::Queries as rustc_middle[859647a78c131592]::ty::query::QueryEngine>::eval_to_valtree
  25:     0x7f12830f7ead - <rustc_const_eval[5fcfc11a8ec3c326]::interpret::eval_context::InterpCx<rustc_mir_transform[b59ddbd07b3aad]::const_prop::ConstPropMachine>>::eval_rvalue_into_place
  26:     0x7f12830e5b1d - <rustc_mir_transform[b59ddbd07b3aad]::const_prop::ConstPropagator as rustc_middle[859647a78c131592]::mir::visit::MutVisitor>::visit_body
  27:     0x7f12830e449f - <rustc_mir_transform[b59ddbd07b3aad]::const_prop::ConstProp as rustc_middle[859647a78c131592]::mir::MirPass>::run_pass
  28:     0x7f1282633505 - rustc_mir_transform[b59ddbd07b3aad]::pass_manager::run_passes
  29:     0x7f128267b3e5 - rustc_mir_transform[b59ddbd07b3aad]::optimized_mir
  30:     0x7f1282e9923b - rustc_query_system[805b36373ad9fc78]::query::plumbing::try_execute_query::<rustc_query_impl[b2bb6402dd535588]::plumbing::QueryCtxt, rustc_query_system[805b36373ad9fc78]::query::caches::DefaultCache<rustc_span[2a62a1a4bd62443]::def_id::DefId, &rustc_middle[859647a78c131592]::mir::Body>>
  31:     0x7f12839de1cf - <rustc_query_impl[b2bb6402dd535588]::Queries as rustc_middle[859647a78c131592]::ty::query::QueryEngine>::optimized_mir
  32:     0x7f12826cab45 - <rustc_middle[859647a78c131592]::ty::context::TyCtxt>::instance_mir
  33:     0x7f12826bfedc - rustc_monomorphize[1117666a277ffcd5]::collector::collect_neighbours
  34:     0x7f12826bda72 - rustc_monomorphize[1117666a277ffcd5]::collector::collect_items_rec
  35:     0x7f128325c710 - <rustc_session[680b9b11862337c1]::session::Session>::time::<(), rustc_monomorphize[1117666a277ffcd5]::collector::collect_crate_mono_items::{closure#1}>
  36:     0x7f128325c2a9 - rustc_monomorphize[1117666a277ffcd5]::collector::collect_crate_mono_items
  37:     0x7f128325b1a6 - rustc_monomorphize[1117666a277ffcd5]::partitioning::collect_and_partition_mono_items
  38:     0x7f128384f0d9 - rustc_query_system[805b36373ad9fc78]::query::plumbing::try_execute_query::<rustc_query_impl[b2bb6402dd535588]::plumbing::QueryCtxt, rustc_query_system[805b36373ad9fc78]::query::caches::DefaultCache<(), (&std[cf6421f2bc0d2537]::collections::hash::set::HashSet<rustc_span[2a62a1a4bd62443]::def_id::DefId, core[9f866f05454cf730]::hash::BuildHasherDefault<rustc_hash[73508f04cfa2c000]::FxHasher>>, &[rustc_middle[859647a78c131592]::mir::mono::CodegenUnit])>>
  39:     0x7f128384edcb - rustc_query_system[805b36373ad9fc78]::query::plumbing::get_query::<rustc_query_impl[b2bb6402dd535588]::queries::collect_and_partition_mono_items, rustc_query_impl[b2bb6402dd535588]::plumbing::QueryCtxt>
  40:     0x7f128384ed0e - <rustc_query_impl[b2bb6402dd535588]::Queries as rustc_middle[859647a78c131592]::ty::query::QueryEngine>::collect_and_partition_mono_items
  41:     0x7f128359aa52 - rustc_codegen_ssa[186f3e6e445c3d13]::base::codegen_crate::<rustc_codegen_llvm[9ddb4f3cd4c5fe97]::LlvmCodegenBackend>
  42:     0x7f128359a822 - <rustc_codegen_llvm[9ddb4f3cd4c5fe97]::LlvmCodegenBackend as rustc_codegen_ssa[186f3e6e445c3d13]::traits::backend::CodegenBackend>::codegen_crate
  43:     0x7f1282862c1c - <rustc_session[680b9b11862337c1]::session::Session>::time::<alloc[ba5258d936a56716]::boxed::Box<dyn core[9f866f05454cf730]::any::Any>, rustc_interface[479f73b3aaea2fc6]::passes::start_codegen::{closure#0}>
  44:     0x7f12828625ee - <rustc_interface[479f73b3aaea2fc6]::passes::QueryContext>::enter::<<rustc_interface[479f73b3aaea2fc6]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[9f866f05454cf730]::result::Result<alloc[ba5258d936a56716]::boxed::Box<dyn core[9f866f05454cf730]::any::Any>, rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>>
  45:     0x7f12828221c3 - <rustc_interface[479f73b3aaea2fc6]::queries::Queries>::ongoing_codegen
  46:     0x7f128282062a - rustc_interface[479f73b3aaea2fc6]::interface::create_compiler_and_run::<core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>, rustc_driver[a090673f82e083ee]::run_compiler::{closure#1}>
  47:     0x7f128281ef22 - <scoped_tls[a920566c4771e8d1]::ScopedKey<rustc_span[2a62a1a4bd62443]::SessionGlobals>>::set::<rustc_interface[479f73b3aaea2fc6]::interface::run_compiler<core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>, rustc_driver[a090673f82e083ee]::run_compiler::{closure#1}>::{closure#0}, core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>>
  48:     0x7f128281ec0f - std[cf6421f2bc0d2537]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[479f73b3aaea2fc6]::util::run_in_thread_pool_with_globals<rustc_interface[479f73b3aaea2fc6]::interface::run_compiler<core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>, rustc_driver[a090673f82e083ee]::run_compiler::{closure#1}>::{closure#0}, core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>>::{closure#0}, core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>>
  49:     0x7f1283902520 - <<std[cf6421f2bc0d2537]::thread::Builder>::spawn_unchecked_<rustc_interface[479f73b3aaea2fc6]::util::run_in_thread_pool_with_globals<rustc_interface[479f73b3aaea2fc6]::interface::run_compiler<core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>, rustc_driver[a090673f82e083ee]::run_compiler::{closure#1}>::{closure#0}, core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>>::{closure#0}, core[9f866f05454cf730]::result::Result<(), rustc_errors[c1b3d0cec79490cb]::ErrorGuaranteed>>::{closure#1} as core[9f866f05454cf730]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7f1281297013 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5705618028306d08
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/alloc/src/boxed.rs:1940:9
  51:     0x7f1281297013 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4f35798672ba59b7
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/alloc/src/boxed.rs:1940:9
  52:     0x7f1281297013 - std::sys::unix::thread::Thread::new::thread_start::hd53ffe926e75eb0c
                               at /rustc/cd8cc91045281f7f1924ecc101f2c6002f6a1eee/library/std/src/sys/unix/thread.rs:108:17
  53:     0x7f1280fef78d - <unknown>
  54:     0x7f12810708e4 - clone
  55:                0x0 - <unknown>

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.66.0-nightly (cd8cc9104 2022-09-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `<impl at 0027cd46a519f921742e5a1a61aaa3d6b40784e3.rs:12:1: 12:26>::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
#2 [optimized_mir] optimizing MIR for `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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.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