@@ -56,7 +56,7 @@ pub fn check(path: &Path, bad: &mut bool, quiet: bool) {
56
56
let mut features = collect_lang_features ( path) ;
57
57
assert ! ( !features. is_empty( ) ) ;
58
58
59
- let lib_features = collect_lib_features ( path, bad, & features) ;
59
+ let lib_features = get_and_check_lib_features ( path, bad, & features) ;
60
60
assert ! ( !lib_features. is_empty( ) ) ;
61
61
62
62
let mut contents = String :: new ( ) ;
@@ -217,10 +217,61 @@ pub fn collect_lang_features(base_src_path: &Path) -> Features {
217
217
. collect ( )
218
218
}
219
219
220
- pub fn collect_lib_features ( base_src_path : & Path ,
221
- bad : & mut bool ,
222
- features : & Features ) -> Features {
220
+ pub fn collect_lib_features ( base_src_path : & Path ) -> Features {
223
221
let mut lib_features = Features :: new ( ) ;
222
+ map_lib_features ( base_src_path,
223
+ & mut |res, _, _| {
224
+ match res {
225
+ Ok ( ( name, feature) ) => {
226
+ if lib_features. get ( name) . is_some ( ) {
227
+ return ;
228
+ }
229
+ lib_features. insert ( name. to_owned ( ) , feature) ;
230
+ } ,
231
+ Err ( _) => ( ) ,
232
+ }
233
+ } ) ;
234
+ lib_features
235
+ }
236
+
237
+ fn get_and_check_lib_features ( base_src_path : & Path ,
238
+ bad : & mut bool ,
239
+ lang_features : & Features ) -> Features {
240
+ let mut lib_features = Features :: new ( ) ;
241
+ map_lib_features ( base_src_path,
242
+ & mut |res, file, line| {
243
+ match res {
244
+ Ok ( ( name, f) ) => {
245
+ let mut err = |msg : & str | {
246
+ tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , line, msg) ;
247
+ } ;
248
+ if lang_features. contains_key ( name) {
249
+ err ( "duplicating a lang feature" ) ;
250
+ }
251
+ if let Some ( ref s) = lib_features. get ( name) {
252
+ if s. level != f. level {
253
+ err ( "different stability level than before" ) ;
254
+ }
255
+ if s. since != f. since {
256
+ err ( "different `since` than before" ) ;
257
+ }
258
+ if s. tracking_issue != f. tracking_issue {
259
+ err ( "different `tracking_issue` than before" ) ;
260
+ }
261
+ }
262
+ lib_features. insert ( name. to_owned ( ) , f) ;
263
+ } ,
264
+ Err ( msg) => {
265
+ tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , line, msg) ;
266
+ } ,
267
+ }
268
+
269
+ } ) ;
270
+ lib_features
271
+ }
272
+
273
+ fn map_lib_features ( base_src_path : & Path ,
274
+ mf : & mut FnMut ( Result < ( & str , Feature ) , & str > , & Path , usize ) ) {
224
275
let mut contents = String :: new ( ) ;
225
276
super :: walk ( base_src_path,
226
277
& mut |path| super :: filter_dirs ( path) || path. ends_with ( "src/test" ) ,
@@ -236,16 +287,19 @@ pub fn collect_lib_features(base_src_path: &Path,
236
287
237
288
let mut becoming_feature: Option < ( String , Feature ) > = None ;
238
289
for ( i, line) in contents. lines ( ) . enumerate ( ) {
239
- let mut err = |msg : & str | {
240
- tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
290
+ macro_rules! err {
291
+ ( $msg: expr) => { {
292
+ mf( Err ( $msg) , file, i + 1 ) ;
293
+ continue ;
294
+ } } ;
241
295
} ;
242
296
if let Some ( ( ref name, ref mut f) ) = becoming_feature {
243
297
if f. tracking_issue . is_none ( ) {
244
298
f. tracking_issue = find_attr_val ( line, "issue" )
245
299
. map ( |s| s. parse ( ) . unwrap ( ) ) ;
246
300
}
247
301
if line. ends_with ( "]" ) {
248
- lib_features . insert ( name . to_owned ( ) , f. clone ( ) ) ;
302
+ mf ( Ok ( ( name , f. clone ( ) ) ) , file , i + 1 ) ;
249
303
} else if !line. ends_with ( "," ) && !line. ends_with ( "\\ " ) {
250
304
// We need to bail here because we might have missed the
251
305
// end of a stability attribute above because the "]"
@@ -254,7 +308,7 @@ pub fn collect_lib_features(base_src_path: &Path,
254
308
// we continue parsing the file assuming the current stability
255
309
// attribute has not ended, and ignoring possible feature
256
310
// attributes in the process.
257
- err ( "malformed stability attribute" ) ;
311
+ err ! ( "malformed stability attribute" ) ;
258
312
} else {
259
313
continue ;
260
314
}
@@ -269,45 +323,28 @@ pub fn collect_lib_features(base_src_path: &Path,
269
323
} ;
270
324
let feature_name = match find_attr_val ( line, "feature" ) {
271
325
Some ( name) => name,
272
- None => {
273
- err ( "malformed stability attribute" ) ;
274
- continue ;
275
- }
326
+ None => err ! ( "malformed stability attribute" ) ,
276
327
} ;
277
328
let since = match find_attr_val ( line, "since" ) {
278
329
Some ( name) => name,
279
330
None if level == Status :: Stable => {
280
- err ( "malformed stability attribute" ) ;
281
- continue ;
331
+ err ! ( "malformed stability attribute" ) ;
282
332
}
283
333
None => "None" ,
284
334
} ;
285
335
let tracking_issue = find_attr_val ( line, "issue" ) . map ( |s| s. parse ( ) . unwrap ( ) ) ;
286
336
287
- if features. contains_key ( feature_name) {
288
- err ( "duplicating a lang feature" ) ;
289
- }
290
- if let Some ( ref s) = lib_features. get ( feature_name) {
291
- if s. level != level {
292
- err ( "different stability level than before" ) ;
293
- }
294
- if s. since != since {
295
- err ( "different `since` than before" ) ;
296
- }
297
- continue ;
298
- }
299
337
let feature = Feature {
300
338
level,
301
339
since : since. to_owned ( ) ,
302
340
has_gate_test : false ,
303
341
tracking_issue,
304
342
} ;
305
343
if line. contains ( "]" ) {
306
- lib_features . insert ( feature_name . to_owned ( ) , feature) ;
344
+ mf ( Ok ( ( feature_name , feature) ) , file , i + 1 ) ;
307
345
} else {
308
346
becoming_feature = Some ( ( feature_name. to_owned ( ) , feature) ) ;
309
347
}
310
348
}
311
349
} ) ;
312
- lib_features
313
350
}
0 commit comments