@@ -15,6 +15,7 @@ use crate::directives::auxiliary::{AuxProps, parse_and_update_aux};
1515use crate :: directives:: directive_names:: {
1616 KNOWN_DIRECTIVE_NAMES , KNOWN_HTMLDOCCK_DIRECTIVE_NAMES , KNOWN_JSONDOCCK_DIRECTIVE_NAMES ,
1717} ;
18+ use crate :: directives:: line:: { DirectiveLine , line_directive} ;
1819use crate :: directives:: needs:: CachedNeedsConditions ;
1920use crate :: errors:: ErrorKind ;
2021use crate :: executor:: { CollectedTestDesc , ShouldPanic } ;
@@ -24,6 +25,7 @@ use crate::util::static_regex;
2425pub ( crate ) mod auxiliary;
2526mod cfg;
2627mod directive_names;
28+ mod line;
2729mod needs;
2830#[ cfg( test) ]
2931mod tests;
@@ -820,70 +822,6 @@ impl TestProps {
820822 }
821823}
822824
823- /// If the given line begins with the appropriate comment prefix for a directive,
824- /// returns a struct containing various parts of the directive.
825- fn line_directive < ' line > (
826- line_number : usize ,
827- original_line : & ' line str ,
828- ) -> Option < DirectiveLine < ' line > > {
829- // Ignore lines that don't start with the comment prefix.
830- let after_comment =
831- original_line. trim_start ( ) . strip_prefix ( COMPILETEST_DIRECTIVE_PREFIX ) ?. trim_start ( ) ;
832-
833- let revision;
834- let raw_directive;
835-
836- if let Some ( after_open_bracket) = after_comment. strip_prefix ( '[' ) {
837- // A comment like `//@[foo]` only applies to revision `foo`.
838- let Some ( ( line_revision, after_close_bracket) ) = after_open_bracket. split_once ( ']' ) else {
839- panic ! (
840- "malformed condition directive: expected `{COMPILETEST_DIRECTIVE_PREFIX}[foo]`, found `{original_line}`"
841- )
842- } ;
843-
844- revision = Some ( line_revision) ;
845- raw_directive = after_close_bracket. trim_start ( ) ;
846- } else {
847- revision = None ;
848- raw_directive = after_comment;
849- } ;
850-
851- Some ( DirectiveLine { line_number, revision, raw_directive } )
852- }
853-
854- /// The (partly) broken-down contents of a line containing a test directive,
855- /// which [`iter_directives`] passes to its callback function.
856- ///
857- /// For example:
858- ///
859- /// ```text
860- /// //@ compile-flags: -O
861- /// ^^^^^^^^^^^^^^^^^ raw_directive
862- ///
863- /// //@ [foo] compile-flags: -O
864- /// ^^^ revision
865- /// ^^^^^^^^^^^^^^^^^ raw_directive
866- /// ```
867- struct DirectiveLine < ' ln > {
868- line_number : usize ,
869- /// Some test directives start with a revision name in square brackets
870- /// (e.g. `[foo]`), and only apply to that revision of the test.
871- /// If present, this field contains the revision name (e.g. `foo`).
872- revision : Option < & ' ln str > ,
873- /// The main part of the directive, after removing the comment prefix
874- /// and the optional revision specifier.
875- ///
876- /// This is "raw" because the directive's name and colon-separated value
877- /// (if present) have not yet been extracted or checked.
878- raw_directive : & ' ln str ,
879- }
880-
881- impl < ' ln > DirectiveLine < ' ln > {
882- fn applies_to_test_revision ( & self , test_revision : Option < & str > ) -> bool {
883- self . revision . is_none ( ) || self . revision == test_revision
884- }
885- }
886-
887825pub ( crate ) struct CheckDirectiveResult < ' ln > {
888826 is_known_directive : bool ,
889827 trailing_directive : Option < & ' ln str > ,
@@ -916,8 +854,6 @@ fn check_directive<'a>(
916854 CheckDirectiveResult { is_known_directive, trailing_directive }
917855}
918856
919- const COMPILETEST_DIRECTIVE_PREFIX : & str = "//@" ;
920-
921857fn iter_directives (
922858 mode : TestMode ,
923859 poisoned : & mut bool ,
0 commit comments