@@ -32,14 +32,8 @@ use syn::spanned::Spanned;
3232use syn:: visit:: { self , Visit } ;
3333use syn:: Token ;
3434
35- macro_rules! t {
36- ( $e: expr) => {
37- match $e {
38- Ok ( e) => e,
39- Err ( e) => panic!( "{} failed with {}" , stringify!( $e) , e) ,
40- }
41- } ;
42- }
35+ type Error = Box < dyn std:: error:: Error > ;
36+ type Result < T > = std:: result:: Result < T , Error > ;
4337
4438#[ test]
4539fn check_style ( ) {
@@ -50,7 +44,7 @@ fn check_style() {
5044
5145 let root_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../src" ) ;
5246 let mut errors = Errors { errs : false } ;
53- walk ( & root_dir, & mut errors) ;
47+ walk ( & root_dir, & mut errors) . expect ( "root dir should be walked successfully" ) ;
5448
5549 if errors. errs {
5650 panic ! ( "found some lint errors" ) ;
@@ -59,29 +53,31 @@ fn check_style() {
5953 }
6054}
6155
62- fn walk ( path : & Path , err : & mut Errors ) {
63- for entry in t ! ( path. read_dir( ) ) . map ( |e| t ! ( e) ) {
64- let path = entry. path ( ) ;
65- if t ! ( entry. file_type( ) ) . is_dir ( ) {
66- walk ( & path, err) ;
56+ fn walk ( root_dir : & Path , err : & mut Errors ) -> Result < ( ) > {
57+ for entry in glob:: glob ( & format ! (
58+ "{}/**/*.rs" ,
59+ root_dir. to_str( ) . expect( "dir should be valid UTF-8" )
60+ ) ) ? {
61+ let entry = entry?;
62+
63+ let name = entry
64+ . file_name ( )
65+ . expect ( "file name should not end in .." )
66+ . to_str ( )
67+ . expect ( "file name should be valid UTF-8" ) ;
68+ if let "lib.rs" | "macros.rs" = & name[ ..] {
6769 continue ;
6870 }
6971
70- let name = entry. file_name ( ) . into_string ( ) . unwrap ( ) ;
71- match & name[ ..] {
72- n if !n. ends_with ( ".rs" ) => continue ,
73-
74- "lib.rs" | "macros.rs" => continue ,
75-
76- _ => { }
77- }
78-
7972 let mut contents = String :: new ( ) ;
80- t ! ( t!( fs:: File :: open( & path) ) . read_to_string( & mut contents) ) ;
73+ let path = entry. as_path ( ) ;
74+ fs:: File :: open ( path) ?. read_to_string ( & mut contents) ?;
8175
82- let file = t ! ( syn:: parse_file( & contents) ) ;
76+ let file = syn:: parse_file ( & contents) ? ;
8377 StyleChecker :: new ( |line, msg| err. error ( & path, line, msg) ) . visit_file ( & file) ;
8478 }
79+
80+ Ok ( ( ) )
8581}
8682
8783struct Errors {
0 commit comments