1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use clippy_utils::{is_expr_identity_function, is_trait_method};
3 use rustc_errors::Applicability;
5 use rustc_lint::LateContext;
6 use rustc_span::{source_map::Span, sym};
8 use super::FLAT_MAP_IDENTITY;
10 /// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient
11 pub(super) fn check<'tcx>(
12 cx: &LateContext<'tcx>,
13 expr: &'tcx hir::Expr<'_>,
14 flat_map_arg: &'tcx hir::Expr<'_>,
17 if is_trait_method(cx, expr, sym::Iterator) && is_expr_identity_function(cx, flat_map_arg) {
21 flat_map_span.with_hi(expr.span.hi()),
22 "use of `flat_map` with an identity function",
24 "flatten()".to_string(),
25 Applicability::MachineApplicable,