Skip to content

[ICE]: remove_or_use_generic: expect_struct: found Item  #156701

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct Type;

enum TypeTreeValueIter<T> {
    A(T),
}

impl<T> TypeTreeValueIter<Type> {
    type Item = T;
}

original:

struct Type;

enum TypeTreeValueIter<T> {
    A(T),
}

impl<T> TypeTreeValueIter<Type> {
    type Item = T;
}

fn main() {}

Version information

rustc 1.97.0-nightly (5ea817c65 2026-05-18)
binary: rustc
commit-hash: 5ea817c65e4896167300b7d2550781b98da9901a
commit-date: 2026-05-18
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Possibly related line of code:

suggestions.push((seg.ident.span.shrink_to_hi(), format!("<{}>", param.name)));
}
if is_param_used {
// If the parameter is used in the body, we also want to suggest adding it to the struct definition if it's not already there
let struct_span = tcx.def_span(struct_def_id);
let last_param_span = if let Some(local_def_id) = struct_def_id.as_local() {
let hir_struct = tcx.hir_node_by_def_id(local_def_id).expect_item().expect_struct();
hir_struct.1.params.last().map(|param| param.span)
} else {
let generics = tcx.generics_of(struct_def_id);
generics.own_params.last().map(|param| tcx.def_span(param.def_id))
};

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

Program output

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


thread 'rustc' (2228181) panicked at /rustc-dev/5ea817c65e4896167300b7d2550781b98da9901a/compiler/rustc_hir_analysis/src/errors/remove_or_use_generic.rs:154:85:
expect_struct: found Item { owner_id: DefId(0:5 ~ mvce[7157]::TypeTreeValueIter), kind: Enum(TypeTreeValueIter#0, Generics { params: [GenericParam { hir_id: HirId(DefId(0:5 ~ mvce[7157]::TypeTreeValueIter).1), def_id: DefId(0:6 ~ mvce[7157]::TypeTreeValueIter::T), name: Plain(T#0), span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:3:24: 3:25 (#0), pure_wrt_drop: false, kind: Type { default: None, synthetic: false }, colon_span: None, source: Generics }], predicates: [], has_where_clause_predicates: false, where_clause_span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:3:26: 3:26 (#0), span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:3:23: 3:26 (#0) }, EnumDef { variants: [Variant { ident: A#0, hir_id: HirId(DefId(0:5 ~ mvce[7157]::TypeTreeValueIter).2), def_id: DefId(0:7 ~ mvce[7157]::TypeTreeValueIter::A), data: Tuple([FieldDef { span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:4:7: 4:8 (#0), vis_span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:4:7: 4:7 (#0), ident: 0#0, hir_id: HirId(DefId(0:5 ~ mvce[7157]::TypeTreeValueIter).6), def_id: DefId(0:9 ~ mvce[7157]::TypeTreeValueIter::A::0), ty: Ty { hir_id: HirId(DefId(0:5 ~ mvce[7157]::TypeTreeValueIter).4), span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:4:7: 4:8 (#0), kind: Path(Resolved(None, Path { span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:4:7: 4:8 (#0), res: Def(TyParam, DefId(0:6 ~ mvce[7157]::TypeTreeValueIter::T)), segments: [PathSegment { ident: T#0, hir_id: HirId(DefId(0:5 ~ mvce[7157]::TypeTreeValueIter).5), res: Def(TyParam, DefId(0:6 ~ mvce[7157]::TypeTreeValueIter::T)), args: None, infer_args: false }] })) }, safety: Safe, default: None }], HirId(DefId(0:5 ~ mvce[7157]::TypeTreeValueIter).3), DefId(0:8 ~ mvce[7157]::TypeTreeValueIter::A::{constructor#0})), disr_expr: None, span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:4:5: 4:9 (#0) }] }), span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:3:1: 5:2 (#0), vis_span: /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:3:1: 3:1 (#0), has_delayed_lints: false, eii: false }
stack backtrace:
   0:     0x7f993748ddb9 - <<std[febbc7d5ef9e8e1f]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[aa07da85d566abbf]::fmt::Display>::fmt
   1:     0x7f9937c1a888 - core[aa07da85d566abbf]::fmt::write
   2:     0x7f99374a4aa6 - <std[febbc7d5ef9e8e1f]::sys::stdio::unix::Stderr as std[febbc7d5ef9e8e1f]::io::Write>::write_fmt
   3:     0x7f9937463dfe - std[febbc7d5ef9e8e1f]::panicking::default_hook::{closure#0}
   4:     0x7f9937481473 - std[febbc7d5ef9e8e1f]::panicking::default_hook
   5:     0x7f993627f031 - std[febbc7d5ef9e8e1f]::panicking::update_hook::<alloc[66402de0da046d42]::boxed::Box<rustc_driver_impl[6c9a40b2ab140533]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f9937481752 - std[febbc7d5ef9e8e1f]::panicking::panic_with_hook
   7:     0x7f9937463ec2 - std[febbc7d5ef9e8e1f]::panicking::panic_handler::{closure#0}
   8:     0x7f993745abc9 - std[febbc7d5ef9e8e1f]::sys::backtrace::__rust_end_short_backtrace::<std[febbc7d5ef9e8e1f]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f993746592d - __rustc[280a9ea41858211c]::rust_begin_unwind
  10:     0x7f99346d090c - core[aa07da85d566abbf]::panicking::panic_fmt
  11:     0x7f99363395b8 - rustc_hir[2fd618c2280f22b2]::hir::expect_failed::<&rustc_hir[2fd618c2280f22b2]::hir::Item>
  12:     0x7f993633e41e - <rustc_hir[2fd618c2280f22b2]::hir::Item>::expect_struct
  13:     0x7f99357d1295 - rustc_hir_analysis[911523de3d691631]::errors::remove_or_use_generic::suggest_to_remove_or_use_generic
  14:     0x7f993814eb53 - rustc_hir_analysis[911523de3d691631]::impl_wf_check::enforce_impl_non_lifetime_params_are_constrained
  15:     0x7f993814e319 - rustc_query_impl[dc639321cf6e8af7]::query_impl::enforce_impl_non_lifetime_params_are_constrained::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f99381559e6 - rustc_query_impl[dc639321cf6e8af7]::execution::try_execute_query::<rustc_data_structures[11d21e362a720300]::vec_cache::VecCache<rustc_span[69dba1113f30a056]::def_id::LocalDefId, rustc_middle[16cd8b9ebbd7d037]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[16cd8b9ebbd7d037]::dep_graph::graph::DepNodeIndex>, false>
  17:     0x7f9938155482 - rustc_query_impl[dc639321cf6e8af7]::query_impl::enforce_impl_non_lifetime_params_are_constrained::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f9938159513 - rustc_hir_analysis[911523de3d691631]::check::check::check_item_type
  19:     0x7f993815641c - rustc_hir_analysis[911523de3d691631]::check::wfcheck::check_well_formed
  20:     0x7f99381563f7 - rustc_query_impl[dc639321cf6e8af7]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7f99381559e6 - rustc_query_impl[dc639321cf6e8af7]::execution::try_execute_query::<rustc_data_structures[11d21e362a720300]::vec_cache::VecCache<rustc_span[69dba1113f30a056]::def_id::LocalDefId, rustc_middle[16cd8b9ebbd7d037]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[16cd8b9ebbd7d037]::dep_graph::graph::DepNodeIndex>, false>
  22:     0x7f993815577b - rustc_query_impl[dc639321cf6e8af7]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7f9938152469 - rustc_hir_analysis[911523de3d691631]::check::wfcheck::check_type_wf
  24:     0x7f9938152379 - rustc_query_impl[dc639321cf6e8af7]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  25:     0x7f9938db3edc - rustc_query_impl[dc639321cf6e8af7]::execution::try_execute_query::<rustc_middle[16cd8b9ebbd7d037]::query::caches::SingleCache<rustc_middle[16cd8b9ebbd7d037]::query::erase::ErasedData<[u8; 1usize]>>, false>
  26:     0x7f9938db3cb7 - rustc_query_impl[dc639321cf6e8af7]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  27:     0x7f9937efe2db - rustc_hir_analysis[911523de3d691631]::check_crate
  28:     0x7f9937ef9c61 - rustc_interface[3e547b2b11ba9fdb]::passes::analysis
  29:     0x7f9938db3289 - rustc_query_impl[dc639321cf6e8af7]::execution::try_execute_query::<rustc_middle[16cd8b9ebbd7d037]::query::caches::SingleCache<rustc_middle[16cd8b9ebbd7d037]::query::erase::ErasedData<[u8; 0usize]>>, false>
  30:     0x7f9938db2f69 - rustc_query_impl[dc639321cf6e8af7]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  31:     0x7f9938dce7cd - rustc_interface[3e547b2b11ba9fdb]::interface::run_compiler::<(), rustc_driver_impl[6c9a40b2ab140533]::run_compiler::{closure#0}>::{closure#1}
  32:     0x7f9938d98740 - std[febbc7d5ef9e8e1f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3e547b2b11ba9fdb]::util::run_in_thread_with_globals<rustc_interface[3e547b2b11ba9fdb]::util::run_in_thread_pool_with_globals<rustc_interface[3e547b2b11ba9fdb]::interface::run_compiler<(), rustc_driver_impl[6c9a40b2ab140533]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  33:     0x7f9938d98e2d - <std[febbc7d5ef9e8e1f]::thread::lifecycle::spawn_unchecked<rustc_interface[3e547b2b11ba9fdb]::util::run_in_thread_with_globals<rustc_interface[3e547b2b11ba9fdb]::util::run_in_thread_pool_with_globals<rustc_interface[3e547b2b11ba9fdb]::interface::run_compiler<(), rustc_driver_impl[6c9a40b2ab140533]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[aa07da85d566abbf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7f9938d99c2c - <std[febbc7d5ef9e8e1f]::sys::thread::unix::Thread>::new::thread_start
  35:     0x7f993229697a - <unknown>
  36:     0x7f993231a2bc - <unknown>
  37:                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.97.0-nightly (5ea817c65 2026-05-18) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [enforce_impl_non_lifetime_params_are_constrained] checking that `<impl at /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:7:1: 7:32>`'s generics are constrained by the impl header
#1 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.7UJNKsSL86S2/rustc_testrunner_tmpdir_reporting.gzNR4EY8Q4mr/mvce.rs:7:1: 7:32>` is well-formed
#2 [check_type_wf] checking that types are well-formed
#3 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0601`.

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions