1
- use crate :: utils:: { match_def_path, paths, qpath_res, span_lint} ;
1
+ use crate :: utils:: { is_entrypoint_fn , match_def_path, paths, qpath_res, span_lint} ;
2
2
use if_chain:: if_chain;
3
3
use rustc:: hir:: { Expr , ExprKind , Item , ItemKind , Node } ;
4
4
use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
@@ -40,7 +40,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
40
40
Some ( Node :: Item ( Item { ident, kind: ItemKind :: Fn ( ..) , ..} ) ) => {
41
41
// If we found a function we check it's name if it is
42
42
// `main` we emit a lint.
43
- if ident. name. as_str( ) != "main" {
43
+ let def_id = cx. tcx. hir( ) . local_def_id( parent) ;
44
+ if !is_entrypoint_fn( cx, def_id) {
44
45
span_lint( cx, EXIT , e. span, "usage of `process::exit`" ) ;
45
46
}
46
47
// We found any kind of function and can end our loop
@@ -49,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
49
50
// If we found anything but a funciton we continue with the
50
51
// loop and go one parent up
51
52
Some ( _) => {
52
- cx. tcx. hir( ) . get_parent_item( parent) ;
53
+ parent = cx. tcx. hir( ) . get_parent_item( parent) ;
53
54
} ,
54
55
// If we found nothing we break.
55
56
None => break ,
0 commit comments