Skip to content

[ICE]: lifetime parameter for associated type in Trait impl for an Enum #160287

Description

@SleighPenguin22

I was busy writing an impl for some trait that has an associated type.
I had one impl for this trait where the associated type had a lifetime parameter, e.g. type AssocType = FooStruct<'a>
By experimenting i found the following things:

  • the panic occurs when the implementor is an Enum (a Struct implementor compiles just fine)
  • the panic does not occur when the associated type has the 'static lifetime
  • the panic occurs when the impl block has at least one generic lifetime, but also occurs when more lifetime and/or type parameters are added

The root issues seems the generic lifetime in the impl Trait block. When using some type with a lifetime param, i.e.

struct FooStruct<'a> {
    some_ref: &'a str
}

and using that as the associated type for the Enum like this:

impl<'a> Foo for FooEnum {
    type Bar = FooStruct<'a>;
}

also causes a panic.

In short, as long as a trait impl has a lifetime parameter, and that parameter is used for an associated type, I get a panic.
The panic does not occur in Beta or Nightly, only in Stable. I do not see it listed in the patch notes on releases.rs.

I might try to find the exact commit that caused it, it would be my first time trying something like that, would that be doable? I would love to contribute

Code

use std::marker::PhantomData;

pub trait Foo {
    type Bar;
}

pub enum FooEnum {}

impl<'a> Foo for FooEnum {
    type Bar = PhantomData<&'a ()>;
}

Meta

rustc --version --verbose:

rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-unknown-linux-gnu
release: 1.97.1
LLVM version: 22.1.6

Error output

   Compiling fuckaround v0.1.0 (/home/wannie/Desktop/fuckaround)

thread 'rustc' (133938) panicked at /rustc-dev/8bab26f4f68e0e26f0bb7960be334d5b520ea452/compiler/rustc_hir_analysis/src/errors/remove_or_use_generic.rs:154:85:
expect_struct: found Item { owner_id: DefId(0:6 ~ fuckaround[d31c]::FooEnum), kind: Enum(FooEnum#0, Generics { params: [], predicates: [], has_where_clause_predicates: false, where_clause_span: src/lib.rs:7:17: 7:17 (#0), span: src/lib.rs:7:17: 7:17 (#0) }, EnumDef { variants: [] }), span: src/lib.rs:7:1: 7:20 (#0), vis_span: src/lib.rs:7:1: 7:4 (#0), has_delayed_lints: false, eii: false }
stack backtrace:
   0:     0x7fbc5c4901f9 - <<std[1e3c4ec04c5261a9]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[37f591cfbe66b0b1]::fmt::Display>::fmt
   1:     0x7fbc5cc20cc8 - core[37f591cfbe66b0b1]::fmt::write
   2:     0x7fbc5e00d936 - <std[1e3c4ec04c5261a9]::sys::stdio::unix::Stderr as std[1e3c4ec04c5261a9]::io::Write>::write_fmt
   3:     0x7fbc5c4663fe - std[1e3c4ec04c5261a9]::panicking::default_hook::{closure#0}
   4:     0x7fbc5c483b33 - std[1e3c4ec04c5261a9]::panicking::default_hook
   5:     0x7fbc5b276c31 - std[1e3c4ec04c5261a9]::panicking::update_hook::<alloc[24b8200b0946867]::boxed::Box<rustc_driver_impl[4e5b0da0f4005eeb]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fbc5c483e12 - std[1e3c4ec04c5261a9]::panicking::panic_with_hook
   7:     0x7fbc5c4664c2 - std[1e3c4ec04c5261a9]::panicking::panic_handler::{closure#0}
   8:     0x7fbc5c45a9a9 - std[1e3c4ec04c5261a9]::sys::backtrace::__rust_end_short_backtrace::<std[1e3c4ec04c5261a9]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fbc5c467f2d - __rustc[6ef78fba13ac776c]::rust_begin_unwind
  10:     0x7fbc58f192dc - core[37f591cfbe66b0b1]::panicking::panic_fmt
  11:     0x7fbc5b333a08 - rustc_hir[ffb6a75957ec3d1e]::hir::expect_failed::<&rustc_hir[ffb6a75957ec3d1e]::hir::Item>
  12:     0x7fbc5b335b8e - <rustc_hir[ffb6a75957ec3d1e]::hir::Item>::expect_struct
  13:     0x7fbc59b15145 - rustc_hir_analysis[1956eea595525479]::errors::remove_or_use_generic::suggest_to_remove_or_use_generic
  14:     0x7fbc5d3cc961 - rustc_hir_analysis[1956eea595525479]::check::check::check_item_type
  15:     0x7fbc5d3c1be6 - rustc_hir_analysis[1956eea595525479]::check::wfcheck::check_well_formed
  16:     0x7fbc5d3c1bc7 - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  17:     0x7fbc5ce4d378 - rustc_query_impl[bdb42d22f02e134a]::execution::try_execute_query::<rustc_data_structures[6314a90323e5c320]::vec_cache::VecCache<rustc_span[d86c6dd34b0962f8]::def_id::LocalDefId, rustc_middle[8a940fbd8c5d50e6]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[8a940fbd8c5d50e6]::dep_graph::graph::DepNodeIndex>, true>
  18:     0x7fbc5ce4c9ba - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_well_formed::execute_query_incr::__rust_end_short_backtrace
  19:     0x7fbc5d3bdc29 - rustc_hir_analysis[1956eea595525479]::check::wfcheck::check_type_wf
  20:     0x7fbc5d3bdb39 - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7fbc5dfe80f1 - rustc_query_impl[bdb42d22f02e134a]::execution::try_execute_query::<rustc_middle[8a940fbd8c5d50e6]::query::caches::SingleCache<rustc_middle[8a940fbd8c5d50e6]::query::erase::ErasedData<[u8; 1usize]>>, true>
  22:     0x7fbc5dfe790b - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_type_wf::execute_query_incr::__rust_end_short_backtrace
  23:     0x7fbc5cebb469 - rustc_hir_analysis[1956eea595525479]::check_crate
  24:     0x7fbc5ceb6e33 - rustc_interface[6818d3a8678689ee]::passes::analysis
  25:     0x7fbc5dd66c35 - rustc_query_impl[bdb42d22f02e134a]::execution::try_execute_query::<rustc_middle[8a940fbd8c5d50e6]::query::caches::SingleCache<rustc_middle[8a940fbd8c5d50e6]::query::erase::ErasedData<[u8; 0usize]>>, true>
  26:     0x7fbc5dd665ea - rustc_query_impl[bdb42d22f02e134a]::query_impl::analysis::execute_query_incr::__rust_end_short_backtrace
  27:     0x7fbc5dd26f1b - rustc_interface[6818d3a8678689ee]::interface::run_compiler::<(), rustc_driver_impl[4e5b0da0f4005eeb]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7fbc5dd5407a - std[1e3c4ec04c5261a9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[6818d3a8678689ee]::util::run_in_thread_with_globals<rustc_interface[6818d3a8678689ee]::util::run_in_thread_pool_with_globals<rustc_interface[6818d3a8678689ee]::interface::run_compiler<(), rustc_driver_impl[4e5b0da0f4005eeb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x7fbc5dd5476d - <std[1e3c4ec04c5261a9]::thread::lifecycle::spawn_unchecked<rustc_interface[6818d3a8678689ee]::util::run_in_thread_with_globals<rustc_interface[6818d3a8678689ee]::util::run_in_thread_pool_with_globals<rustc_interface[6818d3a8678689ee]::interface::run_compiler<(), rustc_driver_impl[4e5b0da0f4005eeb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[37f591cfbe66b0b1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7fbc5dd5556c - <std[1e3c4ec04c5261a9]::sys::thread::unix::Thread>::new::thread_start
  31:     0x7fbc5729af30 - start_thread
  32:     0x7fbc5731ec2c - __clone3
  33:                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.97.1 (8bab26f4f 2026-07-14) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/lib.rs:9:1: 9:25>` is well-formed
#1 [check_type_wf] checking that types are well-formed
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: could not compile `fuckaround` (lib)

Caused by:
  process didn't exit successfully: `/home/wannie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name fuckaround --edition=2024 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=270 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=b197715107c73955 -C extra-filename=-01acd1037278aaa7 --out-dir /home/wannie/Desktop/fuckaround/target/debug/deps -C incremental=/home/wannie/Desktop/fuckaround/target/debug/incremental -L dependency=/home/wannie/Desktop/fuckaround/target/debug/deps --extern log=/home/wannie/Desktop/fuckaround/target/debug/deps/liblog-8994e55502ea410c.rmeta` (exit status: 101)

Backtrace

   Compiling fuckaround v0.1.0 (/home/wannie/Desktop/fuckaround)

thread 'rustc' (132770) panicked at /rustc-dev/8bab26f4f68e0e26f0bb7960be334d5b520ea452/compiler/rustc_hir_analysis/src/errors/remove_or_use_generic.rs:154:85:
expect_struct: found Item { owner_id: DefId(0:9 ~ fuckaround[d31c]::FooEnum), kind: Enum(FooEnum#0, Generics { params: [], predicates: [], has_where_clause_predicates: false, where_clause_span: src/lib.rs:11:17: 11:17 (#0), span: src/lib.rs:11:17: 11:17 (#0) }, EnumDef { variants: [Variant { ident: Var1#0, hir_id: HirId(DefId(0:9 ~ fuckaround[d31c]::FooEnum).1), def_id: DefId(0:10 ~ fuckaround[d31c]::FooEnum::Var1), data: Unit(HirId(DefId(0:9 ~ fuckaround[d31c]::FooEnum).2), DefId(0:11 ~ fuckaround[d31c]::FooEnum::Var1::{constructor#0})), disr_expr: None, span: src/lib.rs:12:5: 12:9 (#0) }] }), span: src/lib.rs:11:1: 13:2 (#0), vis_span: src/lib.rs:11:1: 11:4 (#0), has_delayed_lints: false, eii: false }
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rustc_hir::hir::expect_failed::<&rustc_hir::hir::Item>
   3: <rustc_hir::hir::Item>::expect_struct
   4: rustc_hir_analysis::errors::remove_or_use_generic::suggest_to_remove_or_use_generic
   5: rustc_hir_analysis::check::check::check_item_type
   6: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
   7: rustc_hir_analysis::check::wfcheck::check_type_wf
      [... omitted 1 frame ...]
   8: rustc_hir_analysis::check_crate
   9: rustc_interface::passes::analysis
  10: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, true>
  11: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.97.1 (8bab26f4f 2026-07-14) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/lib.rs:15:1: 15:25>` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `fuckaround`
end of query stack
error: could not compile `fuckaround` (lib)

Caused by:
  process didn't exit successfully: `/home/wannie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name fuckaround --edition=2024 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=270 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=b197715107c73955 -C extra-filename=-01acd1037278aaa7 --out-dir /home/wannie/Desktop/fuckaround/target/debug/deps -C incremental=/home/wannie/Desktop/fuckaround/target/debug/incremental -L dependency=/home/wannie/Desktop/fuckaround/target/debug/deps --extern log=/home/wannie/Desktop/fuckaround/target/debug/deps/liblog-8994e55502ea410c.rmeta` (exit status: 101)

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