@@ -14,6 +14,7 @@ use crate::directives::directive_names::{
1414 KNOWN_DIRECTIVE_NAMES , KNOWN_HTMLDOCCK_DIRECTIVE_NAMES , KNOWN_JSONDOCCK_DIRECTIVE_NAMES ,
1515} ;
1616pub ( crate ) use crate :: directives:: file:: FileDirectives ;
17+ use crate :: directives:: handlers:: DIRECTIVE_HANDLERS_MAP ;
1718use crate :: directives:: line:: { DirectiveLine , line_directive} ;
1819use crate :: directives:: needs:: CachedNeedsConditions ;
1920use crate :: edition:: { Edition , parse_edition} ;
@@ -26,6 +27,7 @@ mod auxiliary;
2627mod cfg;
2728mod directive_names;
2829mod file;
30+ mod handlers;
2931mod line;
3032mod needs;
3133#[ cfg( test) ]
@@ -369,269 +371,9 @@ impl TestProps {
369371 return ;
370372 }
371373
372- use directives:: * ;
373-
374- config. push_name_value_directive (
375- ln,
376- ERROR_PATTERN ,
377- & mut self . error_patterns ,
378- |r| r,
379- ) ;
380- config. push_name_value_directive (
381- ln,
382- REGEX_ERROR_PATTERN ,
383- & mut self . regex_error_patterns ,
384- |r| r,
385- ) ;
386-
387- config. push_name_value_directive ( ln, DOC_FLAGS , & mut self . doc_flags , |r| r) ;
388-
389- fn split_flags ( flags : & str ) -> Vec < String > {
390- // Individual flags can be single-quoted to preserve spaces; see
391- // <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
392- flags
393- . split ( '\'' )
394- . enumerate ( )
395- . flat_map ( |( i, f) | {
396- if i % 2 == 1 { vec ! [ f] } else { f. split_whitespace ( ) . collect ( ) }
397- } )
398- . map ( move |s| s. to_owned ( ) )
399- . collect :: < Vec < _ > > ( )
400- }
401-
402- if let Some ( flags) = config. parse_name_value_directive ( ln, COMPILE_FLAGS ) {
403- let flags = split_flags ( & flags) ;
404- for ( i, flag) in flags. iter ( ) . enumerate ( ) {
405- if flag == "--edition" || flag. starts_with ( "--edition=" ) {
406- panic ! ( "you must use `//@ edition` to configure the edition" ) ;
407- }
408- if ( flag == "-C"
409- && flags. get ( i + 1 ) . is_some_and ( |v| v. starts_with ( "incremental=" ) ) )
410- || flag. starts_with ( "-Cincremental=" )
411- {
412- panic ! (
413- "you must use `//@ incremental` to enable incremental compilation"
414- ) ;
415- }
416- }
417- self . compile_flags . extend ( flags) ;
418- }
419-
420- if let Some ( range) = parse_edition_range ( config, ln) {
421- self . edition = Some ( range. edition_to_test ( config. edition ) ) ;
422- }
423-
424- config. parse_and_update_revisions ( ln, & mut self . revisions ) ;
425-
426- if let Some ( flags) = config. parse_name_value_directive ( ln, RUN_FLAGS ) {
427- self . run_flags . extend ( split_flags ( & flags) ) ;
428- }
429-
430- if self . pp_exact . is_none ( ) {
431- self . pp_exact = config. parse_pp_exact ( ln) ;
432- }
433-
434- config. set_name_directive ( ln, SHOULD_ICE , & mut self . should_ice ) ;
435- config. set_name_directive ( ln, BUILD_AUX_DOCS , & mut self . build_aux_docs ) ;
436- config. set_name_directive ( ln, UNIQUE_DOC_OUT_DIR , & mut self . unique_doc_out_dir ) ;
437-
438- config. set_name_directive ( ln, FORCE_HOST , & mut self . force_host ) ;
439- config. set_name_directive ( ln, CHECK_STDOUT , & mut self . check_stdout ) ;
440- config. set_name_directive ( ln, CHECK_RUN_RESULTS , & mut self . check_run_results ) ;
441- config. set_name_directive (
442- ln,
443- DONT_CHECK_COMPILER_STDOUT ,
444- & mut self . dont_check_compiler_stdout ,
445- ) ;
446- config. set_name_directive (
447- ln,
448- DONT_CHECK_COMPILER_STDERR ,
449- & mut self . dont_check_compiler_stderr ,
450- ) ;
451- config. set_name_directive ( ln, NO_PREFER_DYNAMIC , & mut self . no_prefer_dynamic ) ;
452-
453- if let Some ( m) = config. parse_name_value_directive ( ln, PRETTY_MODE ) {
454- self . pretty_mode = m;
455- }
456-
457- config. set_name_directive (
458- ln,
459- PRETTY_COMPARE_ONLY ,
460- & mut self . pretty_compare_only ,
461- ) ;
462-
463- // Call a helper method to deal with aux-related directives.
464- parse_and_update_aux ( config, ln, & mut self . aux ) ;
465-
466- config. push_name_value_directive (
467- ln,
468- EXEC_ENV ,
469- & mut self . exec_env ,
470- Config :: parse_env,
471- ) ;
472- config. push_name_value_directive (
473- ln,
474- UNSET_EXEC_ENV ,
475- & mut self . unset_exec_env ,
476- |r| r. trim ( ) . to_owned ( ) ,
477- ) ;
478- config. push_name_value_directive (
479- ln,
480- RUSTC_ENV ,
481- & mut self . rustc_env ,
482- Config :: parse_env,
483- ) ;
484- config. push_name_value_directive (
485- ln,
486- UNSET_RUSTC_ENV ,
487- & mut self . unset_rustc_env ,
488- |r| r. trim ( ) . to_owned ( ) ,
489- ) ;
490- config. push_name_value_directive (
491- ln,
492- FORBID_OUTPUT ,
493- & mut self . forbid_output ,
494- |r| r,
495- ) ;
496- config. set_name_directive (
497- ln,
498- CHECK_TEST_LINE_NUMBERS_MATCH ,
499- & mut self . check_test_line_numbers_match ,
500- ) ;
501-
502- self . update_pass_mode ( ln, config) ;
503- self . update_fail_mode ( ln, config) ;
504-
505- config. set_name_directive ( ln, IGNORE_PASS , & mut self . ignore_pass ) ;
506-
507- if let Some ( NormalizeRule { kind, regex, replacement } ) =
508- config. parse_custom_normalization ( ln)
509- {
510- let rule_tuple = ( regex, replacement) ;
511- match kind {
512- NormalizeKind :: Stdout => self . normalize_stdout . push ( rule_tuple) ,
513- NormalizeKind :: Stderr => self . normalize_stderr . push ( rule_tuple) ,
514- NormalizeKind :: Stderr32bit => {
515- if config. target_cfg ( ) . pointer_width == 32 {
516- self . normalize_stderr . push ( rule_tuple) ;
517- }
518- }
519- NormalizeKind :: Stderr64bit => {
520- if config. target_cfg ( ) . pointer_width == 64 {
521- self . normalize_stderr . push ( rule_tuple) ;
522- }
523- }
524- }
525- }
526-
527- if let Some ( code) = config
528- . parse_name_value_directive ( ln, FAILURE_STATUS )
529- . and_then ( |code| code. trim ( ) . parse :: < i32 > ( ) . ok ( ) )
530- {
531- self . failure_status = Some ( code) ;
532- }
533-
534- config. set_name_directive (
535- ln,
536- DONT_CHECK_FAILURE_STATUS ,
537- & mut self . dont_check_failure_status ,
538- ) ;
539-
540- config. set_name_directive ( ln, RUN_RUSTFIX , & mut self . run_rustfix ) ;
541- config. set_name_directive (
542- ln,
543- RUSTFIX_ONLY_MACHINE_APPLICABLE ,
544- & mut self . rustfix_only_machine_applicable ,
545- ) ;
546- config. set_name_value_directive (
547- ln,
548- ASSEMBLY_OUTPUT ,
549- & mut self . assembly_output ,
550- |r| r. trim ( ) . to_string ( ) ,
551- ) ;
552- config. set_name_directive (
553- ln,
554- STDERR_PER_BITWIDTH ,
555- & mut self . stderr_per_bitwidth ,
556- ) ;
557- config. set_name_directive ( ln, INCREMENTAL , & mut self . incremental ) ;
558-
559- // Unlike the other `name_value_directive`s this needs to be handled manually,
560- // because it sets a `bool` flag.
561- if let Some ( known_bug) = config. parse_name_value_directive ( ln, KNOWN_BUG ) {
562- let known_bug = known_bug. trim ( ) ;
563- if known_bug == "unknown"
564- || known_bug. split ( ',' ) . all ( |issue_ref| {
565- issue_ref
566- . trim ( )
567- . split_once ( '#' )
568- . filter ( |( _, number) | {
569- number. chars ( ) . all ( |digit| digit. is_numeric ( ) )
570- } )
571- . is_some ( )
572- } )
573- {
574- self . known_bug = true ;
575- } else {
576- panic ! (
577- "Invalid known-bug value: {known_bug}\n It requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`."
578- ) ;
579- }
580- } else if config. parse_name_directive ( ln, KNOWN_BUG ) {
581- panic ! (
582- "Invalid known-bug attribute, requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`."
583- ) ;
584- }
585-
586- config. set_name_value_directive (
587- ln,
588- TEST_MIR_PASS ,
589- & mut self . mir_unit_test ,
590- |s| s. trim ( ) . to_string ( ) ,
591- ) ;
592- config. set_name_directive ( ln, REMAP_SRC_BASE , & mut self . remap_src_base ) ;
593-
594- if let Some ( flags) = config. parse_name_value_directive ( ln, LLVM_COV_FLAGS ) {
595- self . llvm_cov_flags . extend ( split_flags ( & flags) ) ;
596- }
597-
598- if let Some ( flags) = config. parse_name_value_directive ( ln, FILECHECK_FLAGS ) {
599- self . filecheck_flags . extend ( split_flags ( & flags) ) ;
600- }
601-
602- config. set_name_directive ( ln, NO_AUTO_CHECK_CFG , & mut self . no_auto_check_cfg ) ;
603-
604- self . update_add_core_stubs ( ln, config) ;
605-
606- if let Some ( flags) =
607- config. parse_name_value_directive ( ln, CORE_STUBS_COMPILE_FLAGS )
608- {
609- let flags = split_flags ( & flags) ;
610- for flag in & flags {
611- if flag == "--edition" || flag. starts_with ( "--edition=" ) {
612- panic ! ( "you must use `//@ edition` to configure the edition" ) ;
613- }
614- }
615- self . core_stubs_compile_flags . extend ( flags) ;
374+ if let Some ( handler) = DIRECTIVE_HANDLERS_MAP . get ( ln. name ) {
375+ handler. handle ( config, ln, self ) ;
616376 }
617-
618- if let Some ( err_kind) =
619- config. parse_name_value_directive ( ln, DONT_REQUIRE_ANNOTATIONS )
620- {
621- self . dont_require_annotations
622- . insert ( ErrorKind :: expect_from_user_str ( err_kind. trim ( ) ) ) ;
623- }
624-
625- config. set_name_directive (
626- ln,
627- DISABLE_GDB_PRETTY_PRINTERS ,
628- & mut self . disable_gdb_pretty_printers ,
629- ) ;
630- config. set_name_directive (
631- ln,
632- COMPARE_OUTPUT_BY_LINES ,
633- & mut self . compare_output_by_lines ,
634- ) ;
635377 } ,
636378 ) ;
637379
@@ -1716,3 +1458,14 @@ impl EditionRange {
17161458 }
17171459 }
17181460}
1461+
1462+ fn split_flags ( flags : & str ) -> Vec < String > {
1463+ // Individual flags can be single-quoted to preserve spaces; see
1464+ // <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
1465+ flags
1466+ . split ( '\'' )
1467+ . enumerate ( )
1468+ . flat_map ( |( i, f) | if i % 2 == 1 { vec ! [ f] } else { f. split_whitespace ( ) . collect ( ) } )
1469+ . map ( move |s| s. to_owned ( ) )
1470+ . collect :: < Vec < _ > > ( )
1471+ }
0 commit comments