@@ -33,31 +33,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
3333 if match_def_path( cx, def_id, & paths:: EXIT ) ;
3434 then {
3535 let mut parent = cx. tcx. hir( ) . get_parent_item( e. hir_id) ;
36- // We have to traverse the parents upwards until we find a function
37- // otherwise a exit in a let or if in main would still trigger this
38- loop {
39- match cx. tcx. hir( ) . find( parent) {
40- Some ( Node :: Item ( Item { ident, kind: ItemKind :: Fn ( ..) , ..} ) ) => {
41- // If we found a function we check it's name if it is
42- // `main` we emit a lint.
43- let def_id = cx. tcx. hir( ) . local_def_id( parent) ;
44- if !is_entrypoint_fn( cx, def_id) {
45- span_lint( cx, EXIT , e. span, "usage of `process::exit`" ) ;
46- }
47- // We found any kind of function and can end our loop
48- break ;
49- }
50- // If we found anything but a funciton we continue with the
51- // loop and go one parent up
52- Some ( _) => {
53- parent = cx. tcx. hir( ) . get_parent_item( parent) ;
54- } ,
55- // If we found nothing we break.
56- None => break ,
36+ if let Some ( Node :: Item ( Item { ident, kind: ItemKind :: Fn ( ..) , ..} ) ) = cx. tcx. hir( ) . find( parent) {
37+ // If the next item up is a function we check if it is an entry point
38+ // and only then emit a linter warning
39+ let def_id = cx. tcx. hir( ) . local_def_id( parent) ;
40+ if !is_entrypoint_fn( cx, def_id) {
41+ span_lint( cx, EXIT , e. span, "usage of `process::exit`" ) ;
5742 }
5843 }
5944 }
60-
6145 }
6246 }
6347}
0 commit comments