1 use super::utils::derefs_to_slice;
2 use clippy_utils::diagnostics::span_lint_and_sugg;
3 use clippy_utils::paths;
4 use clippy_utils::source::snippet_with_applicability;
5 use clippy_utils::ty::{is_type_diagnostic_item, match_type};
6 use rustc_errors::Applicability;
8 use rustc_lint::LateContext;
11 use super::ITER_COUNT;
13 pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx Expr<'tcx>, iter_method: &str) {
14 let ty = cx.typeck_results().expr_ty(recv);
15 let caller_type = if derefs_to_slice(cx, recv, ty).is_some() {
17 } else if is_type_diagnostic_item(cx, ty, sym::vec_type) {
19 } else if is_type_diagnostic_item(cx, ty, sym::vecdeque_type) {
21 } else if is_type_diagnostic_item(cx, ty, sym::hashset_type) {
23 } else if is_type_diagnostic_item(cx, ty, sym::hashmap_type) {
25 } else if match_type(cx, ty, &paths::BTREEMAP) {
27 } else if match_type(cx, ty, &paths::BTREESET) {
29 } else if match_type(cx, ty, &paths::LINKED_LIST) {
31 } else if match_type(cx, ty, &paths::BINARY_HEAP) {
36 let mut applicability = Applicability::MachineApplicable;
41 &format!("called `.{}().count()` on a `{}`", iter_method, caller_type),
45 snippet_with_applicability(cx, recv.span, "..", &mut applicability),