@@ -57,7 +57,7 @@ impl EarlyProps {
5757 & mut poisoned,
5858 testfile,
5959 rdr,
60- & mut |DirectiveLine { directive : ln, .. } | {
60+ & mut |DirectiveLine { raw_directive : ln, .. } | {
6161 parse_and_update_aux ( config, ln, & mut props. aux ) ;
6262 config. parse_and_update_revisions ( testfile, ln, & mut props. revisions ) ;
6363 } ,
@@ -344,8 +344,8 @@ impl TestProps {
344344 & mut poisoned,
345345 testfile,
346346 file,
347- & mut |DirectiveLine { header_revision , directive : ln, .. } | {
348- if header_revision . is_some ( ) && header_revision != test_revision {
347+ & mut |directive @ DirectiveLine { raw_directive : ln, .. } | {
348+ if !directive . applies_to_test_revision ( test_revision) {
349349 return ;
350350 }
351351
@@ -678,28 +678,35 @@ impl TestProps {
678678 }
679679}
680680
681- /// Extract an `(Option<line_revision>, directive)` directive from a line if comment is present.
682- ///
683- /// See [`DirectiveLine`] for a diagram.
684- pub fn line_directive < ' line > (
681+ /// If the given line begins with the appropriate comment prefix for a directive,
682+ /// returns a struct containing various parts of the directive.
683+ fn line_directive < ' line > (
684+ line_number : usize ,
685685 comment : & str ,
686686 original_line : & ' line str ,
687- ) -> Option < ( Option < & ' line str > , & ' line str ) > {
687+ ) -> Option < DirectiveLine < ' line > > {
688688 // Ignore lines that don't start with the comment prefix.
689689 let after_comment = original_line. trim_start ( ) . strip_prefix ( comment) ?. trim_start ( ) ;
690690
691+ let revision;
692+ let raw_directive;
693+
691694 if let Some ( after_open_bracket) = after_comment. strip_prefix ( '[' ) {
692695 // A comment like `//@[foo]` only applies to revision `foo`.
693- let Some ( ( line_revision, directive ) ) = after_open_bracket. split_once ( ']' ) else {
696+ let Some ( ( line_revision, after_close_bracket ) ) = after_open_bracket. split_once ( ']' ) else {
694697 panic ! (
695698 "malformed condition directive: expected `{comment}[foo]`, found `{original_line}`"
696699 )
697700 } ;
698701
699- Some ( ( Some ( line_revision) , directive. trim_start ( ) ) )
702+ revision = Some ( line_revision) ;
703+ raw_directive = after_close_bracket. trim_start ( ) ;
700704 } else {
701- Some ( ( None , after_comment) )
702- }
705+ revision = None ;
706+ raw_directive = after_comment;
707+ } ;
708+
709+ Some ( DirectiveLine { line_number, revision, raw_directive } )
703710}
704711
705712// To prevent duplicating the list of commmands between `compiletest`,`htmldocck` and `jsondocck`,
@@ -730,28 +737,37 @@ const KNOWN_HTMLDOCCK_DIRECTIVE_NAMES: &[&str] = &[
730737const KNOWN_JSONDOCCK_DIRECTIVE_NAMES : & [ & str ] =
731738 & [ "count" , "!count" , "has" , "!has" , "is" , "!is" , "ismany" , "!ismany" , "set" , "!set" ] ;
732739
733- /// The broken-down contents of a line containing a test header directive,
740+ /// The (partly) broken-down contents of a line containing a test directive,
734741/// which [`iter_header`] passes to its callback function.
735742///
736743/// For example:
737744///
738745/// ```text
739746/// //@ compile-flags: -O
740- /// ^^^^^^^^^^^^^^^^^ directive
747+ /// ^^^^^^^^^^^^^^^^^ raw_directive
741748///
742749/// //@ [foo] compile-flags: -O
743- /// ^^^ header_revision
744- /// ^^^^^^^^^^^^^^^^^ directive
750+ /// ^^^ revision
751+ /// ^^^^^^^^^^^^^^^^^ raw_directive
745752/// ```
746753struct DirectiveLine < ' ln > {
747754 line_number : usize ,
748- /// Some header directives start with a revision name in square brackets
755+ /// Some test directives start with a revision name in square brackets
749756 /// (e.g. `[foo]`), and only apply to that revision of the test.
750757 /// If present, this field contains the revision name (e.g. `foo`).
751- header_revision : Option < & ' ln str > ,
752- /// The main part of the header directive, after removing the comment prefix
758+ revision : Option < & ' ln str > ,
759+ /// The main part of the directive, after removing the comment prefix
753760 /// and the optional revision specifier.
754- directive : & ' ln str ,
761+ ///
762+ /// This is "raw" because the directive's name and colon-separated value
763+ /// (if present) have not yet been extracted or checked.
764+ raw_directive : & ' ln str ,
765+ }
766+
767+ impl < ' ln > DirectiveLine < ' ln > {
768+ fn applies_to_test_revision ( & self , test_revision : Option < & str > ) -> bool {
769+ self . revision . is_none ( ) || self . revision == test_revision
770+ }
755771}
756772
757773pub ( crate ) struct CheckDirectiveResult < ' ln > {
@@ -819,8 +835,8 @@ fn iter_header(
819835 "ignore-cross-compile" ,
820836 ] ;
821837 // Process the extra implied directives, with a dummy line number of 0.
822- for directive in extra_directives {
823- it ( DirectiveLine { line_number : 0 , header_revision : None , directive } ) ;
838+ for raw_directive in extra_directives {
839+ it ( DirectiveLine { line_number : 0 , revision : None , raw_directive } ) ;
824840 }
825841 }
826842
@@ -847,24 +863,21 @@ fn iter_header(
847863 return ;
848864 }
849865
850- let Some ( ( header_revision, non_revisioned_directive_line) ) = line_directive ( comment, ln)
851- else {
866+ let Some ( directive_line) = line_directive ( line_number, comment, ln) else {
852867 continue ;
853868 } ;
854869
855870 // Perform unknown directive check on Rust files.
856871 if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
857- let directive_ln = non_revisioned_directive_line. trim ( ) ;
858-
859872 let CheckDirectiveResult { is_known_directive, trailing_directive } =
860- check_directive ( directive_ln , mode, ln) ;
873+ check_directive ( directive_line . raw_directive , mode, ln) ;
861874
862875 if !is_known_directive {
863876 * poisoned = true ;
864877
865878 eprintln ! (
866879 "error: detected unknown compiletest test directive `{}` in {}:{}" ,
867- directive_ln ,
880+ directive_line . raw_directive ,
868881 testfile. display( ) ,
869882 line_number,
870883 ) ;
@@ -888,11 +901,7 @@ fn iter_header(
888901 }
889902 }
890903
891- it ( DirectiveLine {
892- line_number,
893- header_revision,
894- directive : non_revisioned_directive_line,
895- } ) ;
904+ it ( directive_line) ;
896905 }
897906}
898907
@@ -1292,8 +1301,8 @@ pub fn make_test_description<R: Read>(
12921301 & mut local_poisoned,
12931302 path,
12941303 src,
1295- & mut |DirectiveLine { header_revision , directive : ln, line_number } | {
1296- if header_revision . is_some ( ) && header_revision != test_revision {
1304+ & mut |directive @ DirectiveLine { line_number , raw_directive : ln, .. } | {
1305+ if !directive . applies_to_test_revision ( test_revision) {
12971306 return ;
12981307 }
12991308
0 commit comments