@@ -85,47 +85,55 @@ fn extract_error_codes(
8585 for line in f. lines ( ) {
8686 let s = line. trim ( ) ;
8787 if !reached_no_explanation && s. starts_with ( 'E' ) && s. contains ( "include_str!(\" " ) {
88- if let Some ( err_code) = s . splitn ( 2 , ':' ) . next ( ) {
89- let err_code = err_code . to_owned ( ) ;
90- if !error_codes . contains_key ( & err_code) {
91- error_codes . insert ( err_code . clone ( ) , false ) ;
92- }
93- // Now we extract the tests from the markdown file!
94- let md = some_or_continue ! ( s . splitn ( 2 , "include_str!( \" " ) . nth ( 1 ) ) ;
95- let md_file_name = some_or_continue ! ( md . splitn ( 2 , " \" )" ) . next ( ) ) ;
96- let path = some_or_continue ! ( path . parent ( ) )
97- . join ( md_file_name )
98- . canonicalize ( )
99- . expect ( "failed to canonicalize error explanation file path" ) ;
100- match read_to_string ( & path ) {
101- Ok ( content ) => {
102- if ! IGNORE_EXPLANATION_CHECK . contains ( & err_code . as_str ( ) )
103- && ! check_if_error_code_is_test_in_explanation ( & content , & err_code )
104- {
105- errors . push ( format ! (
106- "`{}` doesn't use its own error code in compile_fail example" ,
107- path . display ( ) ,
108- ) ) ;
109- }
110- if check_error_code_explanation ( & content, error_codes , err_code) {
111- errors . push ( format ! (
112- "`{}` uses invalid tag `compile-fail` instead of `compile_fail`" ,
113- path . display ( ) ,
114- ) ) ;
115- }
88+ let err_code = match s . split_once ( ':' ) {
89+ None => continue ,
90+ Some ( ( err_code, _ ) ) => err_code . to_owned ( ) ,
91+ } ;
92+ if !error_codes . contains_key ( & err_code ) {
93+ error_codes . insert ( err_code . clone ( ) , false ) ;
94+ }
95+ // Now we extract the tests from the markdown file!
96+ let md_file_name = match s . split_once ( "include_str!( \" " ) {
97+ None => continue ,
98+ Some ( ( _ , md ) ) => match md . split_once ( " \" )" ) {
99+ None => continue ,
100+ Some ( ( file_name , _ ) ) => file_name ,
101+ } ,
102+ } ;
103+ let path = some_or_continue ! ( path . parent ( ) )
104+ . join ( md_file_name )
105+ . canonicalize ( )
106+ . expect ( "failed to canonicalize error explanation file path" ) ;
107+ match read_to_string ( & path ) {
108+ Ok ( content ) => {
109+ if ! IGNORE_EXPLANATION_CHECK . contains ( & err_code . as_str ( ) )
110+ && ! check_if_error_code_is_test_in_explanation ( & content, & err_code)
111+ {
112+ errors . push ( format ! (
113+ "`{}` doesn't use its own error code in compile_fail example" ,
114+ path . display ( ) ,
115+ ) ) ;
116116 }
117- Err ( e) => {
118- eprintln ! ( "Couldn't read `{}`: {}" , path. display( ) , e) ;
117+ if check_error_code_explanation ( & content, error_codes, err_code) {
118+ errors. push ( format ! (
119+ "`{}` uses invalid tag `compile-fail` instead of `compile_fail`" ,
120+ path. display( ) ,
121+ ) ) ;
119122 }
120123 }
124+ Err ( e) => {
125+ eprintln ! ( "Couldn't read `{}`: {}" , path. display( ) , e) ;
126+ }
121127 }
122128 } else if reached_no_explanation && s. starts_with ( 'E' ) {
123- if let Some ( err_code) = s. splitn ( 2 , ',' ) . next ( ) {
124- let err_code = err_code. to_owned ( ) ;
125- if !error_codes. contains_key ( & err_code) {
126- // this check should *never* fail!
127- error_codes. insert ( err_code, false ) ;
128- }
129+ let err_code = match s. split_once ( ',' ) {
130+ None => s,
131+ Some ( ( err_code, _) ) => err_code,
132+ }
133+ . to_string ( ) ;
134+ if !error_codes. contains_key ( & err_code) {
135+ // this check should *never* fail!
136+ error_codes. insert ( err_code, false ) ;
129137 }
130138 } else if s == ";" {
131139 reached_no_explanation = true ;
@@ -137,12 +145,15 @@ fn extract_error_codes_from_tests(f: &str, error_codes: &mut HashMap<String, boo
137145 for line in f. lines ( ) {
138146 let s = line. trim ( ) ;
139147 if s. starts_with ( "error[E" ) || s. starts_with ( "warning[E" ) {
140- if let Some ( err_code) = s. splitn ( 2 , ']' ) . next ( ) {
141- if let Some ( err_code) = err_code. splitn ( 2 , '[' ) . nth ( 1 ) {
142- let nb = error_codes. entry ( err_code. to_owned ( ) ) . or_insert ( false ) ;
143- * nb = true ;
144- }
145- }
148+ let err_code = match s. split_once ( ']' ) {
149+ None => continue ,
150+ Some ( ( err_code, _) ) => match err_code. split_once ( '[' ) {
151+ None => continue ,
152+ Some ( ( _, err_code) ) => err_code,
153+ } ,
154+ } ;
155+ let nb = error_codes. entry ( err_code. to_owned ( ) ) . or_insert ( false ) ;
156+ * nb = true ;
146157 }
147158 }
148159}
0 commit comments