@@ -935,16 +935,26 @@ struct HeaderLine<'ln> {
935935pub ( crate ) struct CheckDirectiveResult < ' ln > {
936936 is_known_directive : bool ,
937937 directive_name : & ' ln str ,
938+ trailing_directive : Option < & ' ln str > ,
938939}
939940
940941// Returns `(is_known_directive, directive_name)`.
941942pub ( 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) ;
944953
945954 CheckDirectiveResult {
946955 is_known_directive : KNOWN_DIRECTIVE_NAMES . contains ( & directive_name) ,
947956 directive_name : directive_ln,
957+ trailing_directive,
948958 }
949959}
950960
@@ -1014,7 +1024,8 @@ fn iter_header(
10141024 if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
10151025 let directive_ln = non_revisioned_directive_line. trim ( ) ;
10161026
1017- let CheckDirectiveResult { is_known_directive, .. } = check_directive ( directive_ln) ;
1027+ let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
1028+ check_directive ( directive_ln) ;
10181029
10191030 if !is_known_directive {
10201031 * poisoned = true ;
@@ -1028,6 +1039,19 @@ fn iter_header(
10281039
10291040 return ;
10301041 }
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+ }
10311055 }
10321056
10331057 it ( HeaderLine {
@@ -1051,7 +1075,8 @@ fn iter_header(
10511075
10521076 let rest = rest. trim_start ( ) ;
10531077
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) ;
10551080
10561081 if is_known_directive {
10571082 * poisoned = true ;
0 commit comments