Handle false positive with map_clone
This commit is contained in:
parent
660b058ba2
commit
20e4c74521
@ -86,8 +86,11 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
|
||||
}
|
||||
}
|
||||
},
|
||||
hir::ExprKind::Call(call, [_]) => {
|
||||
if let hir::ExprKind::Path(qpath) = call.kind {
|
||||
hir::ExprKind::Call(call, args) => {
|
||||
if let hir::ExprKind::Path(qpath) = call.kind
|
||||
&& let [arg] = args
|
||||
&& ident_eq(name, arg)
|
||||
{
|
||||
handle_path(cx, call, &qpath, e, recv);
|
||||
}
|
||||
},
|
||||
@ -119,6 +122,9 @@ fn handle_path(
|
||||
&& let args = args.as_slice()
|
||||
&& let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type())
|
||||
&& 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()));
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
clippy::redundant_clone,
|
||||
clippy::redundant_closure,
|
||||
clippy::useless_asref,
|
||||
clippy::useless_vec
|
||||
clippy::useless_vec,
|
||||
clippy::empty_loop
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
@ -117,4 +118,17 @@ fn main() {
|
||||
let y = x.as_ref().map(|x| String::clone(x));
|
||||
let x: Result<String, ()> = Ok(String::new());
|
||||
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_closure,
|
||||
clippy::useless_asref,
|
||||
clippy::useless_vec
|
||||
clippy::useless_vec,
|
||||
clippy::empty_loop
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
@ -117,4 +118,17 @@ fn main() {
|
||||
let y = x.as_ref().map(|x| String::clone(x));
|
||||
let x: Result<String, ()> = Ok(String::new());
|
||||
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…
Reference in New Issue
Block a user