about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDominik Stolz <d.stolz@tum.de>2024-11-28 17:33:22 +0100
committerDominik Stolz <d.stolz@tum.de>2024-11-30 21:00:31 +0100
commita6a693601937f3b0bf468a03ba4234832def38d1 (patch)
tree1f35457066bdc299e1b0033ac375bb236c7244c0
parentb73a71c6b4c31d303bf542066b79baad6f2a276a (diff)
downloadrust-a6a693601937f3b0bf468a03ba4234832def38d1.tar.gz
rust-a6a693601937f3b0bf468a03ba4234832def38d1.zip
Remove hir::ArrayLen, introduce ConstArgKind::Infer
Remove Node::ArrayLenInfer
-rw-r--r--clippy_lints/src/large_stack_arrays.rs6
-rw-r--r--clippy_lints/src/utils/author.rs12
-rw-r--r--clippy_lints/src/zero_repeat_side_effects.rs5
-rw-r--r--clippy_utils/src/hir_utils.rs30
-rw-r--r--clippy_utils/src/lib.rs6
-rw-r--r--tests/ui/author/repeat.stdout3
6 files changed, 21 insertions, 41 deletions
diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs
index 4ef881f11d5..46d7df6995a 100644
--- a/clippy_lints/src/large_stack_arrays.rs
+++ b/clippy_lints/src/large_stack_arrays.rs
@@ -5,7 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
 use clippy_utils::is_from_proc_macro;
 use clippy_utils::macros::macro_backtrace;
 use clippy_utils::source::snippet;
-use rustc_hir::{ArrayLen, Expr, ExprKind, Item, ItemKind, Node};
+use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::ty::layout::LayoutOf;
 use rustc_middle::ty::{self, ConstKind};
@@ -118,13 +118,13 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
 
 /// Only giving help messages if the expr does not contains macro expanded codes.
 fn might_be_expanded<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool {
-    /// Check if the span of `ArrayLen` of a repeat expression is within the expr's span,
+    /// Check if the span of `ConstArg` of a repeat expression is within the expr's span,
     /// if not, meaning this repeat expr is definitely from some proc-macro.
     ///
     /// This is a fail-safe to a case where even the `is_from_proc_macro` is unable to determain the
     /// correct result.
     fn repeat_expr_might_be_expanded(expr: &Expr<'_>) -> bool {
-        let ExprKind::Repeat(_, ArrayLen::Body(len_ct)) = expr.kind else {
+        let ExprKind::Repeat(_, len_ct) = expr.kind else {
             return false;
         };
         !expr.span.contains(len_ct.span())
diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs
index 1bf24083665..51001d374b4 100644
--- a/clippy_lints/src/utils/author.rs
+++ b/clippy_lints/src/utils/author.rs
@@ -3,7 +3,7 @@ use rustc_ast::LitIntType;
 use rustc_ast::ast::{LitFloatType, LitKind};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_hir::{
-    self as hir, ArrayLen, BindingMode, CaptureBy, Closure, ClosureKind, ConstArg, ConstArgKind, CoroutineKind,
+    self as hir, BindingMode, CaptureBy, Closure, ClosureKind, ConstArg, ConstArgKind, CoroutineKind,
     ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind,
 };
 use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -278,6 +278,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
                 chain!(self, "let ConstArgKind::Anon({anon_const}) = {const_arg}.kind");
                 self.body(field!(anon_const.body));
             },
+            ConstArgKind::Infer(..) => chain!(self, "let ConstArgKind::Infer(..) = {const_arg}.kind"),
         }
     }
 
@@ -611,14 +612,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
                 bind!(self, value, length);
                 kind!("Repeat({value}, {length})");
                 self.expr(value);
-                match length.value {
-                    ArrayLen::Infer(..) => chain!(self, "let ArrayLen::Infer(..) = length"),
-                    ArrayLen::Body(const_arg) => {
-                        bind!(self, const_arg);
-                        chain!(self, "let ArrayLen::Body({const_arg}) = {length}");
-                        self.const_arg(const_arg);
-                    },
-                }
+                self.const_arg(length);
             },
             ExprKind::Err(_) => kind!("Err(_)"),
             ExprKind::DropTemps(expr) => {
diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs
index fdc1d06e67a..05f85650769 100644
--- a/clippy_lints/src/zero_repeat_side_effects.rs
+++ b/clippy_lints/src/zero_repeat_side_effects.rs
@@ -5,7 +5,7 @@ use clippy_utils::visitors::for_each_expr_without_closures;
 use rustc_ast::LitKind;
 use rustc_data_structures::packed::Pu128;
 use rustc_errors::Applicability;
-use rustc_hir::{ArrayLen, ConstArgKind, ExprKind, Node};
+use rustc_hir::{ConstArgKind, ExprKind, Node};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::ty::Ty;
 use rustc_session::declare_lint_pass;
@@ -60,8 +60,7 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects {
         // doesn't seem as confusing as `[f(); 0]`. It would also have false positives when eg.
         // the const item depends on `#[cfg]s` and has different values in different compilation
         // sessions).
-        else if let ExprKind::Repeat(inner_expr, length) = expr.kind
-            && let ArrayLen::Body(const_arg) = length
+        else if let ExprKind::Repeat(inner_expr, const_arg) = expr.kind
             && let ConstArgKind::Anon(anon_const) = const_arg.kind
             && let length_expr = hir_map.body(anon_const.body).value
             && !length_expr.span.from_expansion()
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs
index ea866a78d87..920562f4b93 100644
--- a/clippy_utils/src/hir_utils.rs
+++ b/clippy_utils/src/hir_utils.rs
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHasher;
 use rustc_hir::MatchSource::TryDesugar;
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::{
-    ArrayLen, AssocItemConstraint, BinOpKind, BindingMode, Block, BodyId, Closure, ConstArg, ConstArgKind, Expr,
+    AssocItemConstraint, BinOpKind, BindingMode, Block, BodyId, Closure, ConstArg, ConstArgKind, Expr,
     ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime,
     LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitBoundModifiers, Ty,
     TyKind,
@@ -266,14 +266,6 @@ impl HirEqInterExpr<'_, '_, '_> {
         })
     }
 
-    pub fn eq_array_length(&mut self, left: ArrayLen<'_>, right: ArrayLen<'_>) -> bool {
-        match (left, right) {
-            (ArrayLen::Infer(..), ArrayLen::Infer(..)) => true,
-            (ArrayLen::Body(l_ct), ArrayLen::Body(r_ct)) => self.eq_const_arg(l_ct, r_ct),
-            (_, _) => false,
-        }
-    }
-
     pub fn eq_body(&mut self, left: BodyId, right: BodyId) -> bool {
         // swap out TypeckResults when hashing a body
         let old_maybe_typeck_results = self.inner.maybe_typeck_results.replace((
@@ -383,7 +375,7 @@ impl HirEqInterExpr<'_, '_, '_> {
             },
             (ExprKind::Path(l), ExprKind::Path(r)) => self.eq_qpath(l, r),
             (&ExprKind::Repeat(le, ll), &ExprKind::Repeat(re, rl)) => {
-                self.eq_expr(le, re) && self.eq_array_length(ll, rl)
+                self.eq_expr(le, re) && self.eq_const_arg(ll, rl)
             },
             (ExprKind::Ret(l), ExprKind::Ret(r)) => both(l.as_ref(), r.as_ref(), |l, r| self.eq_expr(l, r)),
             (&ExprKind::Struct(l_path, lf, ref lo), &ExprKind::Struct(r_path, rf, ref ro)) => {
@@ -469,8 +461,10 @@ impl HirEqInterExpr<'_, '_, '_> {
         match (&left.kind, &right.kind) {
             (ConstArgKind::Path(l_p), ConstArgKind::Path(r_p)) => self.eq_qpath(l_p, r_p),
             (ConstArgKind::Anon(l_an), ConstArgKind::Anon(r_an)) => self.eq_body(l_an.body, r_an.body),
+            (ConstArgKind::Infer(..), ConstArgKind::Infer(..)) => true,
             // Use explicit match for now since ConstArg is undergoing flux.
-            (ConstArgKind::Path(..), ConstArgKind::Anon(..)) | (ConstArgKind::Anon(..), ConstArgKind::Path(..)) => {
+            (ConstArgKind::Path(..), ConstArgKind::Anon(..)) | (ConstArgKind::Anon(..), ConstArgKind::Path(..))
+            | (ConstArgKind::Infer(..), _) | (_, ConstArgKind::Infer(..)) => {
                 false
             },
         }
@@ -589,7 +583,7 @@ impl HirEqInterExpr<'_, '_, '_> {
     pub fn eq_ty(&mut self, left: &Ty<'_>, right: &Ty<'_>) -> bool {
         match (&left.kind, &right.kind) {
             (&TyKind::Slice(l_vec), &TyKind::Slice(r_vec)) => self.eq_ty(l_vec, r_vec),
-            (&TyKind::Array(lt, ll), &TyKind::Array(rt, rl)) => self.eq_ty(lt, rt) && self.eq_array_length(ll, rl),
+            (&TyKind::Array(lt, ll), &TyKind::Array(rt, rl)) => self.eq_ty(lt, rt) && self.eq_const_arg(ll, rl),
             (TyKind::Ptr(l_mut), TyKind::Ptr(r_mut)) => l_mut.mutbl == r_mut.mutbl && self.eq_ty(l_mut.ty, r_mut.ty),
             (TyKind::Ref(_, l_rmut), TyKind::Ref(_, r_rmut)) => {
                 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(l_rmut.ty, r_rmut.ty)
@@ -1002,7 +996,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
             },
             ExprKind::Repeat(e, len) => {
                 self.hash_expr(e);
-                self.hash_array_length(len);
+                self.hash_const_arg(len);
             },
             ExprKind::Ret(ref e) => {
                 if let Some(e) = *e {
@@ -1195,7 +1189,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
             },
             &TyKind::Array(ty, len) => {
                 self.hash_ty(ty);
-                self.hash_array_length(len);
+                self.hash_const_arg(len);
             },
             TyKind::Pat(ty, pat) => {
                 self.hash_ty(ty);
@@ -1246,13 +1240,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
         }
     }
 
-    pub fn hash_array_length(&mut self, length: ArrayLen<'_>) {
-        match length {
-            ArrayLen::Infer(..) => {},
-            ArrayLen::Body(ct) => self.hash_const_arg(ct),
-        }
-    }
-
     pub fn hash_body(&mut self, body_id: BodyId) {
         // swap out TypeckResults when hashing a body
         let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id));
@@ -1264,6 +1251,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
         match &const_arg.kind {
             ConstArgKind::Path(path) => self.hash_qpath(path),
             ConstArgKind::Anon(anon) => self.hash_body(anon.body),
+            ConstArgKind::Infer(..) => {},
         }
     }
 
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 6408cc938cb..82699211489 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -102,7 +102,7 @@ use rustc_hir::definitions::{DefPath, DefPathData};
 use rustc_hir::hir_id::{HirIdMap, HirIdSet};
 use rustc_hir::intravisit::{FnKind, Visitor, walk_expr};
 use rustc_hir::{
-    self as hir, Arm, ArrayLen, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, ConstContext,
+    self as hir, Arm, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, ConstContext,
     Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind,
     ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, OwnerNode, Param, Pat,
     PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef,
@@ -921,7 +921,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
             _ => false,
         },
         ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)),
-        ExprKind::Repeat(x, ArrayLen::Body(len)) => {
+        ExprKind::Repeat(x, len) => {
             if let ConstArgKind::Anon(anon_const) = len.kind
                 && let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind
                 && let LitKind::Int(v, _) = const_lit.node
@@ -951,7 +951,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: &
                 ..
             }) => return sym.is_empty() && is_path_lang_item(cx, ty, LangItem::String),
             ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec),
-            ExprKind::Repeat(_, ArrayLen::Body(len)) => {
+            ExprKind::Repeat(_, len) => {
                 if let ConstArgKind::Anon(anon_const) = len.kind
                     && let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind
                     && let LitKind::Int(v, _) = const_lit.node
diff --git a/tests/ui/author/repeat.stdout b/tests/ui/author/repeat.stdout
index d9e3f864f12..1a608734ada 100644
--- a/tests/ui/author/repeat.stdout
+++ b/tests/ui/author/repeat.stdout
@@ -1,8 +1,7 @@
 if let ExprKind::Repeat(value, length) = expr.kind
     && let ExprKind::Lit(ref lit) = value.kind
     && let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node
-    && let ArrayLen::Body(const_arg) = length
-    && let ConstArgKind::Anon(anon_const) = const_arg.kind
+    && let ConstArgKind::Anon(anon_const) = length.kind
     && expr1 = &cx.tcx.hir().body(anon_const.body).value
     && let ExprKind::Lit(ref lit1) = expr1.kind
     && let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node