1 use clippy_utils::diagnostics::span_lint_and_help;
2 use clippy_utils::ty::is_type_diagnostic_item;
3 use rustc_hir::{CaptureBy, Closure, Expr, ExprKind, PatKind};
4 use rustc_lint::LateContext;
7 use super::MAP_ERR_IGNORE;
9 pub(super) fn check<'tcx>(cx: &LateContext<'_>, e: &Expr<'_>, arg: &'tcx Expr<'_>) {
10 if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
11 && let Some(impl_id) = cx.tcx.impl_of_method(method_id)
12 && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Result)
13 && let ExprKind::Closure(&Closure {
14 capture_clause: CaptureBy::Ref,
19 && let closure_body = cx.tcx.hir().body(body)
20 && let [param] = closure_body.params
21 && let PatKind::Wild = param.pat.kind
23 // span the area of the closure capture and warn that the
24 // original error will be thrown away
29 "`map_err(|_|...` wildcard pattern discards the original error",
31 "consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)",