diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 1f3954d569a..7931fabf8d7 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -69,8 +69,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => { match closure_expr.kind { 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, true); + if ident_eq(name, inner) { + if let ty::Ref(..) = cx.tables.expr_ty(inner).kind { + lint(cx, e.span, args[0].span, true); + } } }, hir::ExprKind::MethodCall(ref method, _, ref obj) => { diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index 2029c81d0d5..5e6b3fad41c 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -23,4 +23,14 @@ fn main() { // Issue #498 let _ = std::env::args(); + + // Issue #4824 item types that aren't references + { + use std::rc::Rc; + + let o: Option<Rc<u32>> = Some(Rc::new(0_u32)); + let _: Option<u32> = o.map(|x| *x); + let v: Vec<Rc<u32>> = vec![Rc::new(0_u32)]; + let _: Vec<u32> = v.into_iter().map(|x| *x).collect(); + } } diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 495c18f311f..2fe078b2752 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -23,4 +23,14 @@ fn main() { // Issue #498 let _ = std::env::args().map(|v| v.clone()); + + // Issue #4824 item types that aren't references + { + use std::rc::Rc; + + let o: Option<Rc<u32>> = Some(Rc::new(0_u32)); + let _: Option<u32> = o.map(|x| *x); + let v: Vec<Rc<u32>> = vec![Rc::new(0_u32)]; + let _: Vec<u32> = v.into_iter().map(|x| *x).collect(); + } }