Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading