diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-05-26 10:38:02 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-05-28 10:03:01 +0000 |
| commit | 013ab6cdb116a4c194ef5ed5fdeda55e68d49fe7 (patch) | |
| tree | e72116ad86c102162033fc4122fbff41b8e9cdaf | |
| parent | ce0adf08c9c08a770fa65c98cdb59335d4acee3d (diff) | |
| download | rust-013ab6cdb116a4c194ef5ed5fdeda55e68d49fe7.tar.gz rust-013ab6cdb116a4c194ef5ed5fdeda55e68d49fe7.zip | |
Use `builin_index` instead of hand-rolling it
| -rw-r--r-- | clippy_lints/src/index_refutable_slice.rs | 5 | ||||
| -rw-r--r-- | clippy_lints/src/tuple_array_conversions.rs | 4 | ||||
| -rw-r--r-- | clippy_utils/src/consts.rs | 4 |
3 files changed, 5 insertions, 8 deletions
diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 0b1cae30ca5..3d131a7825a 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -12,7 +12,6 @@ use rustc_hir::HirId; use rustc_hir::intravisit::{self, Visitor}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; -use rustc_middle::ty; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::symbol::Ident; @@ -109,11 +108,11 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<Hir } let bound_ty = cx.typeck_results().node_type(pat.hir_id); - if let ty::Slice(inner_ty) | ty::Array(inner_ty, _) = bound_ty.peel_refs().kind() { + if let Some(inner_ty) = bound_ty.peel_refs().builtin_index() { // The values need to use the `ref` keyword if they can't be copied. // This will need to be adjusted if the lint want to support mutable access in the future let src_is_ref = bound_ty.is_ref() && by_ref == hir::ByRef::No; - let needs_ref = !(src_is_ref || is_copy(cx, *inner_ty)); + let needs_ref = !(src_is_ref || is_copy(cx, inner_ty)); let slice_info = slices .entry(value_hir_id) diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 95ce19975c7..3c21d194b81 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -66,7 +66,7 @@ impl LateLintPass<'_> for TupleArrayConversions { } fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: &'tcx [Expr<'tcx>]) { - let (ty::Array(ty, _) | ty::Slice(ty)) = cx.typeck_results().expr_ty(expr).kind() else { + let Some(ty) = cx.typeck_results().expr_ty(expr).builtin_index() else { unreachable!("`expr` must be an array or slice due to `ExprKind::Array`"); }; @@ -85,7 +85,7 @@ fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: & ExprKind::Path(_) => Some(elements.iter().collect()), _ => None, }) - && all_bindings_are_for_conv(cx, &[*ty], expr, elements, &locals, ToType::Array) + && all_bindings_are_for_conv(cx, &[ty], expr, elements, &locals, ToType::Array) && !is_from_proc_macro(cx, expr) { span_lint_and_help( diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 6f5b0ec54cd..1ec5d11384f 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -235,9 +235,7 @@ impl Constant<'_> { _ => None, }, (Self::Vec(l), Self::Vec(r)) => { - let (ty::Array(cmp_type, _) | ty::Slice(cmp_type)) = *cmp_type.kind() else { - return None; - }; + let cmp_type = cmp_type.builtin_index()?; iter::zip(l, r) .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri)) .find(|r| r.is_none_or(|o| o != Ordering::Equal)) |
