@@ -935,16 +935,26 @@ struct HeaderLine<'ln> {
935
935
pub ( crate ) struct CheckDirectiveResult < ' ln > {
936
936
is_known_directive : bool ,
937
937
directive_name : & ' ln str ,
938
+ trailing_directive : Option < & ' ln str > ,
938
939
}
939
940
940
941
// Returns `(is_known_directive, directive_name)`.
941
942
pub ( crate ) fn check_directive ( directive_ln : & str ) -> CheckDirectiveResult < ' _ > {
942
- let directive_name =
943
- directive_ln. split_once ( [ ':' , ' ' ] ) . map ( |( pre, _) | pre) . unwrap_or ( directive_ln) ;
943
+ let ( directive_name, post) = directive_ln. split_once ( [ ':' , ' ' ] ) . unwrap_or ( ( directive_ln, "" ) ) ;
944
+
945
+ let trailing = post. trim ( ) . split_once ( ' ' ) . map ( |( pre, _) | pre) . unwrap_or ( post) ;
946
+ let trailing_directive = {
947
+ // 1. is the directive name followed by a space? (to exclude `:`)
948
+ matches ! ( directive_ln. get( directive_name. len( ) ..) , Some ( s) if s. starts_with( " " ) )
949
+ // 2. is what is after that directive also a directive (ex: "only-x86 only-arm")
950
+ && KNOWN_DIRECTIVE_NAMES . contains ( & trailing)
951
+ }
952
+ . then_some ( trailing) ;
944
953
945
954
CheckDirectiveResult {
946
955
is_known_directive : KNOWN_DIRECTIVE_NAMES . contains ( & directive_name) ,
947
956
directive_name : directive_ln,
957
+ trailing_directive,
948
958
}
949
959
}
950
960
@@ -1014,7 +1024,8 @@ fn iter_header(
1014
1024
if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
1015
1025
let directive_ln = non_revisioned_directive_line. trim ( ) ;
1016
1026
1017
- let CheckDirectiveResult { is_known_directive, .. } = check_directive ( directive_ln) ;
1027
+ let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
1028
+ check_directive ( directive_ln) ;
1018
1029
1019
1030
if !is_known_directive {
1020
1031
* poisoned = true ;
@@ -1028,6 +1039,19 @@ fn iter_header(
1028
1039
1029
1040
return ;
1030
1041
}
1042
+
1043
+ if let Some ( trailing_directive) = & trailing_directive {
1044
+ * poisoned = true ;
1045
+
1046
+ eprintln ! (
1047
+ "error: detected trailing compiletest test directive `{}` in {}:{}" ,
1048
+ trailing_directive,
1049
+ testfile. display( ) ,
1050
+ line_number,
1051
+ ) ;
1052
+
1053
+ return ;
1054
+ }
1031
1055
}
1032
1056
1033
1057
it ( HeaderLine {
@@ -1051,7 +1075,8 @@ fn iter_header(
1051
1075
1052
1076
let rest = rest. trim_start ( ) ;
1053
1077
1054
- let CheckDirectiveResult { is_known_directive, directive_name } = check_directive ( rest) ;
1078
+ let CheckDirectiveResult { is_known_directive, directive_name, trailing_directive : _ } =
1079
+ check_directive ( rest) ;
1055
1080
1056
1081
if is_known_directive {
1057
1082
* poisoned = true ;
0 commit comments