Skip to content

Commit 0ed2eda

Browse files
committed
get rid of require_semi function
1 parent d547843 commit 0ed2eda

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

clippy_lints/src/question_mark.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ fn check_if_let_some_or_err_and_early_return(cx: &LateContext<'_>, expr: &Expr<'
122122
let mut applicability = Applicability::MachineApplicable;
123123
let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability);
124124
let by_ref = matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut);
125+
let requires_semi = matches!(get_parent_node(expr), Some(Node::Stmt(_)));
125126
let replacement = format!(
126127
"{}{}?{}",
127128
receiver_str,
128129
if by_ref { ".as_ref()" } else { "" },
129-
if requires_semi(if_then, if_else) { ";" } else { "" }
130+
if requires_semi { ";" } else { "" }
130131
);
131132
offer_suggestion(cx, expr, replacement, applicability);
132133
}
@@ -202,18 +203,6 @@ fn expr_return_none_or_err(
202203
}
203204
}
204205

205-
/// Check whether the fixed code needs semicolon after `?`
206-
///
207-
/// It will need a semicolon if all block(s) has one.
208-
fn requires_semi(if_then: &Expr<'_>, if_else: Option<&Expr<'_>>) -> bool {
209-
let if_then_kind = &peel_blocks_with_stmt(if_then).kind;
210-
let if_then_is_ret_stmt = matches!(if_then_kind, ExprKind::Ret(..));
211-
if if_else.is_none() || matches!(peel_blocks_with_stmt(if_else.unwrap()).kind, ExprKind::Ret(_)) {
212-
return if_then_is_ret_stmt;
213-
}
214-
false
215-
}
216-
217206
fn offer_suggestion(cx: &LateContext<'_>, expr: &Expr<'_>, suggestion: String, applicability: Applicability) {
218207
if !suggestion.is_empty() {
219208
span_lint_and_sugg(

0 commit comments

Comments
 (0)