@@ -33,31 +33,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
33
33
if match_def_path( cx, def_id, & paths:: EXIT ) ;
34
34
then {
35
35
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`" ) ;
57
42
}
58
43
}
59
44
}
60
-
61
45
}
62
46
}
63
47
}
0 commit comments