@@ -4,6 +4,7 @@ use clippy_utils::{fn_def_id, get_enclosing_block, path_to_local_id};
44use rustc_ast:: Mutability ;
55use rustc_ast:: visit:: visit_opt;
66use rustc_errors:: Applicability ;
7+ use rustc_hir:: def_id:: LocalDefId ;
78use rustc_hir:: intravisit:: { Visitor , walk_block, walk_expr, walk_local} ;
89use rustc_hir:: { Expr , ExprKind , HirId , LetStmt , Node , PatKind , Stmt , StmtKind } ;
910use rustc_lint:: { LateContext , LateLintPass } ;
@@ -68,6 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ZombieProcesses {
6869 let mut vis = WaitFinder {
6970 cx,
7071 local_id,
72+ body_id : cx. tcx . hir_enclosing_body_owner ( expr. hir_id ) ,
7173 state : VisitorState :: WalkUpToLocal ,
7274 early_return : None ,
7375 missing_wait_branch : None ,
@@ -129,6 +131,7 @@ struct MaybeWait(Span);
129131struct WaitFinder < ' a , ' tcx > {
130132 cx : & ' a LateContext < ' tcx > ,
131133 local_id : HirId ,
134+ body_id : LocalDefId ,
132135 state : VisitorState ,
133136 early_return : Option < Span > ,
134137 // 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> {
186189 }
187190 } else {
188191 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 => {
190193 visit_opt ! ( self , visit_expr, e) ;
191194 if self . early_return . is_none ( ) {
192195 self . early_return = Some ( ex. span ) ;
0 commit comments