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
This commit is contained in:
bors 2019-12-22 09:55:50 +00:00
commit 8723eb6035
3 changed files with 24 additions and 2 deletions

View File

@ -69,8 +69,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => { hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => {
match closure_expr.kind { match closure_expr.kind {
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
if ident_eq(name, inner) && !cx.tables.expr_ty(inner).is_box() { if ident_eq(name, inner) {
lint(cx, e.span, args[0].span, true); 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) => { hir::ExprKind::MethodCall(ref method, _, ref obj) => {

View File

@ -23,4 +23,14 @@ fn main() {
// Issue #498 // Issue #498
let _ = std::env::args(); 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();
}
} }

View File

@ -23,4 +23,14 @@ fn main() {
// Issue #498 // Issue #498
let _ = std::env::args().map(|v| v.clone()); 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();
}
} }