rustc panics when compiling the following very reduced code. If the enum is replaced by a struct, the compiler does not panic anymore, but gives the correct compilation error about unconstrained lifetime parameter <'s>.
Using nightly (1.99.0-nightly), the compiler correctly gives compile errors about unconstrained lifetime parameter <'s>.
Code
pub enum SqlExpression {
}
pub struct SqlExpressionVisitor<'s> {
stack: Vec<&'s SqlExpression>,
}
impl<'s> Iterator for SqlExpressionVisitor<'s> {
type Item = &'s SqlExpression;
fn next(&mut self) -> Option<Self::Item> {
None
}
}
impl<'s> IntoIterator for SqlExpression {
type Item = &'s SqlExpression;
type IntoIter = SqlExpressionVisitor<'s>;
fn into_iter(self) -> Self::IntoIter {
SqlExpressionVisitor {
stack: vec![&self],
}
}
}
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
RUST_BACKTRACE=full cargo check
Checking test-case v0.1.0 (/home/user/src/rust/test-case)
thread 'rustc' (1938295) 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:3 ~ test_case[3bec]::SqlExpression), kind: Enum(SqlExpression#0, Generics { params: [], predicates: [], has_where_clause_predicates: false, where_clause_span: src/lib.rs:2:23: 2:23 (#0), span: src/lib.rs:2:23: 2:23 (#0) }, EnumDef { variants: [] }), span: src/lib.rs:2:1: 3:2 (#0), vis_span: src/lib.rs:2:1: 2:4 (#0), has_delayed_lints: false, eii: false }
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] -C linker=clang -C link-arg=-fuse-ld=/usr/bin/mold
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:17:1: 17:40>` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `test_case`
end of query stack
error: could not compile `test-case` (lib)
Caused by:
process didn't exit successfully: `/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name test_case --edition=2024 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=421 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=283bea0832b02288 -C extra-filename=-2a38357995ddfbfd --out-dir /home/user/src/rust/test-case/target/debug/deps -C incremental=/home/user/src/rust/test-case/target/debug/incremental -L dependency=/home/user/src/rust/test-case/target/debug/deps -C linker=clang -C link-arg=-fuse-ld=/usr/bin/mold` (exit status: 101)
Backtrace
stack backtrace:
0: 0x7f80962901f9 - <<std[1e3c4ec04c5261a9]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[37f591cfbe66b0b1]::fmt::Display>::fmt
1: 0x7f8096a20cc8 - core[37f591cfbe66b0b1]::fmt::write
2: 0x7f8097e0d936 - <std[1e3c4ec04c5261a9]::sys::stdio::unix::Stderr as std[1e3c4ec04c5261a9]::io::Write>::write_fmt
3: 0x7f80962663fe - std[1e3c4ec04c5261a9]::panicking::default_hook::{closure#0}
4: 0x7f8096283b33 - std[1e3c4ec04c5261a9]::panicking::default_hook
5: 0x7f8095076c31 - std[1e3c4ec04c5261a9]::panicking::update_hook::<alloc[24b8200b0946867]::boxed::Box<rustc_driver_impl[4e5b0da0f4005eeb]::install_ice_hook::{closure#1}>>::{closure#0}
6: 0x7f8096283e12 - std[1e3c4ec04c5261a9]::panicking::panic_with_hook
7: 0x7f80962664c2 - std[1e3c4ec04c5261a9]::panicking::panic_handler::{closure#0}
8: 0x7f809625a9a9 - std[1e3c4ec04c5261a9]::sys::backtrace::__rust_end_short_backtrace::<std[1e3c4ec04c5261a9]::panicking::panic_handler::{closure#0}, !>
9: 0x7f8096267f2d - __rustc[6ef78fba13ac776c]::rust_begin_unwind
10: 0x7f8092d192dc - core[37f591cfbe66b0b1]::panicking::panic_fmt
11: 0x7f8095133a08 - rustc_hir[ffb6a75957ec3d1e]::hir::expect_failed::<&rustc_hir[ffb6a75957ec3d1e]::hir::Item>
12: 0x7f8095135b8e - <rustc_hir[ffb6a75957ec3d1e]::hir::Item>::expect_struct
13: 0x7f8093915145 - rustc_hir_analysis[1956eea595525479]::errors::remove_or_use_generic::suggest_to_remove_or_use_generic
14: 0x7f80971cc961 - rustc_hir_analysis[1956eea595525479]::check::check::check_item_type
15: 0x7f80971c1be6 - rustc_hir_analysis[1956eea595525479]::check::wfcheck::check_well_formed
16: 0x7f80971c1bc7 - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
17: 0x7f8096c4d378 - 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: 0x7f8096c4c9ba - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_well_formed::execute_query_incr::__rust_end_short_backtrace
19: 0x7f80971bdc29 - rustc_hir_analysis[1956eea595525479]::check::wfcheck::check_type_wf
20: 0x7f80971bdb39 - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
21: 0x7f8097de80f1 - rustc_query_impl[bdb42d22f02e134a]::execution::try_execute_query::<rustc_middle[8a940fbd8c5d50e6]::query::caches::SingleCache<rustc_middle[8a940fbd8c5d50e6]::query::erase::ErasedData<[u8; 1usize]>>, true>
22: 0x7f8097de790b - rustc_query_impl[bdb42d22f02e134a]::query_impl::check_type_wf::execute_query_incr::__rust_end_short_backtrace
23: 0x7f8096cbb469 - rustc_hir_analysis[1956eea595525479]::check_crate
24: 0x7f8096cb6e33 - rustc_interface[6818d3a8678689ee]::passes::analysis
25: 0x7f8097b66c35 - rustc_query_impl[bdb42d22f02e134a]::execution::try_execute_query::<rustc_middle[8a940fbd8c5d50e6]::query::caches::SingleCache<rustc_middle[8a940fbd8c5d50e6]::query::erase::ErasedData<[u8; 0usize]>>, true>
26: 0x7f8097b665ea - rustc_query_impl[bdb42d22f02e134a]::query_impl::analysis::execute_query_incr::__rust_end_short_backtrace
27: 0x7f8097b26f1b - rustc_interface[6818d3a8678689ee]::interface::run_compiler::<(), rustc_driver_impl[4e5b0da0f4005eeb]::run_compiler::{closure#0}>::{closure#1}
28: 0x7f8097b5407a - 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: 0x7f8097b5476d - <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: 0x7f8097b5556c - <std[1e3c4ec04c5261a9]::sys::thread::unix::Thread>::new::thread_start
31: 0x7f80910a407a - start_thread
at ./nptl/pthread_create.c:454:8
32: 0x7f809113772c - __GI___clone3
at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
33: 0x0 - <unknown>
rustc panics when compiling the following very reduced code. If the enum is replaced by a struct, the compiler does not panic anymore, but gives the correct compilation error about unconstrained lifetime parameter <'s>.
Using nightly (1.99.0-nightly), the compiler correctly gives compile errors about unconstrained lifetime parameter <'s>.
Code
Meta
rustc --version --verbose:Error output
Backtrace