pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'_>) -> Option<DerefClosure> {
    if let hir::ExprKind::Closure(_, fn_decl, body_id, ..) = closure.kind {
        let closure_body = cx.tcx.hir().body(body_id);
        // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
        // a type annotation is present if param `kind` is different from `TyKind::Infer`
        let closure_arg_is_type_annotated_double_ref = if let TyKind::Rptr(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind
        {
            matches!(ty.kind, TyKind::Rptr(_, MutTy { .. }))
        } else {
            false
        };

        let mut visitor = DerefDelegate {
            cx,
            closure_span: closure.span,
            closure_arg_is_type_annotated_double_ref,
            next_pos: closure.span.lo(),
            suggestion_start: String::new(),
            applicability: Applicability::MaybeIncorrect,
        };

        let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
        cx.tcx.infer_ctxt().enter(|infcx| {
            ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
                .consume_body(closure_body);
        });

        if !visitor.suggestion_start.is_empty() {
            return Some(DerefClosure {
                applicability: visitor.applicability,
                suggestion: visitor.finish(),
            });
        }
    }
    None
}
/// Build suggestion gradually by handling closure arg specific usages,
/// such as explicit deref and borrowing cases.
/// Returns `None` if no such use cases have been triggered in closure body
///
/// note: this only works on single line immutable closures with exactly one input parameter.
Build suggestion gradually by handling closure arg specific usages,
such as explicit deref and borrowing cases.
Returns `None` if no such use cases have been triggered in closure body

this only works on single line immutable closures with exactly one input parameter.
Build suggestion gradually by handling closure arg specific usages such as explicit deref and borrowing cases . Returns ` None ` if no such use cases have been triggered in closure body this only works on single line immutable closures with exactly one input parameter .
pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'_>) -> Option<DerefClosure> {
    if let hir::ExprKind::Closure(_, fn_decl, body_id, ..) = closure.kind {
        let closure_body = cx.tcx.hir().body(body_id);
        // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
        // a type annotation is present if param `kind` is different from `TyKind::Infer`
        let closure_arg_is_type_annotated_double_ref = if let TyKind::Rptr(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind
        {
            matches!(ty.kind, TyKind::Rptr(_, MutTy { .. }))
        } else {
            false
        };
        let mut visitor = DerefDelegate {
            cx,
            closure_span: closure.span,
            closure_arg_is_type_annotated_double_ref,
            next_pos: closure.span.lo(),
            suggestion_start: String::new(),
            applicability: Applicability::MaybeIncorrect,
        };
        let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
        cx.tcx.infer_ctxt().enter(|infcx| {
            ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
                .consume_body(closure_body);
        });
        if !visitor.suggestion_start.is_empty() {
            return Some(DerefClosure {
                applicability: visitor.applicability,
                suggestion: visitor.finish(),
            });
        }
    }
    None
}
pub fn deref_closure_args < ' tcx > ( cx : & LateContext < ' _ > , closure : & ' tcx hir :: Expr < ' _ > ) -> Option < DerefClosure > { if let hir :: ExprKind :: Closure ( _ , fn_decl , body_id , .. ) = closure . kind { let closure_body = cx . tcx . hir ( ) . body ( body_id ) ; // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` let closure_arg_is_type_annotated_double_ref = if let TyKind :: Rptr ( _ , MutTy { ty , .. } ) = fn_decl . inputs [ 0 ] . kind { matches ! ( ty kind TyKind Rptr ( MutTy { } ) ) } else { false } ; let mut visitor = DerefDelegate { cx , closure_span : closure . span , closure_arg_is_type_annotated_double_ref , next_pos : closure . span . lo ( ) , suggestion_start : String :: new ( ) , applicability : Applicability :: MaybeIncorrect , } ; let fn_def_id = cx . tcx . hir ( ) . local_def_id ( closure . hir_id ) ; cx . tcx . infer_ctxt ( ) . enter ( | infcx | { ExprUseVisitor :: new ( & mut visitor , & infcx , fn_def_id , cx . param_env , cx . typeck_results ( ) ) . consume_body ( closure_body ) ; } ) ; if ! visitor . suggestion_start . is_empty ( ) { return Some ( DerefClosure { applicability : visitor . applicability , suggestion : visitor . finish ( ) , } ) ; } } None }
Build suggestion gradually by handling closure arg specific usages,
such as explicit deref and borrowing cases.
Build suggestion gradually by handling closure arg specific usages such as explicit deref and borrowing cases .
cx
&LateContext<'_>
closure
&'tcx hir::Expr<'_>