6161//! "
6262//! ```
6363
64+ use std:: iter;
65+
6466use rustc_hash:: FxHashMap ;
6567use stdx:: trim_indent;
6668
@@ -259,7 +261,7 @@ impl MiniCore {
259261 if res. has_flag ( entry) {
260262 panic ! ( "duplicate minicore flag: {:?}" , entry) ;
261263 }
262- res. activated_flags . push ( entry. to_string ( ) ) ;
264+ res. activated_flags . push ( entry. to_owned ( ) ) ;
263265 }
264266
265267 res
@@ -273,35 +275,34 @@ impl MiniCore {
273275 let raw_mini_core = include_str ! ( "./minicore.rs" ) ;
274276 let mut lines = raw_mini_core. split_inclusive ( '\n' ) ;
275277
276- let mut parsing_flags = false ;
277278 let mut implications = Vec :: new ( ) ;
278279
279280 // 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
300286 }
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+ }
301303
302- if line. contains ( "Available flags:" ) {
303- parsing_flags = true ;
304- }
304+ for ( _, dep) in & implications {
305+ self . assert_valid_flag ( dep) ;
305306 }
306307
307308 for flag in & self . activated_flags {
@@ -332,7 +333,7 @@ impl MiniCore {
332333 }
333334 if let Some ( region) = trimmed. strip_prefix ( "// endregion:" ) {
334335 let prev = active_regions. pop ( ) . unwrap ( ) ;
335- assert_eq ! ( prev, region) ;
336+ assert_eq ! ( prev, region, "unbalanced region pairs" ) ;
336337 continue ;
337338 }
338339
0 commit comments