Skip to content

Commit 8723eb6

Browse files
committed
Auto merge of #4937 - mikerite:fix-4824, r=phansch
Fix `map_clone` false positive Don't lint when the item type is not a reference. `copied` only applies to references. changelog: Fix `map_clone` false positive
2 parents 19dbb22 + b15b977 commit 8723eb6

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

clippy_lints/src/map_clone.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
6969
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => {
7070
match closure_expr.kind {
7171
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
72-
if ident_eq(name, inner) && !cx.tables.expr_ty(inner).is_box() {
73-
lint(cx, e.span, args[0].span, true);
72+
if ident_eq(name, inner) {
73+
if let ty::Ref(..) = cx.tables.expr_ty(inner).kind {
74+
lint(cx, e.span, args[0].span, true);
75+
}
7476
}
7577
},
7678
hir::ExprKind::MethodCall(ref method, _, ref obj) => {

tests/ui/map_clone.fixed

+10
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ fn main() {
2323

2424
// Issue #498
2525
let _ = std::env::args();
26+
27+
// Issue #4824 item types that aren't references
28+
{
29+
use std::rc::Rc;
30+
31+
let o: Option<Rc<u32>> = Some(Rc::new(0_u32));
32+
let _: Option<u32> = o.map(|x| *x);
33+
let v: Vec<Rc<u32>> = vec![Rc::new(0_u32)];
34+
let _: Vec<u32> = v.into_iter().map(|x| *x).collect();
35+
}
2636
}

tests/ui/map_clone.rs

+10
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ fn main() {
2323

2424
// Issue #498
2525
let _ = std::env::args().map(|v| v.clone());
26+
27+
// Issue #4824 item types that aren't references
28+
{
29+
use std::rc::Rc;
30+
31+
let o: Option<Rc<u32>> = Some(Rc::new(0_u32));
32+
let _: Option<u32> = o.map(|x| *x);
33+
let v: Vec<Rc<u32>> = vec![Rc::new(0_u32)];
34+
let _: Vec<u32> = v.into_iter().map(|x| *x).collect();
35+
}
2636
}

0 commit comments

Comments
 (0)