-use crate::utils::span_lint_and_help;
-
+use clippy_utils::diagnostics::span_lint_and_help;
use rustc_hir::{CaptureBy, Expr, ExprKind, PatKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
- /// **What it does:** Checks for instances of `map_err(|_| Some::Enum)`
- ///
- /// **Why is this bad?** This map_err throws away the original error rather than allowing the enum to contain and report the cause of the error
+ /// ### What it does
+ /// Checks for instances of `map_err(|_| Some::Enum)`
///
- /// **Known problems:** None.
+ /// ### Why is this bad?
+ /// This `map_err` throws away the original error rather than allowing the enum to contain and report the cause of the error
///
- /// **Example:**
+ /// ### Example
/// Before:
/// ```rust
/// use std::fmt;
/// })
/// }
/// ```
+ #[clippy::version = "1.48.0"]
pub MAP_ERR_IGNORE,
- pedantic,
+ restriction,
"`map_err` should not ignore the original error"
}
}
// check if this is a method call (e.g. x.foo())
- if let ExprKind::MethodCall(ref method, _t_span, ref args, _) = e.kind {
+ if let ExprKind::MethodCall(method, args, _) = e.kind {
// only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1]
// Enum::Variant[2]))
if method.ident.as_str() == "map_err" && args.len() == 2 {
cx,
MAP_ERR_IGNORE,
body_span,
- "`map_err(|_|...` ignores the original error",
+ "`map_err(|_|...` wildcard pattern discards the original error",
None,
- "Consider wrapping the error in an enum variant",
+ "consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)",
);
}
}