]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/uninit_vec.rs
Rollup merge of #102888 - GuillaumeGomez:improve-search-color-check, r=notriddle
[rust.git] / src / tools / clippy / clippy_lints / src / uninit_vec.rs
index 3f99bd3f31567c43592b9e2301557857096f65e7..1ab0162a88134165770c19ba80cc0fe3da0433f7 100644 (file)
@@ -1,7 +1,7 @@
 use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
 use clippy_utils::higher::{get_vec_init_kind, VecInitKind};
 use clippy_utils::ty::{is_type_diagnostic_item, is_uninit_value_valid_for_ty};
-use clippy_utils::{is_lint_allowed, path_to_local_id, peel_hir_expr_while, SpanlessEq};
+use clippy_utils::{is_integer_literal, is_lint_allowed, path_to_local_id, peel_hir_expr_while, SpanlessEq};
 use rustc_hir::{Block, Expr, ExprKind, HirId, PatKind, PathSegment, Stmt, StmtKind};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::lint::in_external_macro;
@@ -211,9 +211,12 @@ fn extract_set_len_self<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Opt
         }
     });
     match expr.kind {
-        ExprKind::MethodCall(path, self_expr, [_], _) => {
+        ExprKind::MethodCall(path, self_expr, [arg], _) => {
             let self_type = cx.typeck_results().expr_ty(self_expr).peel_refs();
-            if is_type_diagnostic_item(cx, self_type, sym::Vec) && path.ident.name.as_str() == "set_len" {
+            if is_type_diagnostic_item(cx, self_type, sym::Vec)
+                && path.ident.name.as_str() == "set_len"
+                && !is_integer_literal(arg, 0)
+            {
                 Some((self_expr, expr.span))
             } else {
                 None