@@ -935,16 +935,25 @@ 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
940- // Returns `(is_known_directive, directive_name)`.
941941pub ( 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) ;
944952
945953 CheckDirectiveResult {
946954 is_known_directive : KNOWN_DIRECTIVE_NAMES . contains ( & directive_name) ,
947955 directive_name : directive_ln,
956+ trailing_directive,
948957 }
949958}
950959
@@ -1014,7 +1023,8 @@ fn iter_header(
10141023 if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
10151024 let directive_ln = non_revisioned_directive_line. trim ( ) ;
10161025
1017- let CheckDirectiveResult { is_known_directive, .. } = check_directive ( directive_ln) ;
1026+ let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
1027+ check_directive ( directive_ln) ;
10181028
10191029 if !is_known_directive {
10201030 * poisoned = true ;
@@ -1028,6 +1038,21 @@ fn iter_header(
10281038
10291039 return ;
10301040 }
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+ }
10311056 }
10321057
10331058 it ( HeaderLine {
@@ -1051,7 +1076,8 @@ fn iter_header(
10511076
10521077 let rest = rest. trim_start ( ) ;
10531078
1054- let CheckDirectiveResult { is_known_directive, directive_name } = check_directive ( rest) ;
1079+ let CheckDirectiveResult { is_known_directive, directive_name, .. } =
1080+ check_directive ( rest) ;
10551081
10561082 if is_known_directive {
10571083 * poisoned = true ;
0 commit comments