in gazebo_lint/src/lib.rs [334:364]
fn check_use_duped(cx: &LateContext, expr: &Expr) {
if let ExprKind::MethodCall(method_call, method_span, args, _) = expr.kind {
if args.len() == 1 && method_call.ident.name == sym!(cloned) {
if let Some(iterator_trait) =
clippy::get_trait_def_id(cx, &["gazebo", "ext", "iter", "IterDuped"])
{
let mut cloned_type = cx.typeck_results().expr_ty(&args[0]);
loop {
if clippy::implements_trait(cx, cloned_type, iterator_trait, &[]) {
emit_suggestion(
cx,
GAZEBO_LINT_USE_DUPED,
method_span,
"duped".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;
}
}
}
}
}
}