changed the msrv to 1.70 to suggest is_some_and

if the msrv is not >= 1.70 then the `map_or` is suggested instead of `is_some_and` (even when `unwrap_or` returns false)
This commit is contained in:
darklyspaced 2023-06-26 13:39:45 +08:00
parent 9b7d8d1dc7
commit c60222dc12
No known key found for this signature in database
5 changed files with 49 additions and 6 deletions

View file

@ -3906,7 +3906,7 @@ impl Methods {
manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]);
},
Some(("map", m_recv, [m_arg], span, _)) => {
option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span);
option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span, &self.msrv);
},
Some(("then_some", t_recv, [t_arg], _, _)) => {
obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg);

View file

@ -1,4 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::is_copy;
use clippy_utils::ty::is_type_diagnostic_item;
@ -27,6 +28,7 @@ pub(super) fn check<'tcx>(
unwrap_recv: &rustc_hir::Expr<'_>,
unwrap_arg: &'tcx rustc_hir::Expr<'_>,
map_span: Span,
msrv: &Msrv,
) {
// lint if the caller of `map()` is an `Option`
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option) {
@ -75,10 +77,12 @@ pub(super) fn check<'tcx>(
}
let mut suggest_is_some_and = false;
// argument to `unwrap_or` is false; should suggest using `is_some_and`
if let ExprKind::Lit(unwrap_lit) = &unwrap_arg.kind {
if let rustc_ast::LitKind::Bool(false) = unwrap_lit.node {
suggest_is_some_and = true;
// argument to `unwrap_or` is false & is_some_and is stabilised; should suggest using `is_some_and`
if msrv.meets(msrvs::OPT_IS_SOME_AND) {
if let ExprKind::Lit(unwrap_lit) = &unwrap_arg.kind {
if let rustc_ast::LitKind::Bool(false) = unwrap_lit.node {
suggest_is_some_and = true;
}
}
}