@@ -57,7 +57,7 @@ impl EarlyProps {
57
57
& mut poisoned,
58
58
testfile,
59
59
rdr,
60
- & mut |DirectiveLine { directive : ln, .. } | {
60
+ & mut |DirectiveLine { raw_directive : ln, .. } | {
61
61
parse_and_update_aux ( config, ln, & mut props. aux ) ;
62
62
config. parse_and_update_revisions ( testfile, ln, & mut props. revisions ) ;
63
63
} ,
@@ -344,8 +344,8 @@ impl TestProps {
344
344
& mut poisoned,
345
345
testfile,
346
346
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) {
349
349
return ;
350
350
}
351
351
@@ -678,28 +678,35 @@ impl TestProps {
678
678
}
679
679
}
680
680
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 ,
685
685
comment : & str ,
686
686
original_line : & ' line str ,
687
- ) -> Option < ( Option < & ' line str > , & ' line str ) > {
687
+ ) -> Option < DirectiveLine < ' line > > {
688
688
// Ignore lines that don't start with the comment prefix.
689
689
let after_comment = original_line. trim_start ( ) . strip_prefix ( comment) ?. trim_start ( ) ;
690
690
691
+ let revision;
692
+ let raw_directive;
693
+
691
694
if let Some ( after_open_bracket) = after_comment. strip_prefix ( '[' ) {
692
695
// 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 {
694
697
panic ! (
695
698
"malformed condition directive: expected `{comment}[foo]`, found `{original_line}`"
696
699
)
697
700
} ;
698
701
699
- Some ( ( Some ( line_revision) , directive. trim_start ( ) ) )
702
+ revision = Some ( line_revision) ;
703
+ raw_directive = after_close_bracket. trim_start ( ) ;
700
704
} 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 } )
703
710
}
704
711
705
712
// To prevent duplicating the list of commmands between `compiletest`,`htmldocck` and `jsondocck`,
@@ -730,28 +737,37 @@ const KNOWN_HTMLDOCCK_DIRECTIVE_NAMES: &[&str] = &[
730
737
const KNOWN_JSONDOCCK_DIRECTIVE_NAMES : & [ & str ] =
731
738
& [ "count" , "!count" , "has" , "!has" , "is" , "!is" , "ismany" , "!ismany" , "set" , "!set" ] ;
732
739
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,
734
741
/// which [`iter_header`] passes to its callback function.
735
742
///
736
743
/// For example:
737
744
///
738
745
/// ```text
739
746
/// //@ compile-flags: -O
740
- /// ^^^^^^^^^^^^^^^^^ directive
747
+ /// ^^^^^^^^^^^^^^^^^ raw_directive
741
748
///
742
749
/// //@ [foo] compile-flags: -O
743
- /// ^^^ header_revision
744
- /// ^^^^^^^^^^^^^^^^^ directive
750
+ /// ^^^ revision
751
+ /// ^^^^^^^^^^^^^^^^^ raw_directive
745
752
/// ```
746
753
struct DirectiveLine < ' ln > {
747
754
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
749
756
/// (e.g. `[foo]`), and only apply to that revision of the test.
750
757
/// 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
753
760
/// 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
+ }
755
771
}
756
772
757
773
pub ( crate ) struct CheckDirectiveResult < ' ln > {
@@ -819,8 +835,8 @@ fn iter_header(
819
835
"ignore-cross-compile" ,
820
836
] ;
821
837
// 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 } ) ;
824
840
}
825
841
}
826
842
@@ -847,24 +863,21 @@ fn iter_header(
847
863
return ;
848
864
}
849
865
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 {
852
867
continue ;
853
868
} ;
854
869
855
870
// Perform unknown directive check on Rust files.
856
871
if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
857
- let directive_ln = non_revisioned_directive_line. trim ( ) ;
858
-
859
872
let CheckDirectiveResult { is_known_directive, trailing_directive } =
860
- check_directive ( directive_ln , mode, ln) ;
873
+ check_directive ( directive_line . raw_directive , mode, ln) ;
861
874
862
875
if !is_known_directive {
863
876
* poisoned = true ;
864
877
865
878
eprintln ! (
866
879
"error: detected unknown compiletest test directive `{}` in {}:{}" ,
867
- directive_ln ,
880
+ directive_line . raw_directive ,
868
881
testfile. display( ) ,
869
882
line_number,
870
883
) ;
@@ -888,11 +901,7 @@ fn iter_header(
888
901
}
889
902
}
890
903
891
- it ( DirectiveLine {
892
- line_number,
893
- header_revision,
894
- directive : non_revisioned_directive_line,
895
- } ) ;
904
+ it ( directive_line) ;
896
905
}
897
906
}
898
907
@@ -1292,8 +1301,8 @@ pub fn make_test_description<R: Read>(
1292
1301
& mut local_poisoned,
1293
1302
path,
1294
1303
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) {
1297
1306
return ;
1298
1307
}
1299
1308
0 commit comments