Skip to content
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

ICE: None in compiler/rustc_middle/src/ty/sty.rs #129145

Closed
matthiaskrgr opened this issue Aug 16, 2024 · 2 comments · Fixed by #129168
Closed

ICE: None in compiler/rustc_middle/src/ty/sty.rs #129145

matthiaskrgr opened this issue Aug 16, 2024 · 2 comments · Fixed by #129168
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

trait Collate<const MASK: u32> {
    type Pass;
    type Fail;
}

impl<H, T, const MASK: u32> Collate<MASK> for (H, T) {
    fn collate(self) -> (Self::Pass, Self::Fail) {
        <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
    }
}
original code

original:

#![feature(const_generics, const_evaluatable_checked)]

struct True;
struct False;

trait ConstBool {
    type Val;
}
struct TypeBool<const X: bool>;

impl ConstBool for TypeBool<true> {
    type Val = True;
}

impl ConstBool for TypeBool<false> {
    type Val = False;
}

trait Collate<const MASK: u32> {
    type Pass;
    type Fail;

    fn collate(self) -> (Self::Pass, Self::Fail);
}

impl<const MASK: u32> Collate<MASK> for () {
    type Pass = ();
    type Fail = ();

    fn collate(self) -> ((), ()) {
        ((), ())
    }
}

trait CollateStep<X, Prev> {
    3
    type Fail;
    fn collate_step(x: X, prev: Prev) -> (Self::Pass, Self::Fail);
}

impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<true> {
    type Pass = (X, P);
    type Fail = F;

    fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) {
        ((x, p), f)
    }
}

impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<false> {
    type Pass = P;
    type Fail = (X, F);

    fn collate_step(x: X, (p, f): (P, F)) -> (P, (X, F)) {
        (p, (x, f))
    }
}

impl<H, T: Collate<{ MASK >> 1 }>, const MASK: u32> Collate<MASK> for (H, T)
where
    TypeBool<{ 1 == MASK & 1 }>: CollateStep<H, (T::Pass, T::Fail)>,
{
    type Pass =
        <TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Pass;
    type Fail =
        <TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Fail;

    fn collate(self) -> (Self::Pass, Self::Fail) {
        <Collate<{ 1 == MASK & 1 }>
         as CollateStep<H, (T::Pass, T::Fail)>>
         ::collate_step(self.0, self.1.collate())
    }
}

fn collate<X,const MASK:u32>(x:X)->(X::Pass, X::Fail)
where X:Collate<MASK> {
    self.1()
}

fn main() {
    dbg!(collate::<_,3>((4, ('!',()))));
}

Version information

rustc 1.82.0-nightly (4b7d074d7 2024-08-15)
binary: rustc
commit-hash: 4b7d074d766d00a32fa8b2e4fa3813dd7d4d64e6
commit-date: 2024-08-15
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0407]: method `collate` is not a member of trait `Collate`
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:7:5
  |
7 | /     fn collate(self) -> (Self::Pass, Self::Fail) {
8 | |         <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
9 | |     }
  | |_____^ not a member of trait `Collate`

error: generic parameters may not be used in const operations
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:8:25
  |
8 |         <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
  |                         ^^^^ cannot perform const operation using `MASK`
  |
  = help: const parameters may only be used as standalone arguments, i.e. `MASK`
  = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions

error[E0405]: cannot find trait `CollateStep` in this scope
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:8:40
  |
8 |         <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
  |                                        ^^^^^^^^^^^ not found in this scope

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs`

error[E0046]: not all trait items implemented, missing: `Pass`, `Fail`
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:6:1
  |
2 |     type Pass;
  |     --------- `Pass` from trait
3 |     type Fail;
  |     --------- `Fail` from trait
...
6 | impl<H, T, const MASK: u32> Collate<MASK> for (H, T) {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pass`, `Fail` in implementation

warning: trait objects without an explicit `dyn` are deprecated
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:8:10
  |
8 |         <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
  |
8 |         <dyn Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
  |          +++

error[E0191]: the value of the associated types `Pass` and `Fail` in `Collate` must be specified
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:8:10
  |
2 |     type Pass;
  |     --------- `Pass` defined here
3 |     type Fail;
  |     --------- `Fail` defined here
...
8 |         <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: specify the associated types: `Collate<{ 1 == MASK & 1 }, Pass = Type, Fail = Type>`

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:8:20
  |
8 |         <Collate<{ 1 == MASK & 1 }> as CollateStep<H>>::collate_step(self.0)
  |                    ^^^^^^^^^^^^^ expected `u32`, found `bool`

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:362:36:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x756daf5b8efd - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h9dbfa5a13334a048
   1:     0x756dafe05297 - core::fmt::write::hcbbcd98e2555f5d0
   2:     0x756db0dbef11 - std::io::Write::write_fmt::hbce2407a9809228c
   3:     0x756daf5bb5db - std::panicking::default_hook::{{closure}}::h5281c3800a5e87cc
   4:     0x756daf5bb24e - std::panicking::default_hook::hc6eb547e64d62a2d
   5:     0x756dae74ef59 - std[3d2b83dd2aabb1df]::panicking::update_hook::<alloc[2925aedc1a634bb5]::boxed::Box<rustc_driver_impl[df17b2027db720ee]::install_ice_hook::{closure#0}>>::{closure#0}
   6:     0x756daf5bbef7 - std::panicking::rust_panic_with_hook::h88497b8939cfe9de
   7:     0x756daf5bbb83 - std::panicking::begin_panic_handler::{{closure}}::hca70fb01649d46e8
   8:     0x756daf5b93b9 - std::sys::backtrace::__rust_end_short_backtrace::h6a031b654d0ad1a2
   9:     0x756daf5bb884 - rust_begin_unwind
  10:     0x756dac7a1f93 - core::panicking::panic_fmt::h818a0d1eb005cfb3
  11:     0x756dac663a7c - core::panicking::panic::h1e56b544c77c5180
  12:     0x756dac7b3019 - core::option::unwrap_failed::habc9b524efb569a1
  13:     0x756db188d87c - <rustc_middle[b1a78737217f88d2]::ty::sty::ParamConst>::find_ty_from_env.cold
  14:     0x756dac466fa7 - <rustc_trait_selection[e1be1b7552eed254]::traits::fulfill::FulfillProcessor as rustc_data_structures[95451bf12efeed46]::obligation_forest::ObligationProcessor>::process_obligation
  15:     0x756dafe08777 - <rustc_data_structures[95451bf12efeed46]::obligation_forest::ObligationForest<rustc_trait_selection[e1be1b7552eed254]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[e1be1b7552eed254]::traits::fulfill::FulfillProcessor>
  16:     0x756db016f5ed - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::type_inference_fallback
  17:     0x756db0167aac - rustc_hir_typeck[c3f01b2c610829a2]::typeck
  18:     0x756db01674f3 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>
  19:     0x756db00c7179 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  20:     0x756db00c6395 - rustc_query_impl[9ef7872d5217e630]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  21:     0x756db061b4db - rustc_mir_build[8030a5d9df7a35f7]::thir::pattern::check_match::check_match
  22:     0x756db061ac1b - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 1usize]>>
  23:     0x756db061a291 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  24:     0x756db0619fdd - rustc_query_impl[9ef7872d5217e630]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  25:     0x756db0631192 - rustc_mir_build[8030a5d9df7a35f7]::build::mir_build
  26:     0x756db063084e - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>
  27:     0x756db00c7179 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  28:     0x756db00c6c8d - rustc_query_impl[9ef7872d5217e630]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  29:     0x756db06ceced - rustc_mir_transform[1c9d8798cf57df7a]::mir_const_qualif
  30:     0x756db06cebf7 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::mir_const_qualif::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 4usize]>>
  31:     0x756db06ce00e - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::DefIdCache<rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  32:     0x756db06cdda3 - rustc_query_impl[9ef7872d5217e630]::query_impl::mir_const_qualif::get_query_non_incr::__rust_end_short_backtrace
  33:     0x756db06173da - rustc_mir_transform[1c9d8798cf57df7a]::mir_promoted
  34:     0x756db0616d52 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 16usize]>>
  35:     0x756db024c810 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  36:     0x756db0f1ca10 - rustc_query_impl[9ef7872d5217e630]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  37:     0x756db0f1cb03 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>
  38:     0x756db00c7179 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  39:     0x756db00c6bcd - rustc_query_impl[9ef7872d5217e630]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  40:     0x756db00be34f - rustc_mir_transform[1c9d8798cf57df7a]::mir_drops_elaborated_and_const_checked
  41:     0x756db00bd83d - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>
  42:     0x756db00c7179 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  43:     0x756db00c6b0d - rustc_query_impl[9ef7872d5217e630]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  44:     0x756db06d5e75 - rustc_mir_transform[1c9d8798cf57df7a]::mir_for_ctfe
  45:     0x756db06d5d27 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::mir_for_ctfe::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>
  46:     0x756dafe99fa7 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::DefIdCache<rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  47:     0x756db0a1635f - rustc_query_impl[9ef7872d5217e630]::query_impl::mir_for_ctfe::get_query_non_incr::__rust_end_short_backtrace
  48:     0x756db0a164a0 - <rustc_const_eval[8d29268bebe65f61]::interpret::eval_context::InterpCx<rustc_const_eval[8d29268bebe65f61]::const_eval::machine::CompileTimeMachine>>::load_mir
  49:     0x756db0a17712 - rustc_const_eval[8d29268bebe65f61]::const_eval::eval_queries::eval_to_allocation_raw_provider
  50:     0x756db0a17448 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 24usize]>>
  51:     0x756db0a12012 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::DefaultCache<rustc_middle[b1a78737217f88d2]::ty::ParamEnvAnd<rustc_middle[b1a78737217f88d2]::mir::interpret::GlobalId>, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  52:     0x756db0a11bef - rustc_query_impl[9ef7872d5217e630]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  53:     0x756db09f7cf3 - rustc_const_eval[8d29268bebe65f61]::const_eval::valtrees::eval_to_valtree
  54:     0x756db09f7b03 - <rustc_const_eval[8d29268bebe65f61]::provide::{closure#0} as core[77596ae8a24c31da]::ops::function::FnOnce<(rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt, rustc_middle[b1a78737217f88d2]::ty::ParamEnvAnd<rustc_middle[b1a78737217f88d2]::mir::interpret::GlobalId>)>>::call_once
  55:     0x756db09f7aba - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::eval_to_valtree::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 24usize]>>
  56:     0x756db09f7a7b - <rustc_query_impl[9ef7872d5217e630]::query_impl::eval_to_valtree::dynamic_query::{closure#2} as core[77596ae8a24c31da]::ops::function::FnOnce<(rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt, rustc_middle[b1a78737217f88d2]::ty::ParamEnvAnd<rustc_middle[b1a78737217f88d2]::mir::interpret::GlobalId>)>>::call_once
  57:     0x756db0a120ed - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::DefaultCache<rustc_middle[b1a78737217f88d2]::ty::ParamEnvAnd<rustc_middle[b1a78737217f88d2]::mir::interpret::GlobalId>, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  58:     0x756db08aba48 - rustc_query_impl[9ef7872d5217e630]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace
  59:     0x756db08aa622 - rustc_middle[b1a78737217f88d2]::query::plumbing::query_get_at::<rustc_query_system[897f24727061e191]::query::caches::DefaultCache<rustc_middle[b1a78737217f88d2]::ty::ParamEnvAnd<rustc_middle[b1a78737217f88d2]::mir::interpret::GlobalId>, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 24usize]>>>
  60:     0x756db08aa05c - <rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  61:     0x756db08a483e - <rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  62:     0x756db08a44ce - <rustc_middle[b1a78737217f88d2]::ty::consts::Const>::eval
  63:     0x756db08a3fd6 - <rustc_trait_selection[e1be1b7552eed254]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[3c2561b8ed23244e]::fold::TypeFolder<rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>>::fold_const
  64:     0x756db0700066 - <&rustc_middle[b1a78737217f88d2]::ty::list::RawList<(), rustc_middle[b1a78737217f88d2]::ty::generic_args::GenericArg> as rustc_type_ir[3c2561b8ed23244e]::fold::TypeFoldable<rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection[e1be1b7552eed254]::traits::normalize::AssocTypeNormalizer>
  65:     0x756daf454aff - <rustc_trait_selection[e1be1b7552eed254]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[3c2561b8ed23244e]::fold::TypeFolder<rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>>::fold_binder::<rustc_type_ir[3c2561b8ed23244e]::predicate::ExistentialPredicate<rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>>
  66:     0x756db0702537 - <rustc_middle[b1a78737217f88d2]::ty::Ty as rustc_type_ir[3c2561b8ed23244e]::fold::TypeSuperFoldable<rustc_middle[b1a78737217f88d2]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_trait_selection[e1be1b7552eed254]::traits::normalize::AssocTypeNormalizer>
  67:     0x756dafed4504 - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::normalize::<rustc_middle[b1a78737217f88d2]::ty::Ty>
  68:     0x756db0694f08 - <dyn rustc_hir_analysis[93a8a2dd976a2b34]::hir_ty_lowering::HirTyLowerer>::lower_ty_common::{closure#0}
  69:     0x756db03d4f29 - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::check_expr_path
  70:     0x756db08d3c18 - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  71:     0x756db08d5351 - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  72:     0x756db08cea16 - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::check_block_with_expected
  73:     0x756db08d5e0b - <rustc_hir_typeck[c3f01b2c610829a2]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  74:     0x756dafec0777 - rustc_hir_typeck[c3f01b2c610829a2]::check::check_fn
  75:     0x756db0167a9f - rustc_hir_typeck[c3f01b2c610829a2]::typeck
  76:     0x756db01674f3 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>
  77:     0x756db00c7179 - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::VecCache<rustc_span[17985c86cfc7b367]::def_id::LocalDefId, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  78:     0x756db00c6395 - rustc_query_impl[9ef7872d5217e630]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  79:     0x756db00c601b - <rustc_middle[b1a78737217f88d2]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[93a8a2dd976a2b34]::check_crate::{closure#4}>::{closure#0}
  80:     0x756db00c3d64 - rustc_hir_analysis[93a8a2dd976a2b34]::check_crate
  81:     0x756db07fdfff - rustc_interface[cd3bffbbdd36a14f]::passes::run_required_analyses
  82:     0x756db092a75e - rustc_interface[cd3bffbbdd36a14f]::passes::analysis
  83:     0x756db092a731 - rustc_query_impl[9ef7872d5217e630]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9ef7872d5217e630]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 1usize]>>
  84:     0x756db0d88b2e - rustc_query_system[897f24727061e191]::query::plumbing::try_execute_query::<rustc_query_impl[9ef7872d5217e630]::DynamicConfig<rustc_query_system[897f24727061e191]::query::caches::SingleCache<rustc_middle[b1a78737217f88d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9ef7872d5217e630]::plumbing::QueryCtxt, false>
  85:     0x756db0d8888f - rustc_query_impl[9ef7872d5217e630]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  86:     0x756db0be69ea - rustc_interface[cd3bffbbdd36a14f]::interface::run_compiler::<core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>, rustc_driver_impl[df17b2027db720ee]::run_compiler::{closure#0}>::{closure#1}
  87:     0x756db0bc5bd0 - std[3d2b83dd2aabb1df]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[cd3bffbbdd36a14f]::util::run_in_thread_with_globals<rustc_interface[cd3bffbbdd36a14f]::util::run_in_thread_pool_with_globals<rustc_interface[cd3bffbbdd36a14f]::interface::run_compiler<core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>, rustc_driver_impl[df17b2027db720ee]::run_compiler::{closure#0}>::{closure#1}, core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>>::{closure#0}, core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>>
  88:     0x756db0bc623a - <<std[3d2b83dd2aabb1df]::thread::Builder>::spawn_unchecked_<rustc_interface[cd3bffbbdd36a14f]::util::run_in_thread_with_globals<rustc_interface[cd3bffbbdd36a14f]::util::run_in_thread_pool_with_globals<rustc_interface[cd3bffbbdd36a14f]::interface::run_compiler<core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>, rustc_driver_impl[df17b2027db720ee]::run_compiler::{closure#0}>::{closure#1}, core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>>::{closure#0}, core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[77596ae8a24c31da]::result::Result<(), rustc_span[17985c86cfc7b367]::ErrorGuaranteed>>::{closure#1} as core[77596ae8a24c31da]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  89:     0x756db0bc65ab - std::sys::pal::unix::thread::Thread::new::thread_start::h360706b1a7e57c20
  90:     0x756db22e139d - <unknown>
  91:     0x756db236649c - <unknown>
  92:                0x0 - <unknown>

error: 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: please make sure that you have updated to the latest nightly

note: rustc 1.82.0-nightly (4b7d074d7 2024-08-15) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:6:1: 6:53>::collate::{constant#0}`
#1 [check_match] match-checking `<impl at /tmp/icemaker_global_tempdir.QNaAT9qATeCf/rustc_testrunner_tmpdir_reporting.yNN1vodqNDs9/mvce.rs:6:1: 6:53>::collate::{constant#0}`
end of query stack
error: aborting due to 7 previous errors; 1 warning emitted

Some errors have detailed explanations: E0046, E0191, E0308, E0405, E0407, E0601.
For more information about an error, try `rustc --explain E0046`.

@rustbot label +F-const_generics +F-const_evaluatable_checked

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Aug 16, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 16, 2024
@theemathas
Copy link
Contributor

Slightly minimized with fewer errors:

fn generic<const N: u32>() {}

trait Collate<const MASK: u32> {
    type Pass;
    fn collate(self) -> Self::Pass;
}

impl<const MASK: u32> Collate<MASK> for i32 {
    type Pass = ();
    fn collate(self) -> Self::Pass {
        generic::<{ true }>()
    }
}

The compiler seems to have trouble figuring out whether the type of generic::<{ true }>() matches the returned type Self::Pass

Program output
   Compiling playground v0.0.1 (/playground)
warning: unnecessary braces around const expression
  --> src/lib.rs:11:19
   |
11 |         generic::<{ true }>()
   |                   ^^    ^^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
   |
11 -         generic::<{ true }>()
11 +         generic::<true>()
   |

error[E0308]: mismatched types
  --> src/lib.rs:11:21
   |
11 |         generic::<{ true }>()
   |                     ^^^^ expected `u32`, found `bool`

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:360:36:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f12de777f05 - std::backtrace_rs::backtrace::libunwind::trace::h23054e327d0d4b55
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f12de777f05 - std::backtrace_rs::backtrace::trace_unsynchronized::h0cc587407d7f7f64
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f12de777f05 - std::sys_common::backtrace::_print_fmt::h4feeb59774730d6b
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f12de777f05 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd736fd5964392270
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f12de7c8c4b - core::fmt::rt::Argument::fmt::h105051d8ea1ade1e
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/rt.rs:165:63
   5:     0x7f12de7c8c4b - core::fmt::write::hc6043626647b98ea
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/mod.rs:1168:21
   6:     0x7f12de76cbdf - std::io::Write::write_fmt::h0d24b3e0473045db
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/io/mod.rs:1835:15
   7:     0x7f12de777cde - std::sys_common::backtrace::_print::h62df6fc36dcebfc8
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f12de777cde - std::sys_common::backtrace::print::h45eb8174d25a1e76
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f12de77a719 - std::panicking::default_hook::{{closure}}::haf3f0170eb4f3b53
  10:     0x7f12de77a4ba - std::panicking::default_hook::hb5d3b27aa9f6dcda
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:298:9
  11:     0x7f12e18020c1 - std[fba9fafec3bdacf8]::panicking::update_hook::<alloc[a325a9cea6fa5e89]::boxed::Box<rustc_driver_impl[ce01f96e2e949677]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f12de77ae4b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2026a29033a1b9f6
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2077:9
  13:     0x7f12de77ae4b - std::panicking::rust_panic_with_hook::h6b49d59f86ee588c
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:799:13
  14:     0x7f12de77ab8b - std::panicking::begin_panic_handler::{{closure}}::hd4c2f7ed79b82b70
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:656:13
  15:     0x7f12de7783c9 - std::sys_common::backtrace::__rust_end_short_backtrace::h2946d6d32d7ea1ad
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f12de77a8f7 - rust_begin_unwind
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:652:5
  17:     0x7f12de7c51e3 - core::panicking::panic_fmt::ha02418e5cd774672
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:72:14
  18:     0x7f12de7c528c - core::panicking::panic::h6c780fb115b2371d
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:146:5
  19:     0x7f12de7c4f29 - core::option::unwrap_failed::hff19eb16beb38f1f
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/option.rs:1985:5
  20:     0x7f12e436fb32 - <rustc_middle[ecc07153edf3c281]::ty::sty::ParamConst>::find_ty_from_env.cold
  21:     0x7f12dfb50504 - <rustc_trait_selection[bf98a35716bfd7e5]::traits::fulfill::FulfillProcessor as rustc_data_structures[25e6784d61918b0d]::obligation_forest::ObligationProcessor>::process_obligation
  22:     0x7f12e2bf3a3d - <rustc_data_structures[25e6784d61918b0d]::obligation_forest::ObligationForest<rustc_trait_selection[bf98a35716bfd7e5]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[bf98a35716bfd7e5]::traits::fulfill::FulfillProcessor>
  23:     0x7f12e355cdae - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::type_inference_fallback
  24:     0x7f12e3562c0a - rustc_hir_typeck[624c394323d1dd51]::typeck
  25:     0x7f12e35618cf - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7f12e2d47aeb - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  27:     0x7f12e2d474e5 - rustc_query_impl[c1633093ec927e0e]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f12e2f64af8 - rustc_mir_build[7b7735d0d37e34f3]::thir::pattern::check_match::check_match
  29:     0x7f12e2f63f23 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 1usize]>>
  30:     0x7f12e2f636a9 - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  31:     0x7f12e2f63381 - rustc_query_impl[c1633093ec927e0e]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f12e2f69cd9 - rustc_mir_build[7b7735d0d37e34f3]::build::mir_build
  33:     0x7f12e2f6938e - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>
  34:     0x7f12e2d47aeb - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  35:     0x7f12e2d47593 - rustc_query_impl[c1633093ec927e0e]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7f12e34c9d4f - rustc_mir_transform[e8632467688ea17a]::mir_const_qualif
  37:     0x7f12e34c9c69 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::mir_const_qualif::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 4usize]>>
  38:     0x7f12e34c955d - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::DefIdCache<rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  39:     0x7f12e34c932d - rustc_query_impl[c1633093ec927e0e]::query_impl::mir_const_qualif::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7f12e069b68f - rustc_mir_transform[e8632467688ea17a]::mir_promoted
  41:     0x7f12e3245122 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 16usize]>>
  42:     0x7f12e324539e - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  43:     0x7f12e3aa0ad0 - rustc_query_impl[c1633093ec927e0e]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7f12e3aa0b9d - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>
  45:     0x7f12e2d47aeb - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  46:     0x7f12e2d4764d - rustc_query_impl[c1633093ec927e0e]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  47:     0x7f12e069fc71 - rustc_mir_transform[e8632467688ea17a]::mir_drops_elaborated_and_const_checked
  48:     0x7f12e2d477f9 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>
  49:     0x7f12e2d47aeb - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  50:     0x7f12e2d4734d - rustc_query_impl[c1633093ec927e0e]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7f12e34cbe9f - rustc_mir_transform[e8632467688ea17a]::mir_for_ctfe
  52:     0x7f12e34cbd9f - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::mir_for_ctfe::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>
  53:     0x7f12e2cc2e3c - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::DefIdCache<rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  54:     0x7f12e2cbf720 - rustc_query_impl[c1633093ec927e0e]::query_impl::mir_for_ctfe::get_query_non_incr::__rust_end_short_backtrace
  55:     0x7f12e2cbf833 - <rustc_const_eval[964325fd78f4b8e1]::interpret::eval_context::InterpCx<rustc_const_eval[964325fd78f4b8e1]::const_eval::machine::CompileTimeInterpreter>>::load_mir
  56:     0x7f12e09cbdaa - rustc_const_eval[964325fd78f4b8e1]::const_eval::eval_queries::eval_to_allocation_raw_provider
  57:     0x7f12e32da0c2 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 24usize]>>
  58:     0x7f12e32d9de6 - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::DefaultCache<rustc_middle[ecc07153edf3c281]::ty::ParamEnvAnd<rustc_middle[ecc07153edf3c281]::mir::interpret::GlobalId>, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  59:     0x7f12e32d9a36 - rustc_query_impl[c1633093ec927e0e]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  60:     0x7f12e39662b0 - rustc_const_eval[964325fd78f4b8e1]::const_eval::valtrees::eval_to_valtree
  61:     0x7f12e39660ff - <rustc_const_eval[964325fd78f4b8e1]::provide::{closure#0} as core[1a380081440346cb]::ops::function::FnOnce<(rustc_middle[ecc07153edf3c281]::ty::context::TyCtxt, rustc_middle[ecc07153edf3c281]::ty::ParamEnvAnd<rustc_middle[ecc07153edf3c281]::mir::interpret::GlobalId>)>>::call_once
  62:     0x7f12e39660b6 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::eval_to_valtree::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 24usize]>>
  63:     0x7f12e396606f - <rustc_query_impl[c1633093ec927e0e]::query_impl::eval_to_valtree::dynamic_query::{closure#2} as core[1a380081440346cb]::ops::function::FnOnce<(rustc_middle[ecc07153edf3c281]::ty::context::TyCtxt, rustc_middle[ecc07153edf3c281]::ty::ParamEnvAnd<rustc_middle[ecc07153edf3c281]::mir::interpret::GlobalId>)>>::call_once
  64:     0x7f12e32d9ebe - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::DefaultCache<rustc_middle[ecc07153edf3c281]::ty::ParamEnvAnd<rustc_middle[ecc07153edf3c281]::mir::interpret::GlobalId>, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  65:     0x7f12e32d9860 - rustc_query_impl[c1633093ec927e0e]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace
  66:     0x7f12e3377949 - rustc_middle[ecc07153edf3c281]::query::plumbing::query_get_at::<rustc_query_system[b257ee99c2874caa]::query::caches::DefaultCache<rustc_middle[ecc07153edf3c281]::ty::ParamEnvAnd<rustc_middle[ecc07153edf3c281]::mir::interpret::GlobalId>, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 24usize]>>>
  67:     0x7f12e3376319 - <rustc_middle[ecc07153edf3c281]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  68:     0x7f12e33748c3 - <rustc_middle[ecc07153edf3c281]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  69:     0x7f12e3374624 - <rustc_middle[ecc07153edf3c281]::ty::consts::Const>::eval
  70:     0x7f12e33bf4f7 - <rustc_trait_selection[bf98a35716bfd7e5]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[8d868667529acadd]::fold::TypeFolder<rustc_middle[ecc07153edf3c281]::ty::context::TyCtxt>>::fold_const
  71:     0x7f12e33be85f - <&rustc_middle[ecc07153edf3c281]::ty::list::RawList<(), rustc_middle[ecc07153edf3c281]::ty::generic_args::GenericArg> as rustc_type_ir[8d868667529acadd]::fold::TypeFoldable<rustc_middle[ecc07153edf3c281]::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection[bf98a35716bfd7e5]::traits::normalize::AssocTypeNormalizer>
  72:     0x7f12e2f26203 - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::normalize::<&rustc_middle[ecc07153edf3c281]::ty::list::RawList<(), rustc_middle[ecc07153edf3c281]::ty::generic_args::GenericArg>>
  73:     0x7f12e2f16874 - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::instantiate_value_path
  74:     0x7f12e2f0ee0e - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::check_expr_path
  75:     0x7f12e37636f6 - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  76:     0x7f12e3764676 - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  77:     0x7f12e375f5fe - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::check_block_with_expected
  78:     0x7f12e3764bad - <rustc_hir_typeck[624c394323d1dd51]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  79:     0x7f12e2f039e7 - rustc_hir_typeck[624c394323d1dd51]::check::check_fn
  80:     0x7f12e3562bfd - rustc_hir_typeck[624c394323d1dd51]::typeck
  81:     0x7f12e35618cf - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>
  82:     0x7f12e2d47aeb - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::VecCache<rustc_span[4d50fd03223eefaa]::def_id::LocalDefId, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  83:     0x7f12e2d474e5 - rustc_query_impl[c1633093ec927e0e]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  84:     0x7f12e35cc677 - rustc_hir_analysis[be96d916f40dad1b]::check_crate
  85:     0x7f12e368062b - rustc_interface[c31201428b712578]::passes::analysis
  86:     0x7f12e3680025 - rustc_query_impl[c1633093ec927e0e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c1633093ec927e0e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 1usize]>>
  87:     0x7f12e3952622 - rustc_query_system[b257ee99c2874caa]::query::plumbing::try_execute_query::<rustc_query_impl[c1633093ec927e0e]::DynamicConfig<rustc_query_system[b257ee99c2874caa]::query::caches::SingleCache<rustc_middle[ecc07153edf3c281]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c1633093ec927e0e]::plumbing::QueryCtxt, false>
  88:     0x7f12e39523cf - rustc_query_impl[c1633093ec927e0e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  89:     0x7f12e37ff24d - rustc_interface[c31201428b712578]::interface::run_compiler::<core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>, rustc_driver_impl[ce01f96e2e949677]::run_compiler::{closure#0}>::{closure#1}
  90:     0x7f12e3934869 - std[fba9fafec3bdacf8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c31201428b712578]::util::run_in_thread_with_globals<rustc_interface[c31201428b712578]::interface::run_compiler<core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>, rustc_driver_impl[ce01f96e2e949677]::run_compiler::{closure#0}>::{closure#1}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>
  91:     0x7f12e393466a - <<std[fba9fafec3bdacf8]::thread::Builder>::spawn_unchecked_<rustc_interface[c31201428b712578]::util::run_in_thread_with_globals<rustc_interface[c31201428b712578]::interface::run_compiler<core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>, rustc_driver_impl[ce01f96e2e949677]::run_compiler::{closure#0}>::{closure#1}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>::{closure#2} as core[1a380081440346cb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  92:     0x7f12de784e3b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdf5fcef8be77a431
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2063:9
  93:     0x7f12de784e3b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8e8c5ceee46ee198
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2063:9
  94:     0x7f12de784e3b - std::sys::pal::unix::thread::Thread::new::thread_start::hb85dbfa54ba503d6
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys/pal/unix/thread.rs:108:17
  95:     0x7f12de692609 - start_thread
  96:     0x7f12de5b5353 - clone
  97:                0x0 - <unknown>

error: 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.80.1 (3f5fd8dd4 2024-08-06) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/lib.rs:8:1: 8:44>::collate::{constant#0}`
#1 [check_match] match-checking `<impl at src/lib.rs:8:1: 8:44>::collate::{constant#0}`
end of query stack
For more information about this error, try `rustc --explain E0308`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib) due to 1 previous error; 1 warning emitted

@matthiaskrgr
Copy link
Member Author

#125958

@BoxyUwU BoxyUwU self-assigned this Aug 16, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 16, 2024
…r=compiler-errors

Return correct HirId when finding body owner in diagnostics

Fixes rust-lang#129145
Fixes rust-lang#128810

r? `@compiler-errors`

```rust
fn generic<const N: u32>() {}

trait Collate<const A: u32> {
    type Pass;
    fn collate(self) -> Self::Pass;
}

impl<const B: u32> Collate<B> for i32 {
    type Pass = ();
    fn collate(self) -> Self::Pass {
        generic::<{ true }>()
        //~^ ERROR: mismatched types
    }
}
```

When type checking the `{ true }` anon const we would error with a type mismatch. This then results in diagnostics code attempting to check whether its due to a type mismatch with the return type. That logic was implemented by walking up the hir until we reached the body owner, except instead of using the `enclosing_body_owner` function it special cased various hir nodes incorrectly resulting in us walking out of the anon const and stopping at `fn collate` instead.

This then resulted in diagnostics logic inside of the anon consts `ParamEnv` attempting to do trait solving involving the `<i32 as Collate<B>>::Pass` type which ICEs because it is in the wrong environment.

I have rewritten this function to just walk up until it hits the `enclosing_body_owner` and made some other changes since I found this pretty hard to read/understand. Hopefully it's easier to understand now, it also makes it more obvious that this is not implemented in a very principled way and is definitely missing cases :)
tgross35 added a commit to tgross35/rust that referenced this issue Aug 17, 2024
…r=compiler-errors

Return correct HirId when finding body owner in diagnostics

Fixes rust-lang#129145
Fixes rust-lang#128810

r? ``@compiler-errors``

```rust
fn generic<const N: u32>() {}

trait Collate<const A: u32> {
    type Pass;
    fn collate(self) -> Self::Pass;
}

impl<const B: u32> Collate<B> for i32 {
    type Pass = ();
    fn collate(self) -> Self::Pass {
        generic::<{ true }>()
        //~^ ERROR: mismatched types
    }
}
```

When type checking the `{ true }` anon const we would error with a type mismatch. This then results in diagnostics code attempting to check whether its due to a type mismatch with the return type. That logic was implemented by walking up the hir until we reached the body owner, except instead of using the `enclosing_body_owner` function it special cased various hir nodes incorrectly resulting in us walking out of the anon const and stopping at `fn collate` instead.

This then resulted in diagnostics logic inside of the anon consts `ParamEnv` attempting to do trait solving involving the `<i32 as Collate<B>>::Pass` type which ICEs because it is in the wrong environment.

I have rewritten this function to just walk up until it hits the `enclosing_body_owner` and made some other changes since I found this pretty hard to read/understand. Hopefully it's easier to understand now, it also makes it more obvious that this is not implemented in a very principled way and is definitely missing cases :)
@bors bors closed this as completed in ddbbda4 Aug 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 17, 2024
Rollup merge of rust-lang#129168 - BoxyUwU:mismatched_ty_correct_id, r=compiler-errors

Return correct HirId when finding body owner in diagnostics

Fixes rust-lang#129145
Fixes rust-lang#128810

r? ```@compiler-errors```

```rust
fn generic<const N: u32>() {}

trait Collate<const A: u32> {
    type Pass;
    fn collate(self) -> Self::Pass;
}

impl<const B: u32> Collate<B> for i32 {
    type Pass = ();
    fn collate(self) -> Self::Pass {
        generic::<{ true }>()
        //~^ ERROR: mismatched types
    }
}
```

When type checking the `{ true }` anon const we would error with a type mismatch. This then results in diagnostics code attempting to check whether its due to a type mismatch with the return type. That logic was implemented by walking up the hir until we reached the body owner, except instead of using the `enclosing_body_owner` function it special cased various hir nodes incorrectly resulting in us walking out of the anon const and stopping at `fn collate` instead.

This then resulted in diagnostics logic inside of the anon consts `ParamEnv` attempting to do trait solving involving the `<i32 as Collate<B>>::Pass` type which ICEs because it is in the wrong environment.

I have rewritten this function to just walk up until it hits the `enclosing_body_owner` and made some other changes since I found this pretty hard to read/understand. Hopefully it's easier to understand now, it also makes it more obvious that this is not implemented in a very principled way and is definitely missing cases :)
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

5 participants