11//! Checks that all error codes have at least one test to prevent having error
22//! codes that are silently not thrown by the compiler anymore.
33
4- use std:: collections:: hash_map:: Entry ;
54use std:: collections:: HashMap ;
65use std:: ffi:: OsStr ;
76use std:: fs:: read_to_string;
@@ -106,19 +105,8 @@ fn extract_error_codes(
106105 )
107106 . 0
108107 . to_owned ( ) ;
109- match error_codes. entry ( err_code. clone ( ) ) {
110- Entry :: Occupied ( mut e) => {
111- let mut entry = e. get_mut ( ) ;
112- entry. has_explanation = true
113- }
114- Entry :: Vacant ( e) => {
115- e. insert ( ErrorCodeStatus {
116- has_test : false ,
117- is_used : false ,
118- has_explanation : true ,
119- } ) ;
120- }
121- }
108+ error_codes. entry ( err_code. clone ( ) ) . or_default ( ) . has_explanation = true ;
109+
122110 // Now we extract the tests from the markdown file!
123111 let md_file_name = match s. split_once ( "include_str!(\" " ) {
124112 None => continue ,
@@ -184,19 +172,7 @@ fn extract_error_codes_from_tests(f: &str, error_codes: &mut HashMap<String, Err
184172 Some ( ( _, err_code) ) => err_code,
185173 } ,
186174 } ;
187- match error_codes. entry ( err_code. to_owned ( ) ) {
188- Entry :: Occupied ( mut e) => {
189- let mut entry = e. get_mut ( ) ;
190- entry. has_test = true
191- }
192- Entry :: Vacant ( e) => {
193- e. insert ( ErrorCodeStatus {
194- has_test : true ,
195- is_used : false ,
196- has_explanation : false ,
197- } ) ;
198- }
199- }
175+ error_codes. entry ( err_code. to_owned ( ) ) . or_default ( ) . has_test = true ;
200176 }
201177 }
202178}
@@ -212,19 +188,7 @@ fn extract_error_codes_from_source(
212188 }
213189 for cap in regex. captures_iter ( line) {
214190 if let Some ( error_code) = cap. get ( 1 ) {
215- match error_codes. entry ( error_code. as_str ( ) . to_owned ( ) ) {
216- Entry :: Occupied ( mut e) => {
217- let mut entry = e. get_mut ( ) ;
218- entry. is_used = true
219- }
220- Entry :: Vacant ( e) => {
221- e. insert ( ErrorCodeStatus {
222- has_test : false ,
223- is_used : true ,
224- has_explanation : false ,
225- } ) ;
226- }
227- }
191+ error_codes. entry ( error_code. as_str ( ) . to_owned ( ) ) . or_default ( ) . is_used = true ;
228192 }
229193 }
230194 }
0 commit comments