Skip to content

Commit

Permalink
chore: update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxqiu committed Dec 17, 2023
1 parent e346244 commit 87ef71a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions clippy_lints/src/methods/map_unwrap_or_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ pub(super) fn check<'tcx>(
unwrap_recv: &'tcx rustc_hir::Expr<'_>,
msrv: &Msrv,
) {
// Don't lint if:

// 1. the `expr` is generated by a macro
if expr.span.from_expansion() {
return;
}

// Lint if:

// 1. the caller of `map()` is an `Option` or `Result`
// 2. the caller of `map()` is neither `Option` nor `Result`
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(map_recv), sym::Option);
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(map_recv), sym::Result);
if !is_option && !is_result {
return;
}

// 2. the `map_arg` maps `T` to `bool`
// 3. the `map_arg` function/closure doesn't return `bool`
let map_arg_return_bool = expr_sig(cx, map_arg).is_some_and(|fn_sig| {
fn_sig
.output()
Expand All @@ -40,7 +41,7 @@ pub(super) fn check<'tcx>(
return;
}

// 3. msrv meets `OPTION_IS_SOME_AND` and `RESULT_IS_OK_AND`
// 4. msrv doesn't meet either `OPTION_IS_SOME_AND` or `RESULT_IS_OK_AND`
if !msrv.meets(OPTION_IS_SOME_AND) || !msrv.meets(RESULT_IS_OK_AND) {
return;
}
Expand Down

0 comments on commit 87ef71a

Please sign in to comment.