Rollup merge of #154031 - TaKO8Ki:fix-153695-never-pattern-array-ice, r=chenyukang

Remove divergence check from check_expr_array

Fixes rust-lang/rust#153695.

`check_expr_array` currently assumes it should only be entered with` self.diverges == Diverges::Maybe`, but that assumption does not appear to hold in all valid cases. A never-pattern parameter can seed a function or closure body with inherited `Diverges::Always`, and exprs in that body are still typecked.
This commit is contained in:
Jacob Pratt
2026-03-27 02:30:06 -04:00
committed by GitHub
2 changed files with 13 additions and 8 deletions
-8
View File
@@ -1660,14 +1660,6 @@ fn check_expr_array(
expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> {
let element_ty = if !args.is_empty() {
// This shouldn't happen unless there's another error
// (e.g., never patterns in inappropriate contexts).
if self.diverges.get() != Diverges::Maybe {
self.dcx()
.struct_span_err(expr.span, "unexpected divergence state in checking array")
.delay_as_bug();
}
let coerce_to = expected
.to_option(self)
.and_then(|uty| {
@@ -0,0 +1,13 @@
//@ check-pass
//@ edition: 2024
#![feature(never_patterns)]
#![allow(incomplete_features)]
#![allow(unreachable_code)]
fn main() {
let _ = Some({
return;
})
.map(|!| [1]);
}