about summary refs log tree commit diff
path: root/clippy_lints/src/slow_vector_initialization.rs
diff options
context:
space:
mode:
authorAndre Bogus <bogusandre@gmail.com>2022-10-01 17:55:22 +0200
committerAndre Bogus <bogusandre@gmail.com>2022-10-01 17:55:22 +0200
commiteef5d477b59a3b68bca9c1f3a5334229fc0ad9b6 (patch)
treef1cfc21aafc91ce54efedc84f27b0476904e1c39 /clippy_lints/src/slow_vector_initialization.rs
parent31b17411a6cd5c4b36cde6ff008de1d3ec128ac4 (diff)
downloadrust-eef5d477b59a3b68bca9c1f3a5334229fc0ad9b6.tar.gz
rust-eef5d477b59a3b68bca9c1f3a5334229fc0ad9b6.zip
use `is_integer_literal` more
Diffstat (limited to 'clippy_lints/src/slow_vector_initialization.rs')
-rw-r--r--clippy_lints/src/slow_vector_initialization.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs
index e57ab8cd7a3..6e5d88e1b59 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_expr_path_def_path, is_integer_literal, path_to_local, path_to_local_id, paths, 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};
@@ -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));
@@ -255,9 +255,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
         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_integer_literal(repeat_arg, 0);
             then {
                 true
             } else {