Skip to content

ICE: expected generic param to be owned by item #132534

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait Fun {
    fn identity<const N: usize, 'a, T = u32>() -> T::Error<{ u32::MIN }> {
        t
    }
}

original:

trait Fun {
    type F<'should_pad_explicitly_packed_field>;

    fn identity<const N: usize, 'a, T = u32>(t: Self::F<'a>) -> T::Error<{u32::MIN}> { t }
}

impl <AL> Fun for T {
    type F<'a> = Self
}

fn bug<'a, MyDerivePrint: Fun<F<'A215> = T>>(t: Groups) -> std::future::Future<Output = Result<(), String>> {
    T::identity(t)
}


fn main() {
    let x = 10

    bug(x);
}

Version information

rustc 1.84.0-nightly (588a42035 2024-11-02)
binary: rustc
commit-hash: 588a4203508ed7c76750c96b482641261630ed36
commit-date: 2024-11-02
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Possibly related line of code:

// Double check that the bounds *only* contain `SelfTy: Trait` preds.
let self_ty = match tcx.def_kind(def_id) {
DefKind::TyParam => Ty::new_param(
tcx,
tcx.generics_of(item_def_id)
.param_def_id_to_index(tcx, def_id.to_def_id())
.expect("expected generic param to be owned by item"),
tcx.item_name(def_id.to_def_id()),
),
DefKind::Trait | DefKind::TraitAlias => tcx.types.self_param,
_ => unreachable!(),
};
assert_only_contains_predicates_from(

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

Program output

error: lifetime parameters must be declared prior to type and const parameters
 --> /tmp/icemaker_global_tempdir.Idt105MOd4Ml/rustc_testrunner_tmpdir_reporting.EJv1Jxh24dAe/mvce.rs:2:33
  |
2 |     fn identity<const N: usize, 'a, T = u32>() -> T::Error<{ u32::MIN }> {
  |                -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`

error[E0425]: cannot find value `t` in this scope
 --> /tmp/icemaker_global_tempdir.Idt105MOd4Ml/rustc_testrunner_tmpdir_reporting.EJv1Jxh24dAe/mvce.rs:3:9
  |
2 |     fn identity<const N: usize, 'a, T = u32>() -> T::Error<{ u32::MIN }> {
  |                       - similarly named const parameter `N` defined here
3 |         t
  |         ^ help: a const parameter with a similar name exists: `N`

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

error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
 --> /tmp/icemaker_global_tempdir.Idt105MOd4Ml/rustc_testrunner_tmpdir_reporting.EJv1Jxh24dAe/mvce.rs:2:37
  |
2 |     fn identity<const N: usize, 'a, T = u32>() -> T::Error<{ u32::MIN }> {
  |                                     ^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
  = note: `#[deny(invalid_type_param_default)]` on by default

error[E0220]: associated type `Error` not found for `T`
 --> /tmp/icemaker_global_tempdir.Idt105MOd4Ml/rustc_testrunner_tmpdir_reporting.EJv1Jxh24dAe/mvce.rs:2:54
  |
2 |     fn identity<const N: usize, 'a, T = u32>() -> T::Error<{ u32::MIN }> {
  |                                                      ^^^^^ associated type `Error` not found

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect/predicates_of.rs:852:18:
expected generic param to be owned by item
stack backtrace:
   0:     0x77761e05720a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hb6cd0a6bac89b6a6
   1:     0x77761e8040ca - core::fmt::write::haf33c0c90f8a330f
   2:     0x77761f7de991 - std::io::Write::write_fmt::h8e68b0ac6f9ed075
   3:     0x77761e057062 - std::sys::backtrace::BacktraceLock::print::hfcb510b62adfb854
   4:     0x77761e059566 - std::panicking::default_hook::{{closure}}::h04e002fdca100125
   5:     0x77761e0593b0 - std::panicking::default_hook::h4e6c1c73a1b39936
   6:     0x77761d0dcc49 - std[938f00e4f3f8ec0a]::panicking::update_hook::<alloc[f5b601f10d0c9e52]::boxed::Box<rustc_driver_impl[f21e318f0b376187]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x77761e059c78 - std::panicking::rust_panic_with_hook::h7c34462f21943817
   8:     0x77761e059a4a - std::panicking::begin_panic_handler::{{closure}}::he45bce4689172cf1
   9:     0x77761e0576b9 - std::sys::backtrace::__rust_end_short_backtrace::h1da82e369c9d9924
  10:     0x77761e05970c - rust_begin_unwind
  11:     0x77761aacfcc0 - core::panicking::panic_fmt::h388c11da31cb94e0
  12:     0x77761aff8dfb - core::option::expect_failed::h5a9313176825b44a
  13:     0x77761f1b6b0c - rustc_hir_analysis[4467b4076426cba3]::collect::predicates_of::type_param_predicates
  14:     0x77761f1b64e6 - rustc_query_impl[a29eb052c37ab918]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a29eb052c37ab918]::query_impl::type_param_predicates::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 16usize]>>
  15:     0x77761f1b64af - <rustc_query_impl[a29eb052c37ab918]::query_impl::type_param_predicates::dynamic_query::{closure#2} as core[87cd10b3002d899c]::ops::function::FnOnce<(rustc_middle[b1d1e394adbcd929]::ty::context::TyCtxt, (rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_span[d3d4eeacb399f824]::symbol::Ident))>>::call_once
  16:     0x77761f30eaad - rustc_query_system[3c80327c1b2e9be7]::query::plumbing::try_execute_query::<rustc_query_impl[a29eb052c37ab918]::DynamicConfig<rustc_query_system[3c80327c1b2e9be7]::query::caches::DefaultCache<(rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_span[d3d4eeacb399f824]::symbol::Ident), rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[a29eb052c37ab918]::plumbing::QueryCtxt, false>
  17:     0x77761f30e810 - rustc_query_impl[a29eb052c37ab918]::query_impl::type_param_predicates::get_query_non_incr::__rust_end_short_backtrace
  18:     0x77761f30e546 - rustc_middle[b1d1e394adbcd929]::query::plumbing::query_get_at::<rustc_query_system[3c80327c1b2e9be7]::query::caches::DefaultCache<(rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_span[d3d4eeacb399f824]::symbol::Ident), rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 16usize]>>>
  19:     0x77761f30e403 - <rustc_hir_analysis[4467b4076426cba3]::collect::ItemCtxt as rustc_hir_analysis[4467b4076426cba3]::hir_ty_lowering::HirTyLowerer>::probe_ty_param_bounds
  20:     0x77761f189668 - <dyn rustc_hir_analysis[4467b4076426cba3]::hir_ty_lowering::HirTyLowerer>::probe_single_ty_param_bound_for_assoc_item
  21:     0x77761f18f9cd - <dyn rustc_hir_analysis[4467b4076426cba3]::hir_ty_lowering::HirTyLowerer>::lower_assoc_path
  22:     0x77761f1b9254 - <dyn rustc_hir_analysis[4467b4076426cba3]::hir_ty_lowering::HirTyLowerer>::lower_ty
  23:     0x77761bc156b6 - rustc_hir_analysis[4467b4076426cba3]::collect::type_of::type_of
  24:     0x77761e9b3a2a - rustc_query_impl[a29eb052c37ab918]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a29eb052c37ab918]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>
  25:     0x77761e9b26aa - rustc_query_system[3c80327c1b2e9be7]::query::plumbing::try_execute_query::<rustc_query_impl[a29eb052c37ab918]::DynamicConfig<rustc_query_system[3c80327c1b2e9be7]::query::caches::DefIdCache<rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a29eb052c37ab918]::plumbing::QueryCtxt, false>
  26:     0x77761e9b223f - rustc_query_impl[a29eb052c37ab918]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  27:     0x77761ef0358d - rustc_middle[b1d1e394adbcd929]::query::plumbing::query_get_at::<rustc_query_system[3c80327c1b2e9be7]::query::caches::DefIdCache<rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>>
  28:     0x77761eae06ff - rustc_hir_typeck[64dee917abf8f083]::typeck
  29:     0x77761eade8d3 - rustc_query_impl[a29eb052c37ab918]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a29eb052c37ab918]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>
  30:     0x77761eeaa4c1 - rustc_query_system[3c80327c1b2e9be7]::query::plumbing::try_execute_query::<rustc_query_impl[a29eb052c37ab918]::DynamicConfig<rustc_query_system[3c80327c1b2e9be7]::query::caches::VecCache<rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a29eb052c37ab918]::plumbing::QueryCtxt, false>
  31:     0x77761eea898d - rustc_query_impl[a29eb052c37ab918]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  32:     0x77761eea9a8a - rustc_hir_typeck[64dee917abf8f083]::used_trait_imports
  33:     0x77761eea9999 - rustc_query_impl[a29eb052c37ab918]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a29eb052c37ab918]::query_impl::used_trait_imports::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>
  34:     0x77761eeaa4c1 - rustc_query_system[3c80327c1b2e9be7]::query::plumbing::try_execute_query::<rustc_query_impl[a29eb052c37ab918]::DynamicConfig<rustc_query_system[3c80327c1b2e9be7]::query::caches::VecCache<rustc_span[d3d4eeacb399f824]::def_id::LocalDefId, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a29eb052c37ab918]::plumbing::QueryCtxt, false>
  35:     0x77761eea9953 - rustc_query_impl[a29eb052c37ab918]::query_impl::used_trait_imports::get_query_non_incr::__rust_end_short_backtrace
  36:     0x77761eea949d - rustc_hir_analysis[4467b4076426cba3]::check_unused::check_unused_traits
  37:     0x77761eea9071 - rustc_query_impl[a29eb052c37ab918]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a29eb052c37ab918]::query_impl::check_unused_traits::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 0usize]>>
  38:     0x77761f78a5ae - rustc_query_system[3c80327c1b2e9be7]::query::plumbing::try_execute_query::<rustc_query_impl[a29eb052c37ab918]::DynamicConfig<rustc_query_system[3c80327c1b2e9be7]::query::caches::SingleCache<rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[a29eb052c37ab918]::plumbing::QueryCtxt, false>
  39:     0x77761f78a34e - rustc_query_impl[a29eb052c37ab918]::query_impl::check_unused_traits::get_query_non_incr::__rust_end_short_backtrace
  40:     0x77761eea65a4 - rustc_hir_analysis[4467b4076426cba3]::check_crate
  41:     0x77761ed4324a - rustc_interface[71aa3b1bf0e9b32c]::passes::run_required_analyses
  42:     0x77761f5f709e - rustc_interface[71aa3b1bf0e9b32c]::passes::analysis
  43:     0x77761f5f706f - rustc_query_impl[a29eb052c37ab918]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a29eb052c37ab918]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 1usize]>>
  44:     0x77761f788e2e - rustc_query_system[3c80327c1b2e9be7]::query::plumbing::try_execute_query::<rustc_query_impl[a29eb052c37ab918]::DynamicConfig<rustc_query_system[3c80327c1b2e9be7]::query::caches::SingleCache<rustc_middle[b1d1e394adbcd929]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a29eb052c37ab918]::plumbing::QueryCtxt, false>
  45:     0x77761f788b0e - rustc_query_impl[a29eb052c37ab918]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x77761f67421d - rustc_interface[71aa3b1bf0e9b32c]::interface::run_compiler::<core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>, rustc_driver_impl[f21e318f0b376187]::run_compiler::{closure#0}>::{closure#1}
  47:     0x77761f6f3010 - std[938f00e4f3f8ec0a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[71aa3b1bf0e9b32c]::util::run_in_thread_with_globals<rustc_interface[71aa3b1bf0e9b32c]::util::run_in_thread_pool_with_globals<rustc_interface[71aa3b1bf0e9b32c]::interface::run_compiler<core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>, rustc_driver_impl[f21e318f0b376187]::run_compiler::{closure#0}>::{closure#1}, core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>>::{closure#0}, core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>>
  48:     0x77761f6f342b - <<std[938f00e4f3f8ec0a]::thread::Builder>::spawn_unchecked_<rustc_interface[71aa3b1bf0e9b32c]::util::run_in_thread_with_globals<rustc_interface[71aa3b1bf0e9b32c]::util::run_in_thread_pool_with_globals<rustc_interface[71aa3b1bf0e9b32c]::interface::run_compiler<core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>, rustc_driver_impl[f21e318f0b376187]::run_compiler::{closure#0}>::{closure#1}, core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>>::{closure#0}, core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[87cd10b3002d899c]::result::Result<(), rustc_span[d3d4eeacb399f824]::ErrorGuaranteed>>::{closure#1} as core[87cd10b3002d899c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x77761f6f3ef9 - std::sys::pal::unix::thread::Thread::new::thread_start::h2150c7c4a48ccbb3
  50:     0x777620fca39d - <unknown>
  51:     0x77762104f49c - <unknown>
  52:                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.84.0-nightly (588a42035 2024-11-02) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [type_param_predicates] computing the bounds for type parameter `T`
#1 [type_of] computing type of `Fun::identity::{constant#0}`
end of query stack
error: aborting due to 5 previous errors

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions