1
1
//! Checks that all error codes have at least one test to prevent having error
2
2
//! codes that are silently not thrown by the compiler anymore.
3
3
4
- use std:: collections:: hash_map:: Entry ;
5
4
use std:: collections:: HashMap ;
6
5
use std:: ffi:: OsStr ;
7
6
use std:: fs:: read_to_string;
@@ -106,19 +105,8 @@ fn extract_error_codes(
106
105
)
107
106
. 0
108
107
. 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
+
122
110
// Now we extract the tests from the markdown file!
123
111
let md_file_name = match s. split_once ( "include_str!(\" " ) {
124
112
None => continue ,
@@ -184,19 +172,7 @@ fn extract_error_codes_from_tests(f: &str, error_codes: &mut HashMap<String, Err
184
172
Some ( ( _, err_code) ) => err_code,
185
173
} ,
186
174
} ;
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 ;
200
176
}
201
177
}
202
178
}
@@ -212,19 +188,7 @@ fn extract_error_codes_from_source(
212
188
}
213
189
for cap in regex. captures_iter ( line) {
214
190
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 ;
228
192
}
229
193
}
230
194
}
0 commit comments