-use crate::utils::{eager_or_lazy, usage};
-use crate::utils::{is_type_diagnostic_item, snippet, span_lint_and_sugg};
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet;
+use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::{eager_or_lazy, usage};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
/// lint use of `<fn>_else(simple closure)` for `Option`s and `Result`s that can be
/// replaced with `<fn>(return value of simple closure)`
-pub(super) fn lint<'tcx>(
+pub(super) fn check<'tcx>(
cx: &LateContext<'tcx>,
expr: &'tcx hir::Expr<'_>,
- args: &'tcx [hir::Expr<'_>],
+ recv: &'tcx hir::Expr<'_>,
+ arg: &'tcx hir::Expr<'_>,
simplify_using: &str,
) {
- let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&args[0]), sym::option_type);
- let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&args[0]), sym::result_type);
+ let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type);
+ let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type);
if is_option || is_result {
- if let hir::ExprKind::Closure(_, _, eid, _, _) = args[1].kind {
+ if let hir::ExprKind::Closure(_, _, eid, _, _) = arg.kind {
let body = cx.tcx.hir().body(eid);
let body_expr = &body.value;
UNNECESSARY_LAZY_EVALUATIONS,
expr.span,
msg,
- &format!("Use `{}` instead", simplify_using),
+ &format!("use `{}` instead", simplify_using),
format!(
"{0}.{1}({2})",
- snippet(cx, args[0].span, ".."),
+ snippet(cx, recv.span, ".."),
simplify_using,
snippet(cx, body_expr.span, ".."),
),