- hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => match closure_expr.node {
- hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => lint(cx, e.span, args[0].span, name, inner),
- hir::ExprKind::MethodCall(ref method, _, ref obj) => if method.ident.as_str() == "clone" {
- if match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) {
- lint(cx, e.span, args[0].span, name, &obj[0]);
- }
+ hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => {
+ match closure_expr.node {
+ hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
+ if ident_eq(name, inner) && !cx.tables.expr_ty(inner).is_box() {
+ lint(cx, e.span, args[0].span, is_option);
+ }
+ },
+ hir::ExprKind::MethodCall(ref method, _, ref obj) => {
+ if ident_eq(name, &obj[0]) && method.ident.as_str() == "clone"
+ && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) {
+
+ let obj_ty = cx.tables.expr_ty(&obj[0]);
+ if let ty::Ref(_, ty, _) = obj_ty.sty {
+ let copy = is_copy(cx, ty);
+ lint(cx, e.span, args[0].span, is_option && copy);
+ } else {
+ lint_needless_cloning(cx, e.span, args[0].span);
+ }
+ }
+ },
+ _ => {},