1
1
use crate :: rustc_lint:: LintContext ;
2
2
use clippy_utils:: diagnostics:: span_lint_and_sugg;
3
3
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} ;
5
5
use if_chain:: if_chain;
6
6
use rustc_errors:: Applicability ;
7
- use rustc_hir:: Expr ;
8
- use rustc_hir:: { Block , BlockCheckMode , ExprKind } ;
7
+ use rustc_hir:: { Block , ExprKind } ;
9
8
use rustc_lint:: { LateContext , LateLintPass } ;
10
9
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
11
10
@@ -47,7 +46,7 @@ impl LateLintPass<'_> for SemicolonIfNothingReturned {
47
46
if t_expr. is_unit( ) ;
48
47
if let snippet = snippet_with_macro_callsite( cx, expr. span, "}" ) ;
49
48
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 ) ;
51
50
then {
52
51
// filter out the desugared `for` loop
53
52
if let ExprKind :: DropTemps ( ..) = & expr. kind {
@@ -69,24 +68,3 @@ impl LateLintPass<'_> for SemicolonIfNothingReturned {
69
68
}
70
69
}
71
70
}
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