@@ -4,6 +4,7 @@ use clippy_utils::{fn_def_id, get_enclosing_block, path_to_local_id};
4
4
use rustc_ast:: Mutability ;
5
5
use rustc_ast:: visit:: visit_opt;
6
6
use rustc_errors:: Applicability ;
7
+ use rustc_hir:: def_id:: LocalDefId ;
7
8
use rustc_hir:: intravisit:: { Visitor , walk_block, walk_expr, walk_local} ;
8
9
use rustc_hir:: { Expr , ExprKind , HirId , LetStmt , Node , PatKind , Stmt , StmtKind } ;
9
10
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -68,6 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ZombieProcesses {
68
69
let mut vis = WaitFinder {
69
70
cx,
70
71
local_id,
72
+ body_id : cx. tcx . hir_enclosing_body_owner ( expr. hir_id ) ,
71
73
state : VisitorState :: WalkUpToLocal ,
72
74
early_return : None ,
73
75
missing_wait_branch : None ,
@@ -129,6 +131,7 @@ struct MaybeWait(Span);
129
131
struct WaitFinder < ' a , ' tcx > {
130
132
cx : & ' a LateContext < ' tcx > ,
131
133
local_id : HirId ,
134
+ body_id : LocalDefId ,
132
135
state : VisitorState ,
133
136
early_return : Option < Span > ,
134
137
// When joining two if branches where one of them doesn't call `wait()`, stores its span for more targeted help
@@ -186,7 +189,7 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> {
186
189
}
187
190
} else {
188
191
match ex. kind {
189
- ExprKind :: Ret ( e) => {
192
+ ExprKind :: Ret ( e) if self . cx . tcx . hir_enclosing_body_owner ( ex . hir_id ) == self . body_id => {
190
193
visit_opt ! ( self , visit_expr, e) ;
191
194
if self . early_return . is_none ( ) {
192
195
self . early_return = Some ( ex. span ) ;
0 commit comments