mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 17:53:56 +00:00
do not trigger map_clone in the case of &mut
This commit is contained in:
parent
b20d4c155d
commit
5f57608604
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user