parent
0be654482c
commit
c0d1002d93
@ -32,6 +32,16 @@ pub(super) fn lint<'tcx>(
|
|||||||
} else {
|
} else {
|
||||||
"unnecessary closure used to substitute value for `Result::Err`"
|
"unnecessary closure used to substitute value for `Result::Err`"
|
||||||
};
|
};
|
||||||
|
let applicability = if body
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.all(|param| matches!(param.pat.kind, hir::PatKind::Wild))
|
||||||
|
{
|
||||||
|
Applicability::MachineApplicable
|
||||||
|
} else {
|
||||||
|
// replacing the lambda may break type inference
|
||||||
|
Applicability::MaybeIncorrect
|
||||||
|
};
|
||||||
|
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
@ -45,7 +55,7 @@ pub(super) fn lint<'tcx>(
|
|||||||
simplify_using,
|
simplify_using,
|
||||||
snippet(cx, body_expr.span, ".."),
|
snippet(cx, body_expr.span, ".."),
|
||||||
),
|
),
|
||||||
Applicability::MachineApplicable,
|
applicability,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
tests/ui/unnecessary_lazy_eval_unfixable.rs
Normal file
18
tests/ui/unnecessary_lazy_eval_unfixable.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#![warn(clippy::unnecessary_lazy_evaluations)]
|
||||||
|
|
||||||
|
struct Deep(Option<usize>);
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
struct SomeStruct {
|
||||||
|
some_field: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// fix will break type inference
|
||||||
|
let _ = Ok(1).unwrap_or_else(|()| 2);
|
||||||
|
mod e {
|
||||||
|
pub struct E;
|
||||||
|
}
|
||||||
|
let _ = Ok(1).unwrap_or_else(|e::E| 2);
|
||||||
|
let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
|
||||||
|
}
|
22
tests/ui/unnecessary_lazy_eval_unfixable.stderr
Normal file
22
tests/ui/unnecessary_lazy_eval_unfixable.stderr
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
error: unnecessary closure used to substitute value for `Result::Err`
|
||||||
|
--> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13
|
||||||
|
|
|
||||||
|
LL | let _ = Ok(1).unwrap_or_else(|()| 2);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: unnecessary closure used to substitute value for `Result::Err`
|
||||||
|
--> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13
|
||||||
|
|
|
||||||
|
LL | let _ = Ok(1).unwrap_or_else(|e::E| 2);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||||
|
|
||||||
|
error: unnecessary closure used to substitute value for `Result::Err`
|
||||||
|
--> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13
|
||||||
|
|
|
||||||
|
LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user