rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.38k stars 12.72k forks source link

ICE: `unexpected infer type` #123140

Open matthiaskrgr opened 7 months ago

matthiaskrgr commented 7 months ago

auto-reduced (treereduce-rust):

trait Project {
    const SELF: Self;
}

fn take1(_: Project<SELF = { loop {} }>) {}
original code

original: ````rust // Regression test for issue #108271. // Detect and reject generic params in the type of assoc consts used in an equality bound. #![feature(associated_const_equality)] trait Trait<'a, T: 'a, const N: usize> { //~^ NOTE the lifetime parameter `'r` is defined here //~| NOTE the lifetime parameter `'r` is defined here type Assoc: Trait<'r, Self, Q, K = { loop {} }> //~^ ERROR the type of the associated constant `K` must not depend on generic parameters //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the lifetime parameter `'r` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on `Self` //~| NOTE its type must not depend on `Self` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the const parameter `Q` //~| NOTE the const parameter `Q` is defined here //~| NOTE `K` has type `&'r [Self; Q]` //~| NOTE its type must not depend on the lifetime parameter `'r` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on `Self` //~| NOTE its type must not depend on `Self` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the const parameter `Q` //~| NOTE the const parameter `Q` is defined here //~| NOTE `K` has type `&'r [Self; Q]` //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` where Self: Sized + 'r; } fn take0<'r, A: Project, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} //~^ ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the lifetime parameter `'r` //~| NOTE the lifetime parameter `'r` is defined here //~^ ERROR the type of the associated constant `K` must not depend on generic parameters //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the type parameter `A` //~| NOTE the type parameter `A` is defined here //~| NOTE `K` has type `&'r [A; Q]` //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the const parameter `Q` //~| NOTE the const parameter `Q` is defined here //~| NOTE `K` has type `&'r [A; Q]` trait Project { const SELF: Self; } fn take1(_: Project) {} //~^ ERROR the type of the associated constant `SELF` must not depend on `impl Trait` //~| NOTE its type must not depend on `impl Trait` //~| NOTE the `impl Trait` is specified here fn take2>(_: P) {} //~^ ERROR the type of the associated constant `SELF` must not depend on generic parameters //~| NOTE its type must not depend on the type parameter `P` //~| NOTE the type parameter `P` is defined here //~| NOTE `SELF` has type `P` trait Iface<'r> { //~^ NOTE the lifetime parameter `'r` is defined here //~| NOTE the lifetime parameter `'r` is defined here type Assoc: Trait<'r, Self, Q, K = { loop {} }> //~^ ERROR the type of the associated constant `K` must not depend on generic parameters //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the lifetime parameter `'r` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on `Self` //~| NOTE its type must not depend on `Self` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the const parameter `Q` //~| NOTE the const parameter `Q` is defined here //~| NOTE `K` has type `&'r [Self; Q]` //~| NOTE its type must not depend on the lifetime parameter `'r` //~| NOTE `K` has type `&'r [Self; Q]` //~| ERROR the type of the associated constant `K` must not depend on `Self` //~| NOTE its type must not depend on `Self` //~| NOTE `K` has type `&'r [A; Q]` //~| ERROR the type of the associated constant `K` must not depend on generic parameters //~| NOTE its type must not depend on the const parameter `Q` //~| NOTE the const parameter `Q` is defined here //~| NOTE `K` has type `&'r [Self; Q]` //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` //~^ ERROR the type of the associated constant `SELF` must not depend on generic parameters //~| NOTE its type must not depend on `Self` SELF =; } fn main() { loop {} } ````

Version information

rustc 1.79.0-nightly (d5db7fb53 2024-03-27)
binary: rustc
commit-hash: d5db7fb537c0352eec3855aa0331c271c48ac4f6
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

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

Program output

``` error[E0658]: associated const equality is incomplete --> /tmp/icemaker_global_tempdir.iaTnhD6gpiUs/rustc_testrunner_tmpdir_reporting.j6t1MTYnJCzk/mvce.rs:5:21 | 5 | fn take1(_: Project) {} | ^^^^^^^^^^^^^^^^^^ | = note: see issue #92827 for more information = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable = note: this compiler was built on 2024-03-27; consider upgrading it if it is out of date error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.iaTnhD6gpiUs/rustc_testrunner_tmpdir_reporting.j6t1MTYnJCzk/mvce.rs:5:44 | 5 | fn take1(_: Project) {} | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.iaTnhD6gpiUs/rustc_testrunner_tmpdir_reporting.j6t1MTYnJCzk/mvce.rs` warning: trait objects without an explicit `dyn` are deprecated --> /tmp/icemaker_global_tempdir.iaTnhD6gpiUs/rustc_testrunner_tmpdir_reporting.j6t1MTYnJCzk/mvce.rs:5:13 | 5 | fn take1(_: Project) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `#[warn(bare_trait_objects)]` on by default help: if this is an object-safe trait, use `dyn` | 5 | fn take1(_: dyn Project) {} | +++ error: internal compiler error: compiler/rustc_infer/src/infer/relate/generalize.rs:458:17: unexpected infer type: FreshTy(0) thread 'rustc' panicked at compiler/rustc_infer/src/infer/relate/generalize.rs:458:17: Box stack backtrace: 0: 0x7a1979cc4235 - std::backtrace_rs::backtrace::libunwind::trace::h35c05b60de86c082 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x7a1979cc4235 - std::backtrace_rs::backtrace::trace_unsynchronized::h716cc93b6616466b at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7a1979cc4235 - std::sys_common::backtrace::_print_fmt::h2eafab78e5405086 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7a1979cc4235 - ::fmt::h782eb93aef6bbfdc at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7a1979d153fb - core::fmt::rt::Argument::fmt::h423c1825313972bd at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/core/src/fmt/rt.rs:142:9 5: 0x7a1979d153fb - core::fmt::write::h8bf0eb0713660507 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/core/src/fmt/mod.rs:1153:17 6: 0x7a1979cb8e4f - std::io::Write::write_fmt::h1869b88304121496 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/io/mod.rs:1843:15 7: 0x7a1979cc400e - std::sys_common::backtrace::_print::h3f71a60e8eec22db at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7a1979cc400e - std::sys_common::backtrace::print::hbc0f4a4435261b96 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7a1979cc6c89 - std::panicking::default_hook::{{closure}}::hcb90344a23466037 10: 0x7a1979cc69f3 - std::panicking::default_hook::h4e7402b852825f26 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/panicking.rs:292:9 11: 0x7a19765f7eee - std[ee38f4c3e7db4cb4]::panicking::update_hook::>::{closure#0} 12: 0x7a1979cc738c - as core::ops::function::Fn>::call::h41b4c40829d8b80c at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/alloc/src/boxed.rs:2032:9 13: 0x7a1979cc738c - std::panicking::rust_panic_with_hook::h34319b28877d2524 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/panicking.rs:793:13 14: 0x7a1976627d64 - std[ee38f4c3e7db4cb4]::panicking::begin_panic::::{closure#0} 15: 0x7a1976624c86 - std[ee38f4c3e7db4cb4]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7a1976624966 - std[ee38f4c3e7db4cb4]::panicking::begin_panic:: 17: 0x7a19766311f1 - ::emit_producing_guarantee 18: 0x7a1976ac17bc - rustc_middle[edfcb02b6a244f2]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7a1976aa52ba - rustc_middle[edfcb02b6a244f2]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7a1976aa515b - rustc_middle[edfcb02b6a244f2]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7a1974703930 - rustc_middle[edfcb02b6a244f2]::util::bug::bug_fmt 22: 0x7a1977aa5b28 - ::tys 23: 0x7a1977a9116a - ::tys 24: 0x7a1977a836c3 - ::coerce 25: 0x7a1977a721ab - ::demand_coerce 26: 0x7a1977bf594d - rustc_hir_typeck[d5655f81daec17bc]::typeck 27: 0x7a1977bf3a57 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 28: 0x7a1977be0971 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 29: 0x7a1977bdcdcc - rustc_query_impl[2d2f12ae863522a2]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 30: 0x7a1977dcb79c - rustc_mir_build[1b46b2c93e920ce6]::thir::pattern::check_match::check_match 31: 0x7a1977dca93b - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 32: 0x7a197813bd7c - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 33: 0x7a197813b9ff - rustc_query_impl[2d2f12ae863522a2]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace 34: 0x7a1977dba5f3 - rustc_mir_build[1b46b2c93e920ce6]::build::mir_build 35: 0x7a1977db9aa8 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 36: 0x7a1977be0971 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 37: 0x7a1977be054c - rustc_query_impl[2d2f12ae863522a2]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 38: 0x7a1977be024b - rustc_middle[edfcb02b6a244f2]::query::plumbing::query_get_at::>> 39: 0x7a197812f701 - rustc_mir_transform[953c3acd5e2981a0]::mir_const_qualif 40: 0x7a197812f6b5 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 41: 0x7a197812f18b - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 42: 0x7a197812ef09 - rustc_query_impl[2d2f12ae863522a2]::query_impl::mir_const_qualif::get_query_non_incr::__rust_end_short_backtrace 43: 0x7a197812ed36 - rustc_middle[edfcb02b6a244f2]::query::plumbing::query_get_at::>> 44: 0x7a1974f714b6 - rustc_mir_transform[953c3acd5e2981a0]::mir_promoted 45: 0x7a1977d0341c - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 46: 0x7a1977d036ed - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 47: 0x7a1977d03325 - rustc_query_impl[2d2f12ae863522a2]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace 48: 0x7a1977bdead0 - rustc_borrowck[87c1aa11a50066c]::mir_borrowck 49: 0x7a1977bdea17 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 50: 0x7a1977be0971 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 51: 0x7a1977be048c - rustc_query_impl[2d2f12ae863522a2]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace 52: 0x7a1978136aab - rustc_mir_transform[953c3acd5e2981a0]::mir_drops_elaborated_and_const_checked 53: 0x7a19781361a5 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 54: 0x7a1977be0971 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 55: 0x7a1977be030c - rustc_query_impl[2d2f12ae863522a2]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace 56: 0x7a1977be024b - rustc_middle[edfcb02b6a244f2]::query::plumbing::query_get_at::>> 57: 0x7a1978134f6c - rustc_mir_transform[953c3acd5e2981a0]::mir_for_ctfe 58: 0x7a1978134edb - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 59: 0x7a1977bc6f9c - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 60: 0x7a19785b049e - rustc_query_impl[2d2f12ae863522a2]::query_impl::mir_for_ctfe::get_query_non_incr::__rust_end_short_backtrace 61: 0x7a19785b07ca - >::load_mir 62: 0x7a19785b25df - rustc_const_eval[176732e30479c26b]::const_eval::eval_queries::eval_to_allocation_raw_provider 63: 0x7a19785b2340 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 64: 0x7a19785af396 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::, rustc_middle[edfcb02b6a244f2]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 65: 0x7a19785aef6c - rustc_query_impl[2d2f12ae863522a2]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace 66: 0x7a19785aeb0a - rustc_middle[edfcb02b6a244f2]::query::plumbing::query_get_at::, rustc_middle[edfcb02b6a244f2]::query::erase::Erased<[u8; 24usize]>>> 67: 0x7a197858c421 - rustc_const_eval[176732e30479c26b]::const_eval::valtrees::eval_to_valtree 68: 0x7a197858c3a2 - )>>::call_once 69: 0x7a197858c376 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 70: 0x7a197858c32f - )>>::call_once 71: 0x7a19785af471 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::, rustc_middle[edfcb02b6a244f2]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 72: 0x7a19785999ac - rustc_query_impl[2d2f12ae863522a2]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace 73: 0x7a1977d3e847 - rustc_middle[edfcb02b6a244f2]::query::plumbing::query_get_at::, rustc_middle[edfcb02b6a244f2]::query::erase::Erased<[u8; 24usize]>>> 74: 0x7a19782b791c - ::const_eval_global_id_for_typeck 75: 0x7a19782b70a1 - ::const_eval_resolve_for_typeck 76: 0x7a19782b6e56 - ::eval 77: 0x7a1977bf07c1 - >::fold_const 78: 0x7a19770f6dcd - >::fold_binder:: 79: 0x7a19781fb427 - >::try_super_fold_with:: 80: 0x7a19780605ec - ::normalize:: 81: 0x7a197806140b - rustc_hir_analysis[9a86bb4861b99e0a]::check::wfcheck::check_fn_or_method 82: 0x7a197805f28f - rustc_hir_analysis[9a86bb4861b99e0a]::check::wfcheck::check_item_fn 83: 0x7a197806fec5 - rustc_hir_analysis[9a86bb4861b99e0a]::check::wfcheck::check_well_formed 84: 0x7a197806e787 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 85: 0x7a197806df00 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 86: 0x7a197806dc7f - rustc_query_impl[2d2f12ae863522a2]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace 87: 0x7a197806bbc6 - rustc_hir_analysis[9a86bb4861b99e0a]::check::wfcheck::check_mod_type_wf 88: 0x7a197806ba09 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 89: 0x7a197849e830 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 90: 0x7a197849e5db - rustc_query_impl[2d2f12ae863522a2]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace 91: 0x7a1977bdb07b - rustc_hir_analysis[9a86bb4861b99e0a]::check_crate 92: 0x7a1977f4aaea - rustc_interface[8a3ca12de370bc6d]::passes::analysis 93: 0x7a1977f4a659 - rustc_query_impl[2d2f12ae863522a2]::plumbing::__rust_begin_short_backtrace::> 94: 0x7a1978794da5 - rustc_query_system[1181c72fefabd0ae]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2d2f12ae863522a2]::plumbing::QueryCtxt, false> 95: 0x7a1978794b09 - rustc_query_impl[2d2f12ae863522a2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 96: 0x7a1978687299 - rustc_interface[8a3ca12de370bc6d]::interface::run_compiler::, rustc_driver_impl[b62da54691605f75]::run_compiler::{closure#0}>::{closure#0} 97: 0x7a19787665e3 - std[ee38f4c3e7db4cb4]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[b62da54691605f75]::run_compiler::{closure#0}>::{closure#0}, core[852c89a24d64efc7]::result::Result<(), rustc_span[b9a3f8dff5ad8c72]::ErrorGuaranteed>>::{closure#0}, core[852c89a24d64efc7]::result::Result<(), rustc_span[b9a3f8dff5ad8c72]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[852c89a24d64efc7]::result::Result<(), rustc_span[b9a3f8dff5ad8c72]::ErrorGuaranteed>> 98: 0x7a1978766410 - <::spawn_unchecked_, rustc_driver_impl[b62da54691605f75]::run_compiler::{closure#0}>::{closure#0}, core[852c89a24d64efc7]::result::Result<(), rustc_span[b9a3f8dff5ad8c72]::ErrorGuaranteed>>::{closure#0}, core[852c89a24d64efc7]::result::Result<(), rustc_span[b9a3f8dff5ad8c72]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[852c89a24d64efc7]::result::Result<(), rustc_span[b9a3f8dff5ad8c72]::ErrorGuaranteed>>::{closure#1} as core[852c89a24d64efc7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 99: 0x7a1979cd0ca9 - as core::ops::function::FnOnce>::call_once::hc7f4be48b61584a0 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/alloc/src/boxed.rs:2018:9 100: 0x7a1979cd0ca9 - as core::ops::function::FnOnce>::call_once::h98f2eb6153ee7231 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/alloc/src/boxed.rs:2018:9 101: 0x7a1979cd0ca9 - std::sys::pal::unix::thread::Thread::new::thread_start::h5b05a8117b189654 at /rustc/d5db7fb537c0352eec3855aa0331c271c48ac4f6/library/std/src/sys/pal/unix/thread.rs:108:17 102: 0x7a19734a955a - 103: 0x7a1973526a3c - 104: 0x0 - 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.79.0-nightly (d5db7fb53 2024-03-27) running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `take1::{constant#0}` #1 [check_match] match-checking `take1::{constant#0}` #2 [mir_built] building MIR for `take1::{constant#0}` #3 [mir_const_qualif] const checking `take1::{constant#0}` #4 [mir_promoted] promoting constants in MIR for `take1::{constant#0}` #5 [mir_borrowck] borrow-checking `take1::{constant#0}` #6 [mir_drops_elaborated_and_const_checked] elaborating drops for `take1::{constant#0}` #7 [mir_for_ctfe] caching mir of `take1::{constant#0}` for CTFE #8 [eval_to_allocation_raw] const-evaluating + checking `take1::{constant#0}` #9 [eval_to_valtree] evaluating type-level constant #10 [check_well_formed] checking that `take1` is well-formed #11 [check_mod_type_wf] checking that types are well-formed in top-level module #12 [analysis] running analysis passes on this crate end of query stack error: aborting due to 3 previous errors; 1 warning emitted Some errors have detailed explanations: E0601, E0658. For more information about an error, try `rustc --explain E0601`. ```

matthiaskrgr commented 7 months ago

Regression in nightly-2023-02-18

looking for regression commit between 2023-02-17 and 2023-02-18 fetching (via remote github) commits from max(9a7cc6c32f1a690f86827e4724bcda85e506ef35, 2023-02-15) to 9aa5c24b7d763fb98d998819571128ff2eb8a3ca ending github query because we found starting sha: 9a7cc6c32f1a690f86827e4724bcda85e506ef35 get_commits_between returning commits, len: 8 commit[0] 2023-02-16: Auto merge of #108127 - matthiaskrgr:rollup-kpzfc6j, r=matthiaskrgr commit[1] 2023-02-16: Auto merge of #107833 - Zoxc:arena-query-clean, r=cjgillot commit[2] 2023-02-17: Auto merge of #108145 - matthiaskrgr:rollup-bgadak1, r=matthiaskrgr commit[3] 2023-02-17: Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU commit[4] 2023-02-17: Auto merge of #108058 - Zoxc:query-ctxtx-byval, r=cjgillot commit[5] 2023-02-17: Auto merge of #107965 - BoxyUwU:add_const_arg_has_type_predicate, r=compiler-errors commit[6] 2023-02-17: Auto merge of #108159 - matthiaskrgr:rollup-5k2j7cx, r=matthiaskrgr commit[7] 2023-02-17: Auto merge of #108075 - WaffleLapkin:de-arena-allocates-you-OwO, r=Nilstrieb ERROR: no CI builds available between 9a7cc6c32f1a690f86827e4724bcda85e506ef35 and 9aa5c24b7d763fb98d998819571128ff2eb8a3ca within last 167 days

fmease commented 7 months ago

Oh, I see. I forgot about tcx.types.trait_object_dummy_self (FreshTy(0)) in #121258. Ofc, my PR doesn't regress anything here but still I forgot about this case. Very likely we need to reject trait_object_dummy_self manually and can't rely on registering a <Ty as core::marker::ConstParamTy> obligation[^1] (which I plan to do to fix #119783 but the location is still unclear to me[^2]) because we just shouldn't be feeding the fake FreshTy(0) to type_of as can be seen by the ICE, the trait solver & the inference engine obviously can't handle such malformed obligations.

[^1]: Trait object types never impl ConstParamTy. [^2]: HIR wf-checking isn't an option because we lack too much information at this stage, during normalization isn't an option since we shouldn't rely on normalization for ensuring well-formedness, leaving us with constructing an ObligationCtxt ad hoc during HIR ty lowering which isn't super great.

fmease commented 7 months ago

Wait, I don't think we should deny trait_object_dummy_self in the code path that rejects early-bound and escaping late-bound vars, that's not the right thing to do. They are semi-legitimate types that get discarded by helpers like ExistentialTraitRef::erase_self_ty and ExistentialProjection::erase_self_ty, e.g. inside lower_trait_object_ty (which also introduces these dummy_self types).

Oh, okay, so inside lower_trait_object_ty we discard const projections if their args contain a dummy self type but in our case, the projected type (the type_of(proj)) contains a dummy self type.

As the comment over there says such a (const) projection would expand to an infinitely-long type. We also need to check the projected type for dummy self types and drop the existential const projection in case we find any. Edit: Tho, no I'm confused since the projection_ty and the term.ct().ty() should be same in this case due to the anon const feeding, so why isn't it detecting anything? :thinking: Update: We don't even reach the aforementioned branch inside lower_trait_object_ty for some reason. Update: Oh, that's not the code path we're interested in, that's only for super trait elab.

fmease commented 7 months ago

Stopping my investigations for now but overwriting the args (incl. the self type subst) of such projections with {type error} as well turning the const projection term into {const error} if the args or the type of the projected const contains trait_object_dummy_self didn't help. Note that lower_trait_object_ty does parts of this already.

I haven't dug deeper yet but the cause of this might be the anon const query feeding in lower_assoc_item_binding: We may feed trait_object_dummy_self to type_of(AnonConst) which can't be undone.