1 use clippy_utils::diagnostics::span_lint_and_then;
2 use clippy_utils::ty::is_type_diagnostic_item;
3 use if_chain::if_chain;
4 use rustc_ast::LitKind;
5 use rustc_errors::Applicability;
6 use rustc_hir::{Expr, ExprKind};
7 use rustc_lint::LateContext;
8 use rustc_span::source_map::Spanned;
9 use rustc_span::{sym, Span};
11 use super::VEC_RESIZE_TO_ZERO;
13 pub(super) fn check<'tcx>(
14 cx: &LateContext<'tcx>,
16 count_arg: &'tcx Expr<'_>,
17 default_arg: &'tcx Expr<'_>,
21 if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
22 if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
23 if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Vec);
24 if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = count_arg.kind;
25 if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = default_arg.kind;
27 let method_call_span = expr.span.with_lo(name_span.lo());
32 "emptying a vector with `resize`",
34 db.help("the arguments may be inverted...");
37 "...or you can empty the vector with",
38 "clear()".to_string(),
39 Applicability::MaybeIncorrect,