about summary refs log tree commit diff
path: root/clippy_lints/src/slow_vector_initialization.rs
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2022-10-06 09:19:29 +0200
committerPhilipp Krones <hello@philkrones.com>2022-10-06 09:19:29 +0200
commite2808afd60ea0f0e17c3aced354adfd58a1f825f (patch)
tree3d9bcb2d75f4de029f4720c7c5462cd7e09fcf0d /clippy_lints/src/slow_vector_initialization.rs
parentda16cc1da9814710e637ff242b71768a4d3724b7 (diff)
parent887ba0c5a489e28b55ff84244e1dc153861d16ad (diff)
Merge remote-tracking branch 'upstream/master' into rustup
Diffstat (limited to 'clippy_lints/src/slow_vector_initialization.rs')
-rw-r--r--clippy_lints/src/slow_vector_initialization.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs
index c07aa00a127..76039923151 100644
--- a/clippy_lints/src/slow_vector_initialization.rs
+++ b/clippy_lints/src/slow_vector_initialization.rs
@@ -1,9 +1,10 @@
 use clippy_utils::diagnostics::span_lint_and_then;
 use clippy_utils::sugg::Sugg;
 use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{get_enclosing_block, is_expr_path_def_path, path_to_local, path_to_local_id, paths, SpanlessEq};
+use clippy_utils::{
+    get_enclosing_block, is_integer_literal, is_path_diagnostic_item, path_to_local, path_to_local_id, SpanlessEq,
+};
 use if_chain::if_chain;
-use rustc_ast::ast::LitKind;
 use rustc_errors::Applicability;
 use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, Visitor};
 use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, QPath, Stmt, StmtKind};
@@ -174,7 +175,7 @@ impl SlowVectorInit {
             diag.span_suggestion(
                 vec_alloc.allocation_expr.span,
                 "consider replace allocation with",
-                format!("vec![0; {}]", len_expr),
+                format!("vec![0; {len_expr}]"),
                 Applicability::Unspecified,
             );
         });
@@ -219,8 +220,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
             && path_to_local_id(self_arg, self.vec_alloc.local_id)
             && path.ident.name == sym!(resize)
             // Check that is filled with 0
-            && let ExprKind::Lit(ref lit) = fill_arg.kind
-            && let LitKind::Int(0, _) = lit.node {
+            && is_integer_literal(fill_arg, 0) {
                 // Check that len expression is equals to `with_capacity` expression
                 if SpanlessEq::new(self.cx).eq_expr(len_arg, self.vec_alloc.len_expr) {
                     self.slow_expression = Some(InitializationType::Resize(expr));
@@ -254,10 +254,8 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
     fn is_repeat_zero(&self, expr: &Expr<'_>) -> bool {
         if_chain! {
             if let ExprKind::Call(fn_expr, [repeat_arg]) = expr.kind;
-            if is_expr_path_def_path(self.cx, fn_expr, &paths::ITER_REPEAT);
-            if let ExprKind::Lit(ref lit) = repeat_arg.kind;
-            if let LitKind::Int(0, _) = lit.node;
-
+            if is_path_diagnostic_item(self.cx, fn_expr, sym::iter_repeat);
+            if is_integer_literal(repeat_arg, 0);
             then {
                 true
             } else {