mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
Auto merge of #8487 - dswij:8478, r=giraffate
[`map_identity`] checks for needless `map_err` Closes #8478 changelog: [`map_identity`] checks for needless `map_err`
This commit is contained in:
commit
6206086dd5
5 changed files with 15 additions and 4 deletions
|
@ -13,6 +13,7 @@ pub(super) fn check(
|
|||
expr: &hir::Expr<'_>,
|
||||
caller: &hir::Expr<'_>,
|
||||
map_arg: &hir::Expr<'_>,
|
||||
name: &str,
|
||||
_map_span: Span,
|
||||
) {
|
||||
let caller_ty = cx.typeck_results().expr_ty(caller);
|
||||
|
@ -29,7 +30,7 @@ pub(super) fn check(
|
|||
MAP_IDENTITY,
|
||||
sugg_span,
|
||||
"unnecessary map of the identity function",
|
||||
"remove the call to `map`",
|
||||
&format!("remove the call to `{}`", name),
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
|
|
|
@ -2472,7 +2472,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
|
|||
}
|
||||
}
|
||||
},
|
||||
("map", [m_arg]) => {
|
||||
(name @ ("map" | "map_err"), [m_arg]) => {
|
||||
if let Some((name, [recv2, args @ ..], span2)) = method_call(recv) {
|
||||
match (name, args) {
|
||||
("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, msrv),
|
||||
|
@ -2484,7 +2484,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
|
|||
_ => {},
|
||||
}
|
||||
}
|
||||
map_identity::check(cx, expr, recv, m_arg, span);
|
||||
map_identity::check(cx, expr, recv, m_arg, name, span);
|
||||
},
|
||||
("map_or", [def, map]) => option_map_or_none::check(cx, expr, recv, def, map),
|
||||
(name @ "next", args @ []) => {
|
||||
|
|
|
@ -16,6 +16,8 @@ fn main() {
|
|||
let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
|
||||
return x + 3;
|
||||
});
|
||||
let _: Result<u32, u32> = Ok(1);
|
||||
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
|
||||
}
|
||||
|
||||
fn not_identity(x: &u16) -> u16 {
|
||||
|
|
|
@ -18,6 +18,8 @@ fn main() {
|
|||
let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
|
||||
return x + 3;
|
||||
});
|
||||
let _: Result<u32, u32> = Ok(1).map_err(|a| a);
|
||||
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
|
||||
}
|
||||
|
||||
fn not_identity(x: &u16) -> u16 {
|
||||
|
|
|
@ -33,5 +33,11 @@ LL | | return x;
|
|||
LL | | });
|
||||
| |______^ help: remove the call to `map`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: unnecessary map of the identity function
|
||||
--> $DIR/map_identity.rs:21:36
|
||||
|
|
||||
LL | let _: Result<u32, u32> = Ok(1).map_err(|a| a);
|
||||
| ^^^^^^^^^^^^^^^ help: remove the call to `map_err`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue