Skip to content

Commit 5ec80f3

Browse files
committed
Refactored multiline check
1 parent 6bf8303 commit 5ec80f3

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

clippy_lints/src/semicolon_if_nothing_returned.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::rustc_lint::LintContext;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::snippet_with_macro_callsite;
4-
use clippy_utils::{get_parent_expr_for_hir, in_macro, sugg};
4+
use clippy_utils::{in_macro, sugg};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7-
use rustc_hir::Expr;
8-
use rustc_hir::{Block, BlockCheckMode, ExprKind};
7+
use rustc_hir::{Block, ExprKind};
98
use rustc_lint::{LateContext, LateLintPass};
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110

@@ -47,7 +46,7 @@ impl LateLintPass<'_> for SemicolonIfNothingReturned {
4746
if t_expr.is_unit();
4847
if let snippet = snippet_with_macro_callsite(cx, expr.span, "}");
4948
if !snippet.ends_with('}');
50-
if !check_if_inside_block_on_same_line(cx, block, expr);
49+
if cx.sess().source_map().is_multiline(block.span);
5150
then {
5251
// filter out the desugared `for` loop
5352
if let ExprKind::DropTemps(..) = &expr.kind {
@@ -69,24 +68,3 @@ impl LateLintPass<'_> for SemicolonIfNothingReturned {
6968
}
7069
}
7170
}
72-
73-
/// Check if this block is inside a closure or an unsafe block or a normal on the same line.
74-
fn check_if_inside_block_on_same_line<'tcx>(
75-
cx: &LateContext<'tcx>,
76-
block: &'tcx Block<'tcx>,
77-
last_expr: &'tcx Expr<'_>,
78-
) -> bool {
79-
if_chain! {
80-
if let Some(parent) = get_parent_expr_for_hir(cx, block.hir_id);
81-
82-
if !matches!(block.rules, BlockCheckMode::DefaultBlock) ||
83-
matches!(parent.kind, ExprKind::Closure(..) | ExprKind::Block(..));
84-
85-
if block.stmts.is_empty();
86-
then {
87-
let source_map = cx.sess().source_map();
88-
return !source_map.is_multiline(parent.span.to(last_expr.span));
89-
}
90-
}
91-
false
92-
}

0 commit comments

Comments
 (0)