@@ -289,20 +289,20 @@ impl TestProps {
289
289
}
290
290
}
291
291
292
- pub fn from_aux_file ( & self , testfile : & Path , cfg : Option < & str > , config : & Config ) -> Self {
292
+ pub fn from_aux_file ( & self , testfile : & Path , revision : Option < & str > , config : & Config ) -> Self {
293
293
let mut props = TestProps :: new ( ) ;
294
294
295
295
// copy over select properties to the aux build:
296
296
props. incremental_dir = self . incremental_dir . clone ( ) ;
297
297
props. ignore_pass = true ;
298
- props. load_from ( testfile, cfg , config) ;
298
+ props. load_from ( testfile, revision , config) ;
299
299
300
300
props
301
301
}
302
302
303
- pub fn from_file ( testfile : & Path , cfg : Option < & str > , config : & Config ) -> Self {
303
+ pub fn from_file ( testfile : & Path , revision : Option < & str > , config : & Config ) -> Self {
304
304
let mut props = TestProps :: new ( ) ;
305
- props. load_from ( testfile, cfg , config) ;
305
+ props. load_from ( testfile, revision , config) ;
306
306
307
307
match ( props. pass_mode , props. fail_mode ) {
308
308
( None , None ) if config. mode == Mode :: Ui => props. fail_mode = Some ( FailMode :: Check ) ,
@@ -315,9 +315,9 @@ impl TestProps {
315
315
316
316
/// Loads properties from `testfile` into `props`. If a property is
317
317
/// tied to a particular revision `foo` (indicated by writing
318
- /// `//[foo]`), then the property is ignored unless `cfg ` is
318
+ /// `//@ [foo]`), then the property is ignored unless `test_revision ` is
319
319
/// `Some("foo")`.
320
- fn load_from ( & mut self , testfile : & Path , cfg : Option < & str > , config : & Config ) {
320
+ fn load_from ( & mut self , testfile : & Path , test_revision : Option < & str > , config : & Config ) {
321
321
let mut has_edition = false ;
322
322
if !testfile. is_dir ( ) {
323
323
let file = File :: open ( testfile) . unwrap ( ) ;
@@ -331,7 +331,7 @@ impl TestProps {
331
331
testfile,
332
332
file,
333
333
& mut |HeaderLine { header_revision, directive : ln, .. } | {
334
- if header_revision. is_some ( ) && header_revision != cfg {
334
+ if header_revision. is_some ( ) && header_revision != test_revision {
335
335
return ;
336
336
}
337
337
@@ -455,7 +455,7 @@ impl TestProps {
455
455
& mut self . check_test_line_numbers_match ,
456
456
) ;
457
457
458
- self . update_pass_mode ( ln, cfg , config) ;
458
+ self . update_pass_mode ( ln, test_revision , config) ;
459
459
self . update_fail_mode ( ln, config) ;
460
460
461
461
config. set_name_directive ( ln, IGNORE_PASS , & mut self . ignore_pass ) ;
@@ -645,30 +645,27 @@ impl TestProps {
645
645
}
646
646
}
647
647
648
- /// Extract a `(Option<line_config>, directive)` directive from a line if comment is present.
648
+ /// Extract an `(Option<line_revision>, directive)` directive from a line if comment is present.
649
+ ///
650
+ /// See [`HeaderLine`] for a diagram.
649
651
pub fn line_directive < ' line > (
650
652
comment : & str ,
651
- ln : & ' line str ,
653
+ original_line : & ' line str ,
652
654
) -> Option < ( Option < & ' line str > , & ' line str ) > {
653
- let ln = ln. trim_start ( ) ;
654
- if ln. starts_with ( comment) {
655
- let ln = ln[ comment. len ( ) ..] . trim_start ( ) ;
656
- if ln. starts_with ( '[' ) {
657
- // A comment like `//[foo]` is specific to revision `foo`
658
- let Some ( close_brace) = ln. find ( ']' ) else {
659
- panic ! (
660
- "malformed condition directive: expected `{}[foo]`, found `{}`" ,
661
- comment, ln
662
- ) ;
663
- } ;
655
+ // Ignore lines that don't start with the comment prefix.
656
+ let after_comment = original_line. trim_start ( ) . strip_prefix ( comment) ?. trim_start ( ) ;
657
+
658
+ if let Some ( after_open_bracket) = after_comment. strip_prefix ( '[' ) {
659
+ // A comment like `//@[foo]` only applies to revision `foo`.
660
+ let Some ( ( line_revision, directive) ) = after_open_bracket. split_once ( ']' ) else {
661
+ panic ! (
662
+ "malformed condition directive: expected `{comment}[foo]`, found `{original_line}`"
663
+ )
664
+ } ;
664
665
665
- let lncfg = & ln[ 1 ..close_brace] ;
666
- Some ( ( Some ( lncfg) , ln[ ( close_brace + 1 ) ..] . trim_start ( ) ) )
667
- } else {
668
- Some ( ( None , ln) )
669
- }
666
+ Some ( ( Some ( line_revision) , directive. trim_start ( ) ) )
670
667
} else {
671
- None
668
+ Some ( ( None , after_comment ) )
672
669
}
673
670
}
674
671
@@ -790,16 +787,32 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
790
787
"unset-rustc-env" ,
791
788
] ;
792
789
793
- /// Arguments passed to the callback in [`iter_header`].
790
+ /// The broken-down contents of a line containing a test header directive,
791
+ /// which [`iter_header`] passes to its callback function.
792
+ ///
793
+ /// For example:
794
+ ///
795
+ /// ```text
796
+ /// //@ compile-flags: -O
797
+ /// ^^^^^^^^^^^^^^^^^ directive
798
+ /// ^^^^^^^^^^^^^^^^^^^^^ original_line
799
+ ///
800
+ /// //@ [foo] compile-flags: -O
801
+ /// ^^^ header_revision
802
+ /// ^^^^^^^^^^^^^^^^^ directive
803
+ /// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ original_line
804
+ /// ```
794
805
struct HeaderLine < ' ln > {
795
- /// Contents of the square brackets preceding this header, if present.
796
- header_revision : Option < & ' ln str > ,
806
+ line_number : usize ,
797
807
/// Raw line from the test file, including comment prefix and any revision.
798
808
original_line : & ' ln str ,
799
- /// Remainder of the directive line, after the initial comment prefix
800
- /// (`//` or `//@` or `#`) and revision (if any) have been stripped.
809
+ /// Some header directives start with a revision name in square brackets
810
+ /// (e.g. `[foo]`), and only apply to that revision of the test.
811
+ /// If present, this field contains the revision name (e.g. `foo`).
812
+ header_revision : Option < & ' ln str > ,
813
+ /// The main part of the header directive, after removing the comment prefix
814
+ /// and the optional revision specifier.
801
815
directive : & ' ln str ,
802
- line_number : usize ,
803
816
}
804
817
805
818
fn iter_header (
@@ -831,7 +844,7 @@ fn iter_header(
831
844
] ;
832
845
// Process the extra implied directives, with a dummy line number of 0.
833
846
for directive in extra_directives {
834
- it ( HeaderLine { header_revision : None , original_line : "" , directive , line_number : 0 } ) ;
847
+ it ( HeaderLine { line_number : 0 , original_line : "" , header_revision : None , directive } ) ;
835
848
}
836
849
}
837
850
@@ -865,7 +878,7 @@ fn iter_header(
865
878
866
879
// First try to accept `ui_test` style comments
867
880
} else if let Some ( ( header_revision, directive) ) = line_directive ( comment, ln) {
868
- it ( HeaderLine { header_revision , original_line, directive , line_number } ) ;
881
+ it ( HeaderLine { line_number , original_line, header_revision , directive } ) ;
869
882
} else if mode == Mode :: Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE . is_match ( ln) {
870
883
let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
871
884
continue ;
@@ -1158,7 +1171,7 @@ pub fn make_test_description<R: Read>(
1158
1171
name : test:: TestName ,
1159
1172
path : & Path ,
1160
1173
src : R ,
1161
- cfg : Option < & str > ,
1174
+ test_revision : Option < & str > ,
1162
1175
poisoned : & mut bool ,
1163
1176
) -> test:: TestDesc {
1164
1177
let mut ignore = false ;
@@ -1174,7 +1187,7 @@ pub fn make_test_description<R: Read>(
1174
1187
path,
1175
1188
src,
1176
1189
& mut |HeaderLine { header_revision, original_line, directive : ln, line_number } | {
1177
- if header_revision. is_some ( ) && header_revision != cfg {
1190
+ if header_revision. is_some ( ) && header_revision != test_revision {
1178
1191
return ;
1179
1192
}
1180
1193
0 commit comments