@@ -56,7 +56,7 @@ pub fn check(path: &Path, bad: &mut bool, quiet: bool) {
5656 let mut features = collect_lang_features ( path) ;
5757 assert ! ( !features. is_empty( ) ) ;
5858
59- let lib_features = collect_lib_features ( path, bad, & features) ;
59+ let lib_features = get_and_check_lib_features ( path, bad, & features) ;
6060 assert ! ( !lib_features. is_empty( ) ) ;
6161
6262 let mut contents = String :: new ( ) ;
@@ -217,10 +217,61 @@ pub fn collect_lang_features(base_src_path: &Path) -> Features {
217217 . collect ( )
218218}
219219
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 {
223221 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 ) ) {
224275 let mut contents = String :: new ( ) ;
225276 super :: walk ( base_src_path,
226277 & mut |path| super :: filter_dirs ( path) || path. ends_with ( "src/test" ) ,
@@ -236,16 +287,19 @@ pub fn collect_lib_features(base_src_path: &Path,
236287
237288 let mut becoming_feature: Option < ( String , Feature ) > = None ;
238289 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+ } } ;
241295 } ;
242296 if let Some ( ( ref name, ref mut f) ) = becoming_feature {
243297 if f. tracking_issue . is_none ( ) {
244298 f. tracking_issue = find_attr_val ( line, "issue" )
245299 . map ( |s| s. parse ( ) . unwrap ( ) ) ;
246300 }
247301 if line. ends_with ( "]" ) {
248- lib_features . insert ( name . to_owned ( ) , f. clone ( ) ) ;
302+ mf ( Ok ( ( name , f. clone ( ) ) ) , file , i + 1 ) ;
249303 } else if !line. ends_with ( "," ) && !line. ends_with ( "\\ " ) {
250304 // We need to bail here because we might have missed the
251305 // end of a stability attribute above because the "]"
@@ -254,7 +308,7 @@ pub fn collect_lib_features(base_src_path: &Path,
254308 // we continue parsing the file assuming the current stability
255309 // attribute has not ended, and ignoring possible feature
256310 // attributes in the process.
257- err ( "malformed stability attribute" ) ;
311+ err ! ( "malformed stability attribute" ) ;
258312 } else {
259313 continue ;
260314 }
@@ -269,45 +323,28 @@ pub fn collect_lib_features(base_src_path: &Path,
269323 } ;
270324 let feature_name = match find_attr_val ( line, "feature" ) {
271325 Some ( name) => name,
272- None => {
273- err ( "malformed stability attribute" ) ;
274- continue ;
275- }
326+ None => err ! ( "malformed stability attribute" ) ,
276327 } ;
277328 let since = match find_attr_val ( line, "since" ) {
278329 Some ( name) => name,
279330 None if level == Status :: Stable => {
280- err ( "malformed stability attribute" ) ;
281- continue ;
331+ err ! ( "malformed stability attribute" ) ;
282332 }
283333 None => "None" ,
284334 } ;
285335 let tracking_issue = find_attr_val ( line, "issue" ) . map ( |s| s. parse ( ) . unwrap ( ) ) ;
286336
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- }
299337 let feature = Feature {
300338 level,
301339 since : since. to_owned ( ) ,
302340 has_gate_test : false ,
303341 tracking_issue,
304342 } ;
305343 if line. contains ( "]" ) {
306- lib_features . insert ( feature_name . to_owned ( ) , feature) ;
344+ mf ( Ok ( ( feature_name , feature) ) , file , i + 1 ) ;
307345 } else {
308346 becoming_feature = Some ( ( feature_name. to_owned ( ) , feature) ) ;
309347 }
310348 }
311349 } ) ;
312- lib_features
313350}
0 commit comments