Handle false positive with map_clone
This commit is contained in:
parent
660b058ba2
commit
20e4c74521
3 changed files with 38 additions and 4 deletions
|
@ -86,8 +86,11 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hir::ExprKind::Call(call, [_]) => {
|
hir::ExprKind::Call(call, args) => {
|
||||||
if let hir::ExprKind::Path(qpath) = call.kind {
|
if let hir::ExprKind::Path(qpath) = call.kind
|
||||||
|
&& let [arg] = args
|
||||||
|
&& ident_eq(name, arg)
|
||||||
|
{
|
||||||
handle_path(cx, call, &qpath, e, recv);
|
handle_path(cx, call, &qpath, e, recv);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -119,6 +122,9 @@ fn handle_path(
|
||||||
&& let args = args.as_slice()
|
&& let args = args.as_slice()
|
||||||
&& let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type())
|
&& let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type())
|
||||||
&& ty.is_ref()
|
&& ty.is_ref()
|
||||||
|
&& let ty::Ref(_, ty, Mutability::Not) = ty.kind()
|
||||||
|
&& let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind()
|
||||||
|
&& lst.iter().all(|l| l.as_type() == Some(*ty))
|
||||||
{
|
{
|
||||||
lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs()));
|
lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
clippy::redundant_clone,
|
clippy::redundant_clone,
|
||||||
clippy::redundant_closure,
|
clippy::redundant_closure,
|
||||||
clippy::useless_asref,
|
clippy::useless_asref,
|
||||||
clippy::useless_vec
|
clippy::useless_vec,
|
||||||
|
clippy::empty_loop
|
||||||
)]
|
)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -117,4 +118,17 @@ fn main() {
|
||||||
let y = x.as_ref().map(|x| String::clone(x));
|
let y = x.as_ref().map(|x| String::clone(x));
|
||||||
let x: Result<String, ()> = Ok(String::new());
|
let x: Result<String, ()> = Ok(String::new());
|
||||||
let y = x.as_ref().map(|x| String::clone(x));
|
let y = x.as_ref().map(|x| String::clone(x));
|
||||||
|
|
||||||
|
// Issue #12271
|
||||||
|
{
|
||||||
|
// Don't lint these
|
||||||
|
let x: Option<&u8> = None;
|
||||||
|
let y = x.map(|x| String::clone(loop {}));
|
||||||
|
let x: Option<&u8> = None;
|
||||||
|
let y = x.map(|x| u8::clone(loop {}));
|
||||||
|
let x: Vec<&u8> = vec![];
|
||||||
|
let y = x.into_iter().map(|x| String::clone(loop {}));
|
||||||
|
let x: Vec<&u8> = vec![];
|
||||||
|
let y = x.into_iter().map(|x| u8::clone(loop {}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
clippy::redundant_clone,
|
clippy::redundant_clone,
|
||||||
clippy::redundant_closure,
|
clippy::redundant_closure,
|
||||||
clippy::useless_asref,
|
clippy::useless_asref,
|
||||||
clippy::useless_vec
|
clippy::useless_vec,
|
||||||
|
clippy::empty_loop
|
||||||
)]
|
)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -117,4 +118,17 @@ fn main() {
|
||||||
let y = x.as_ref().map(|x| String::clone(x));
|
let y = x.as_ref().map(|x| String::clone(x));
|
||||||
let x: Result<String, ()> = Ok(String::new());
|
let x: Result<String, ()> = Ok(String::new());
|
||||||
let y = x.as_ref().map(|x| String::clone(x));
|
let y = x.as_ref().map(|x| String::clone(x));
|
||||||
|
|
||||||
|
// Issue #12271
|
||||||
|
{
|
||||||
|
// Don't lint these
|
||||||
|
let x: Option<&u8> = None;
|
||||||
|
let y = x.map(|x| String::clone(loop {}));
|
||||||
|
let x: Option<&u8> = None;
|
||||||
|
let y = x.map(|x| u8::clone(loop {}));
|
||||||
|
let x: Vec<&u8> = vec![];
|
||||||
|
let y = x.into_iter().map(|x| String::clone(loop {}));
|
||||||
|
let x: Vec<&u8> = vec![];
|
||||||
|
let y = x.into_iter().map(|x| u8::clone(loop {}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue