use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{match_def_path, meets_msrv, msrvs, path_to_local_id, paths, remove_blocks};
+use clippy_utils::{match_def_path, meets_msrv, msrvs, path_to_local_id, paths, peel_blocks};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir as hir;
as_ref_recv: &hir::Expr<'_>,
map_arg: &hir::Expr<'_>,
is_mut: bool,
- msrv: Option<&RustcVersion>,
+ msrv: Option<RustcVersion>,
) {
- if !meets_msrv(msrv, &msrvs::OPTION_AS_DEREF) {
+ if !meets_msrv(msrv, msrvs::OPTION_AS_DEREF) {
return;
}
let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not);
let option_ty = cx.typeck_results().expr_ty(as_ref_recv);
- if !is_type_diagnostic_item(cx, option_ty, sym::option_type) {
+ if !is_type_diagnostic_item(cx, option_ty, sym::Option) {
return;
}
.map_or(false, |fun_def_id| {
deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
}),
- hir::ExprKind::Closure(_, _, body_id, _, _) => {
- let closure_body = cx.tcx.hir().body(body_id);
- let closure_expr = remove_blocks(&closure_body.value);
+ hir::ExprKind::Closure { body, .. } => {
+ let closure_body = cx.tcx.hir().body(body);
+ let closure_expr = peel_blocks(&closure_body.value);
match &closure_expr.kind {
- hir::ExprKind::MethodCall(_, _, args, _) => {
+ hir::ExprKind::MethodCall(_, args, _) => {
if_chain! {
if args.len() == 1;
if path_to_local_id(&args[0], closure_body.params[0].pat.hir_id);