61
61
//! "
62
62
//! ```
63
63
64
+ use std:: iter;
65
+
64
66
use rustc_hash:: FxHashMap ;
65
67
use stdx:: trim_indent;
66
68
@@ -259,7 +261,7 @@ impl MiniCore {
259
261
if res. has_flag ( entry) {
260
262
panic ! ( "duplicate minicore flag: {:?}" , entry) ;
261
263
}
262
- res. activated_flags . push ( entry. to_string ( ) ) ;
264
+ res. activated_flags . push ( entry. to_owned ( ) ) ;
263
265
}
264
266
265
267
res
@@ -273,35 +275,34 @@ impl MiniCore {
273
275
let raw_mini_core = include_str ! ( "./minicore.rs" ) ;
274
276
let mut lines = raw_mini_core. split_inclusive ( '\n' ) ;
275
277
276
- let mut parsing_flags = false ;
277
278
let mut implications = Vec :: new ( ) ;
278
279
279
280
// Parse `//!` preamble and extract flags and dependencies.
280
- for line in lines. by_ref ( ) {
281
- let line = match line. strip_prefix ( "//!" ) {
282
- Some ( it) => it,
283
- None => {
284
- assert ! ( line. trim( ) . is_empty( ) ) ;
285
- break ;
286
- }
287
- } ;
288
-
289
- if parsing_flags {
290
- let ( flag, deps) = line. split_once ( ':' ) . unwrap ( ) ;
291
- let flag = flag. trim ( ) ;
292
- self . valid_flags . push ( flag. to_string ( ) ) ;
293
- for dep in deps. split ( ", " ) {
294
- let dep = dep. trim ( ) ;
295
- if !dep. is_empty ( ) {
296
- self . assert_valid_flag ( dep) ;
297
- implications. push ( ( flag, dep) ) ;
298
- }
299
- }
281
+ let trim_doc: fn ( & str ) -> Option < & str > = |line| match line. strip_prefix ( "//!" ) {
282
+ Some ( it) => Some ( it) ,
283
+ None => {
284
+ assert ! ( line. trim( ) . is_empty( ) , "expected empty line after minicore header" ) ;
285
+ None
300
286
}
287
+ } ;
288
+ for line in lines
289
+ . by_ref ( )
290
+ . map_while ( trim_doc)
291
+ . skip_while ( |line| !line. contains ( "Available flags:" ) )
292
+ . skip ( 1 )
293
+ {
294
+ let ( flag, deps) = line. split_once ( ':' ) . unwrap ( ) ;
295
+ let flag = flag. trim ( ) ;
296
+
297
+ self . valid_flags . push ( flag. to_string ( ) ) ;
298
+ implications. extend (
299
+ iter:: repeat ( flag)
300
+ . zip ( deps. split ( ", " ) . map ( str:: trim) . filter ( |dep| !dep. is_empty ( ) ) ) ,
301
+ ) ;
302
+ }
301
303
302
- if line. contains ( "Available flags:" ) {
303
- parsing_flags = true ;
304
- }
304
+ for ( _, dep) in & implications {
305
+ self . assert_valid_flag ( dep) ;
305
306
}
306
307
307
308
for flag in & self . activated_flags {
@@ -332,7 +333,7 @@ impl MiniCore {
332
333
}
333
334
if let Some ( region) = trimmed. strip_prefix ( "// endregion:" ) {
334
335
let prev = active_regions. pop ( ) . unwrap ( ) ;
335
- assert_eq ! ( prev, region) ;
336
+ assert_eq ! ( prev, region, "unbalanced region pairs" ) ;
336
337
continue ;
337
338
}
338
339
0 commit comments