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