diff options
| author | bors <bors@rust-lang.org> | 2020-11-08 01:28:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-08 01:28:27 +0000 |
| commit | 96d5f45adee883c565062fbb44de7ea29918539d (patch) | |
| tree | 2687e95aee0eacd93e9233377b4015a1a72351e5 | |
| parent | c015622568f03cbd6931e073c95de89040e95434 (diff) | |
| parent | 5f57608604bd35bd11c1f33cbd7202250e072b54 (diff) | |
| download | rust-96d5f45adee883c565062fbb44de7ea29918539d.tar.gz rust-96d5f45adee883c565062fbb44de7ea29918539d.zip | |
Auto merge of #6301 - alex-700:fix-map-clone, r=matthiaskrgr
do not trigger map_clone in the case of &mut fixes #6299 changelog: do not trigger map_clone in the case of &mut
| -rw-r--r-- | clippy_lints/src/map_clone.rs | 8 | ||||
| -rw-r--r-- | tests/ui/map_clone.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/map_clone.rs | 8 |
3 files changed, 21 insertions, 3 deletions
diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 034cd99a9be..9a00608ce39 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -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); } diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index 81c7f659efb..6e3a8e67e81 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -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(); + } } diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 8ed164f0ed5..6fd395710d4 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -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(); + } } |
