@@ -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`,
@@ -856,23 +863,21 @@ fn iter_header(
856
863
return ;
857
864
}
858
865
859
- let Some ( ( revision , raw_directive ) ) = line_directive ( comment, ln) else {
866
+ let Some ( directive_line ) = line_directive ( line_number , comment, ln) else {
860
867
continue ;
861
868
} ;
862
869
863
870
// Perform unknown directive check on Rust files.
864
871
if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
865
- let directive_ln = raw_directive. trim ( ) ;
866
-
867
872
let CheckDirectiveResult { is_known_directive, trailing_directive } =
868
- check_directive ( directive_ln , mode, ln) ;
873
+ check_directive ( directive_line . raw_directive , mode, ln) ;
869
874
870
875
if !is_known_directive {
871
876
* poisoned = true ;
872
877
873
878
eprintln ! (
874
879
"error: detected unknown compiletest test directive `{}` in {}:{}" ,
875
- directive_ln ,
880
+ directive_line . raw_directive ,
876
881
testfile. display( ) ,
877
882
line_number,
878
883
) ;
@@ -896,7 +901,7 @@ fn iter_header(
896
901
}
897
902
}
898
903
899
- it ( DirectiveLine { line_number , revision , raw_directive } ) ;
904
+ it ( directive_line ) ;
900
905
}
901
906
}
902
907
0 commit comments