Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix map_clone false positive #4937

Merged
merged 1 commit into from Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/map_clone.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
10 changes: 10 additions & 0 deletions tests/ui/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}