rust-lang / rust-lang/rust

ICE `None` in compiler/rustc_middle/src/ty/sty.rs

Open
#150,049 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-inherent_associated_types F-min_generic_const_args I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

original:

#![feature(min_generic_const_args)]
#![feature(inherent_associated_types)]
struct Foo<'a> {
    x: &'a (),
}

impl<'a> Foo<'a> {
    fn foo(_: [u8; Foo::X]) { std::mem::transmute([4]) }
}

fn main() {}

Version information

rustc 1.94.0-nightly (cec70080f 2025-12-15)
binary: rustc
commit-hash: cec70080fd441d16e9fb08a0d1d1a04c72d1ed25
commit-date: 2025-12-15
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

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

Program output

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/crash.rs:1:12
  |
1 | #![feature(min_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `inherent_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/crash.rs:2:12
  |
2 | #![feature(inherent_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information

warning: struct `Foo` is never constructed
 --> /tmp/crash.rs:3:8
  |
3 | struct Foo<'a> {
  |        ^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: associated function `foo` is never used
 --> /tmp/crash.rs:8:8
  |
7 | impl<'a> Foo<'a> {
  | ---------------- associated function in this implementation
8 |     fn foo(_: [u8; Foo::X]) { std::mem::transmute([4]) }
  |        ^^^


thread 'rustc' (2084098) panicked at compiler/rustc_middle/src/ty/sty.rs:2104:27:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f5d57d8a253 - <<std[5ec89fed4875b12f]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[26a7a51be8c9f870]::fmt::Display>::fmt
   1:     0x7f5d58410708 - core[26a7a51be8c9f870]::fmt::write
   2:     0x7f5d57da08a6 - <std[5ec89fed4875b12f]::sys::stdio::unix::Stderr as std[5ec89fed4875b12f]::io::Write>::write_fmt
   3:     0x7f5d57d60a18 - std[5ec89fed4875b12f]::panicking::default_hook::{closure#0}
   4:     0x7f5d57d7e123 - std[5ec89fed4875b12f]::panicking::default_hook
   5:     0x7f5d56d6ffb7 - std[5ec89fed4875b12f]::panicking::update_hook::<alloc[673ccbb8a4c5d329]::boxed::Box<rustc_driver_impl[50f6efb3f18c5e4b]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f5d57d7e402 - std[5ec89fed4875b12f]::panicking::panic_with_hook
   7:     0x7f5d57d60b0a - std[5ec89fed4875b12f]::panicking::panic_handler::{closure#0}
   8:     0x7f5d57d55389 - std[5ec89fed4875b12f]::sys::backtrace::__rust_end_short_backtrace::<std[5ec89fed4875b12f]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f5d57d6268d - __rustc[c625ac833ac53d73]::rust_begin_unwind
  10:     0x7f5d5523924c - core[26a7a51be8c9f870]::panicking::panic_fmt
  11:     0x7f5d54574782 - core[26a7a51be8c9f870]::panicking::panic
  12:     0x7f5d54e72f19 - core[26a7a51be8c9f870]::option::unwrap_failed
  13:     0x7f5d58db31d4 - <rustc_lint[87c3c4e0ddf52cb1]::BuiltinCombinedModuleLateLintPass as rustc_lint[87c3c4e0ddf52cb1]::passes::LateLintPass>::check_expr
  14:     0x7f5d58d826a6 - <rustc_lint[87c3c4e0ddf52cb1]::late::LateContextAndPass<rustc_lint[87c3c4e0ddf52cb1]::BuiltinCombinedModuleLateLintPass> as rustc_hir[6a9da475a5f9b785]::intravisit::Visitor>::visit_expr
  15:     0x7f5d58d82b1b - <rustc_lint[87c3c4e0ddf52cb1]::late::LateContextAndPass<rustc_lint[87c3c4e0ddf52cb1]::BuiltinCombinedModuleLateLintPass> as rustc_hir[6a9da475a5f9b785]::intravisit::Visitor>::visit_expr
  16:     0x7f5d58d817f2 - <rustc_lint[87c3c4e0ddf52cb1]::late::LateContextAndPass<rustc_lint[87c3c4e0ddf52cb1]::BuiltinCombinedModuleLateLintPass> as rustc_hir[6a9da475a5f9b785]::intravisit::Visitor>::visit_block
  17:     0x7f5d58d90a8d - <rustc_lint[87c3c4e0ddf52cb1]::late::LateContextAndPass<rustc_lint[87c3c4e0ddf52cb1]::BuiltinCombinedModuleLateLintPass> as rustc_hir[6a9da475a5f9b785]::intravisit::Visitor>::visit_nested_body
  18:     0x7f5d58d8aa15 - <rustc_lint[87c3c4e0ddf52cb1]::late::LateContextAndPass<rustc_lint[87c3c4e0ddf52cb1]::BuiltinCombinedModuleLateLintPass> as rustc_hir[6a9da475a5f9b785]::intravisit::Visitor>::visit_nested_item
  19:     0x7f5d58d88da2 - rustc_lint[87c3c4e0ddf52cb1]::lint_mod
  20:     0x7f5d58d88957 - rustc_query_impl[27139b72c8912d2b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[27139b72c8912d2b]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d117b0519601dc6]::query::erase::Erased<[u8; 0usize]>>
  21:     0x7f5d591b8031 - rustc_query_system[5d3859f1d59bc7f3]::query::plumbing::try_execute_query::<rustc_query_impl[27139b72c8912d2b]::DynamicConfig<rustc_query_system[5d3859f1d59bc7f3]::query::caches::DefaultCache<rustc_span[ae684922c33956fd]::def_id::LocalModDefId, rustc_middle[7d117b0519601dc6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[27139b72c8912d2b]::plumbing::QueryCtxt, false>
  22:     0x7f5d591b41fd - rustc_query_impl[27139b72c8912d2b]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7f5d591b3d90 - rustc_lint[87c3c4e0ddf52cb1]::late::check_crate::{closure#1}
  24:     0x7f5d591b397a - rustc_lint[87c3c4e0ddf52cb1]::late::check_crate
  25:     0x7f5d586aa10e - rustc_interface[b41716356610a9ea]::passes::analysis
  26:     0x7f5d586a9825 - rustc_query_impl[27139b72c8912d2b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[27139b72c8912d2b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d117b0519601dc6]::query::erase::Erased<[u8; 0usize]>>
  27:     0x7f5d595b1526 - rustc_query_system[5d3859f1d59bc7f3]::query::plumbing::try_execute_query::<rustc_query_impl[27139b72c8912d2b]::DynamicConfig<rustc_query_system[5d3859f1d59bc7f3]::query::caches::SingleCache<rustc_middle[7d117b0519601dc6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[27139b72c8912d2b]::plumbing::QueryCtxt, false>
  28:     0x7f5d595b10f6 - rustc_query_impl[27139b72c8912d2b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f5d5975fc51 - <rustc_interface[b41716356610a9ea]::passes::create_and_enter_global_ctxt<core[26a7a51be8c9f870]::option::Option<rustc_interface[b41716356610a9ea]::queries::Linker>, rustc_driver_impl[50f6efb3f18c5e4b]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[26a7a51be8c9f870]::ops::function::FnOnce<(&rustc_session[276d18328e744fa4]::session::Session, rustc_middle[7d117b0519601dc6]::ty::context::CurrentGcx, alloc[673ccbb8a4c5d329]::sync::Arc<rustc_data_structures[32d4a3d751e78af5]::jobserver::Proxy>, &std[5ec89fed4875b12f]::sync::once_lock::OnceLock<rustc_middle[7d117b0519601dc6]::ty::context::GlobalCtxt>, &rustc_data_structures[32d4a3d751e78af5]::sync::worker_local::WorkerLocal<rustc_middle[7d117b0519601dc6]::arena::Arena>, &rustc_data_structures[32d4a3d751e78af5]::sync::worker_local::WorkerLocal<rustc_hir[6a9da475a5f9b785]::Arena>, rustc_driver_impl[50f6efb3f18c5e4b]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  30:     0x7f5d595ed2da - rustc_interface[b41716356610a9ea]::interface::run_compiler::<(), rustc_driver_impl[50f6efb3f18c5e4b]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7f5d5955f7ce - std[5ec89fed4875b12f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b41716356610a9ea]::util::run_in_thread_with_globals<rustc_interface[b41716356610a9ea]::util::run_in_thread_pool_with_globals<rustc_interface[b41716356610a9ea]::interface::run_compiler<(), rustc_driver_impl[50f6efb3f18c5e4b]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x7f5d5955f5a0 - <std[5ec89fed4875b12f]::thread::lifecycle::spawn_unchecked<rustc_interface[b41716356610a9ea]::util::run_in_thread_with_globals<rustc_interface[b41716356610a9ea]::util::run_in_thread_pool_with_globals<rustc_interface[b41716356610a9ea]::interface::run_compiler<(), rustc_driver_impl[50f6efb3f18c5e4b]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[26a7a51be8c9f870]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f5d5955d978 - <std[5ec89fed4875b12f]::sys::thread::unix::Thread>::new::thread_start
  34:     0x7f5d52e969cb - <unknown>
  35:     0x7f5d52f1aa0c - <unknown>
  36:                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: please attach the file at `/tmp/im/rustc-ice-2025-12-16T06_24_54-2084080.txt` to your bug report

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on crate `crash`
end of query stack
warning: 4 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: unelided lifetime in signature
 --> /tmp/crash.rs:8:20
  |
8 |     fn foo(_: [u8; Foo::X]) { std::mem::transmute([4]) }
  |                    ^^^
  |
note: delayed at compiler/rustc_hir_analysis/src/collect.rs:334:13
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <rustc_hir_analysis::collect::ItemCtxt as rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::re_infer
         5: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_resolved_ty_path
         6: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty::{closure#0}
         7: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_const_arg
         8: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty::{closure#0}
         9: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_fn_ty
        10: rustc_hir_analysis::collect::lower_fn_sig_recovering_infer_ret_ty
        11: rustc_hir_analysis::collect::fn_sig
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::fn_sig::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 24]>>
        13: <rustc_query_impl::query_impl::fn_sig::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
        14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        15: rustc_query_impl::query_impl::fn_sig::get_query_non_incr::__rust_end_short_backtrace
        16: <rustc_hir_analysis::variance::constraints::ConstraintContext>::build_constraints_for_item
        17: rustc_hir_analysis::variance::crate_variances
        18: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::crate_variances::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        20: rustc_query_impl::query_impl::crate_variances::get_query_non_incr::__rust_end_short_backtrace
        21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::variances_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>.warm
        22: <rustc_query_impl::query_impl::variances_of::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
        23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 16]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        24: rustc_query_impl::query_impl::variances_of::get_query_non_incr::__rust_end_short_backtrace
        25: rustc_hir_analysis::check::wfcheck::check_variances_for_type_defn
        26: rustc_hir_analysis::check::check::check_item_type
        27: rustc_hir_analysis::check::wfcheck::check_well_formed
        28: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        29: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 1]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        30: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
        31: rustc_hir_analysis::check::wfcheck::check_type_wf
        32: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        33: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        34: rustc_query_impl::query_impl::check_type_wf::get_query_non_incr::__rust_end_short_backtrace
        35: rustc_hir_analysis::check_crate
        36: rustc_interface::passes::analysis
        37: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        38: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        39: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        40: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
        41: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        42: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        43: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        44: <std::sys::thread::unix::Thread>::new::thread_start
        45: <unknown>
        46: <unknown>

 --> /tmp/crash.rs:8:20
  |
8 |     fn foo(_: [u8; Foo::X]) { std::mem::transmute([4]) }
  |                    ^^^

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: please attach the file at `/tmp/im/rustc-ice-2025-12-16T06_24_54-2084080.txt` to your bug report

query stack during panic:
end of query stack

@rustbot label +F-min_generic_const_args +F-inherent_associated_types

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the provided generic-const and inherent-associated-type example using rustc. Start at compiler/rustc_middle/src/ty/sty.rs:2104 and inspect the related delayed diagnostic in compiler/rustc_hir_analysis/src/collect.rs:334. Done means this input produces a controlled compiler diagnostic without panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.