Skip to content

Commit 8aafe8c

Browse files
committed
simplify is_early_return function
1 parent e6c4a28 commit 8aafe8c

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

clippy_lints/src/question_mark.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,16 @@ fn is_early_return(smbl: Symbol, cx: &LateContext<'_>, if_block: &IfBlockType<'_
152152
sym::Option => {
153153
// We only need to check `if let Some(x) = option` not `if let None = option`,
154154
// because the later one will be suggested as `if option.is_none()` thus causing conflict.
155-
if if_else.is_none() {
156-
return false;
157-
};
158-
expr_return_none_or_err(smbl, cx, if_else.unwrap(), let_expr, None)
159-
&& is_lang_ctor(cx, qpath, OptionSome)
155+
is_lang_ctor(cx, qpath, OptionSome)
156+
&& if_else.is_some()
157+
&& expr_return_none_or_err(smbl, cx, if_else.unwrap(), let_expr, None)
160158
},
161159
sym::Result => {
162-
if is_lang_ctor(cx, qpath, ResultOk) {
163-
if if_else.is_none() {
164-
return false;
165-
};
166-
expr_return_none_or_err(smbl, cx, if_else.unwrap(), let_expr, Some(let_pat_sym))
167-
} else if is_lang_ctor(cx, qpath, ResultErr) {
168-
expr_return_none_or_err(smbl, cx, if_then, let_expr, Some(let_pat_sym))
169-
} else {
170-
false
171-
}
160+
(is_lang_ctor(cx, qpath, ResultOk)
161+
&& if_else.is_some()
162+
&& expr_return_none_or_err(smbl, cx, if_else.unwrap(), let_expr, Some(let_pat_sym)))
163+
|| is_lang_ctor(cx, qpath, ResultErr)
164+
&& expr_return_none_or_err(smbl, cx, if_then, let_expr, Some(let_pat_sym))
172165
},
173166
_ => false,
174167
}

0 commit comments

Comments
 (0)