Skip to content

[ICE]: unexpected divergence state in checking array #153695

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024
#![feature(never_patterns)]

fn main() {
    let _ = Some({
        return;
    }).map(|!| [1]);
}

original:

#![feature(never_patterns)]
#![allow(incomplete_features)]

enum Never {}

fn example(x: Never) -> [i32; 1] {
    let ! = x;
    [1]
}

fn function_param_never(!: Never) -> [i32; 1] {
    [1]
}

fn generic_never<T>() -> [i32; 1] //~ ERROR mismatched types
where
    T: Copy,
{
    [1]
}

fn main() {
    let _ = Some({
        return;
    }).map(|!| [1]); //~ ERROR mismatched types
}

Version information

rustc 1.96.0-nightly (d1c79458b 2026-03-11)
binary: rustc
commit-hash: d1c79458b5d13bd0179d7dbafd5ca4ea9ae3e6aa
commit-date: 2026-03-11
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2024

Program output

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

warning: unreachable call
 --> /tmp/icemaker_global_tempdir.zIXMeoRY2OPf/rustc_testrunner_tmpdir_reporting.7f1nmVtf4Ttb/mvce.rs:4:13
  |
4 |     let _ = Some({
  |             ^^^^ unreachable call
5 |         return;
  |         ------ any code following this expression is unreachable
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

warning: unreachable expression
 --> /tmp/icemaker_global_tempdir.zIXMeoRY2OPf/rustc_testrunner_tmpdir_reporting.7f1nmVtf4Ttb/mvce.rs:6:17
  |
6 |     }).map(|!| [1]);
  |             -   ^ unreachable expression
  |             |
  |             any code following a never pattern is unreachable

warning: 3 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: unexpected divergence state in checking array
 --> /tmp/icemaker_global_tempdir.zIXMeoRY2OPf/rustc_testrunner_tmpdir_reporting.7f1nmVtf4Ttb/mvce.rs:6:16
  |
6 |     }).map(|!| [1]);
  |                ^^^
  |
note: delayed at /rustc-dev/d1c79458b5d13bd0179d7dbafd5ca4ea9ae3e6aa/compiler/rustc_hir_typeck/src/expr.rs:1668:22
         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::diagnostic::Diag>::delay_as_bug
         4: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_array
         5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
         6: rustc_hir_typeck::check::check_fn
         7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_closure
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
         9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_method_call
        10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_decl
        12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
        13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        14: rustc_hir_typeck::check::check_fn
        15: rustc_hir_typeck::typeck_with_inspect::{closure#0}
        16: rustc_query_impl::query_impl::typeck::invoke_provider_fn::__rust_begin_short_backtrace
        17: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        18: rustc_query_impl::query_impl::typeck::execute_query_non_incr::__rust_end_short_backtrace
        19: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
        20: rustc_hir_analysis::check_crate
        21: rustc_interface::passes::analysis
        22: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
        23: rustc_query_impl::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
        24: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        25: 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}, ()>
        26: <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}
        27: <std::sys::thread::unix::Thread>::new::thread_start
        28: <unknown>
        29: <unknown>
      
 --> /tmp/icemaker_global_tempdir.zIXMeoRY2OPf/rustc_testrunner_tmpdir_reporting.7f1nmVtf4Ttb/mvce.rs:6:16
  |
6 |     }).map(|!| [1]);
  |                ^^^

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.96.0-nightly (d1c79458b 2026-03-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@rustbot label +F-never_patterns

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-never_patterns`#![feature(never_patterns)]`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