From 71d4ef88c61ab0f4673589bb4d19e96c76f89560 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Sep 2026 09:30:29 +1000 Subject: [PATCH] Remove unused `StashKey::UnderscoreForArrayLengths` It's no longer ever used for stashing, so the code looking for it is dead. It became dead in PR 141610 when `generic_arg_infer` was stabilized and `[T; _]` became valid. --- compiler/rustc_errors/src/lib.rs | 1 - compiler/rustc_hir_typeck/src/expr.rs | 29 --------------------------- 2 files changed, 30 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68e10802e21c5..25a82b22707cc 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -375,7 +375,6 @@ struct DiagCtxtInner { #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum StashKey { ItemNoType, - UnderscoreForArrayLengths, EarlySyntaxWarning, CallIntoMethod, /// When an invalid lifetime e.g. `'2` should be reinterpreted diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 04e55dd0fdd95..8944d6a47488a 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1702,34 +1702,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.next_ty_var(expr.span) }; let array_len = args.len() as u64; - self.suggest_array_len(expr, array_len); Ty::new_array(self.tcx, element_ty, array_len) } - fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) { - let parent_node = self.tcx.hir_parent_iter(expr.hir_id).find(|(_, node)| { - !matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. })) - }); - let Some((_, hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }))) = parent_node else { - return; - }; - if let hir::TyKind::Array(_, ct) = ty.peel_refs().kind { - let span = ct.span; - self.dcx().try_steal_modify_and_emit_err( - span, - StashKey::UnderscoreForArrayLengths, - |err| { - err.span_suggestion_verbose( - span, - "consider specifying the array length", - array_len, - Applicability::MaybeIncorrect, - ); - }, - ); - } - } - pub(super) fn check_expr_const_block( &self, block: &'tcx hir::ConstBlock, @@ -1764,10 +1739,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ), ); - if let Some(count) = count.try_to_target_usize(tcx) { - self.suggest_array_len(expr, count); - } - let uty = match expected { ExpectHasType(uty) => uty.builtin_index(), _ => None,