@@ -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 :: edition:: { Edition , parse_edition} ;
2021use crate :: errors:: ErrorKind ;
@@ -25,6 +26,7 @@ use crate::{fatal, help};
2526pub ( crate ) mod auxiliary;
2627mod cfg;
2728mod directive_names;
29+ mod line;
2830mod needs;
2931#[ cfg( test) ]
3032mod tests;
@@ -824,70 +826,6 @@ impl TestProps {
824826 }
825827}
826828
827- /// If the given line begins with the appropriate comment prefix for a directive,
828- /// returns a struct containing various parts of the directive.
829- fn line_directive < ' line > (
830- line_number : usize ,
831- original_line : & ' line str ,
832- ) -> Option < DirectiveLine < ' line > > {
833- // Ignore lines that don't start with the comment prefix.
834- let after_comment =
835- original_line. trim_start ( ) . strip_prefix ( COMPILETEST_DIRECTIVE_PREFIX ) ?. trim_start ( ) ;
836-
837- let revision;
838- let raw_directive;
839-
840- if let Some ( after_open_bracket) = after_comment. strip_prefix ( '[' ) {
841- // A comment like `//@[foo]` only applies to revision `foo`.
842- let Some ( ( line_revision, after_close_bracket) ) = after_open_bracket. split_once ( ']' ) else {
843- panic ! (
844- "malformed condition directive: expected `{COMPILETEST_DIRECTIVE_PREFIX}[foo]`, found `{original_line}`"
845- )
846- } ;
847-
848- revision = Some ( line_revision) ;
849- raw_directive = after_close_bracket. trim_start ( ) ;
850- } else {
851- revision = None ;
852- raw_directive = after_comment;
853- } ;
854-
855- Some ( DirectiveLine { line_number, revision, raw_directive } )
856- }
857-
858- /// The (partly) broken-down contents of a line containing a test directive,
859- /// which [`iter_directives`] passes to its callback function.
860- ///
861- /// For example:
862- ///
863- /// ```text
864- /// //@ compile-flags: -O
865- /// ^^^^^^^^^^^^^^^^^ raw_directive
866- ///
867- /// //@ [foo] compile-flags: -O
868- /// ^^^ revision
869- /// ^^^^^^^^^^^^^^^^^ raw_directive
870- /// ```
871- struct DirectiveLine < ' ln > {
872- line_number : usize ,
873- /// Some test directives start with a revision name in square brackets
874- /// (e.g. `[foo]`), and only apply to that revision of the test.
875- /// If present, this field contains the revision name (e.g. `foo`).
876- revision : Option < & ' ln str > ,
877- /// The main part of the directive, after removing the comment prefix
878- /// and the optional revision specifier.
879- ///
880- /// This is "raw" because the directive's name and colon-separated value
881- /// (if present) have not yet been extracted or checked.
882- raw_directive : & ' ln str ,
883- }
884-
885- impl < ' ln > DirectiveLine < ' ln > {
886- fn applies_to_test_revision ( & self , test_revision : Option < & str > ) -> bool {
887- self . revision . is_none ( ) || self . revision == test_revision
888- }
889- }
890-
891829pub ( crate ) struct CheckDirectiveResult < ' ln > {
892830 is_known_directive : bool ,
893831 trailing_directive : Option < & ' ln str > ,
@@ -920,8 +858,6 @@ fn check_directive<'a>(
920858 CheckDirectiveResult { is_known_directive, trailing_directive }
921859}
922860
923- const COMPILETEST_DIRECTIVE_PREFIX : & str = "//@" ;
924-
925861fn iter_directives (
926862 mode : TestMode ,
927863 poisoned : & mut bool ,
0 commit comments