fn check_use_dupe()

in gazebo_lint/src/lib.rs [302:330]


fn check_use_dupe(cx: &LateContext, expr: &Expr) {
    if let ExprKind::MethodCall(method_call, method_span, args, _) = expr.kind {
        if args.len() == 1 && method_call.ident.name == sym!(clone) {
            if let Some(dupe_trait) = clippy::get_trait_def_id(cx, &["gazebo", "dupe", "Dupe"]) {
                let mut cloned_type = cx.typeck_results().expr_ty(&args[0]).peel_refs();
                loop {
                    if clippy::implements_trait(cx, cloned_type, dupe_trait, &[]) {
                        emit_suggestion(
                            cx,
                            GAZEBO_LINT_USE_DUPE,
                            method_span,
                            "dupe".to_owned(),
                            Applicability::MachineApplicable,
                        );
                    }

                    // Note that Dupe can work on references, that is calling `clone` on `&Foo`
                    // could also be a valid `dupe` call. So, try de-referencing the type once and
                    // check for `Dupe` on `Foo` as well.
                    if let TyKind::Ref(_, inner_ty, _) = cloned_type.kind() {
                        cloned_type = inner_ty;
                    } else {
                        break;
                    }
                }
            }
        }
    }
}