Skip to content

Commit

Permalink
Auto merge of rust-lang#6301 - alex-700:fix-map-clone, r=matthiaskrgr
Browse files Browse the repository at this point in the history
do not trigger map_clone in the case of &mut

fixes rust-lang#6299
changelog: do not trigger map_clone in the case of &mut
  • Loading branch information
bors committed Nov 8, 2020
2 parents c015622 + 5f57608 commit 96d5f45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
&& match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) {

let obj_ty = cx.typeck_results().expr_ty(&obj[0]);
if let ty::Ref(_, ty, _) = obj_ty.kind() {
let copy = is_copy(cx, ty);
lint(cx, e.span, args[0].span, copy);
if let ty::Ref(_, ty, mutability) = obj_ty.kind() {
if matches!(mutability, Mutability::Not) {
let copy = is_copy(cx, ty);
lint(cx, e.span, args[0].span, copy);
}
} else {
lint_needless_cloning(cx, e.span, args[0].span);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/map_clone.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ fn main() {
let v = vec![&mut d];
let _: Vec<u32> = v.into_iter().map(|&mut x| x).collect();
}

// Issue #6299
{
let mut aa = 5;
let mut bb = 3;
let items = vec![&mut aa, &mut bb];
let _: Vec<_> = items.into_iter().map(|x| x.clone()).collect();
}
}
8 changes: 8 additions & 0 deletions tests/ui/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ fn main() {
let v = vec![&mut d];
let _: Vec<u32> = v.into_iter().map(|&mut x| x).collect();
}

// Issue #6299
{
let mut aa = 5;
let mut bb = 3;
let items = vec![&mut aa, &mut bb];
let _: Vec<_> = items.into_iter().map(|x| x.clone()).collect();
}
}

0 comments on commit 96d5f45

Please sign in to comment.