@@ -16,8 +16,20 @@ use crate::{extract_cdb_version, extract_gdb_version};
16
16
mod tests;
17
17
18
18
/// The result of parse_cfg_name_directive.
19
+ #[ derive( Clone , PartialEq , Debug ) ]
20
+ struct ParsedNameDirective {
21
+ comment : Option < String > ,
22
+ outcome : MatchOutcome ,
23
+ }
24
+
25
+ impl ParsedNameDirective {
26
+ fn invalid ( ) -> Self {
27
+ Self { comment : None , outcome : MatchOutcome :: NoMatch }
28
+ }
29
+ }
30
+
19
31
#[ derive( Clone , Copy , PartialEq , Debug ) ]
20
- enum ParsedNameDirective {
32
+ enum MatchOutcome {
21
33
/// No match.
22
34
NoMatch ,
23
35
/// Match.
@@ -647,7 +659,7 @@ impl Config {
647
659
}
648
660
649
661
fn parse_custom_normalization ( & self , mut line : & str , prefix : & str ) -> Option < ( String , String ) > {
650
- if self . parse_cfg_name_directive ( line, prefix) == ParsedNameDirective :: Match {
662
+ if self . parse_cfg_name_directive ( line, prefix) . outcome == MatchOutcome :: Match {
651
663
let from = parse_normalization_string ( & mut line) ?;
652
664
let to = parse_normalization_string ( & mut line) ?;
653
665
Some ( ( from, to) )
@@ -668,13 +680,15 @@ impl Config {
668
680
/// or `normalize-stderr-32bit`.
669
681
fn parse_cfg_name_directive ( & self , line : & str , prefix : & str ) -> ParsedNameDirective {
670
682
if !line. as_bytes ( ) . starts_with ( prefix. as_bytes ( ) ) {
671
- return ParsedNameDirective :: NoMatch ;
683
+ return ParsedNameDirective :: invalid ( ) ;
672
684
}
673
685
if line. as_bytes ( ) . get ( prefix. len ( ) ) != Some ( & b'-' ) {
674
- return ParsedNameDirective :: NoMatch ;
686
+ return ParsedNameDirective :: invalid ( ) ;
675
687
}
688
+ let line = & line[ prefix. len ( ) + 1 ..] ;
676
689
677
- let name = line[ prefix. len ( ) + 1 ..] . split ( & [ ':' , ' ' ] [ ..] ) . next ( ) . unwrap ( ) ;
690
+ let ( name, comment) =
691
+ line. split_once ( & [ ':' , ' ' ] ) . map ( |( l, c) | ( l, Some ( c) ) ) . unwrap_or ( ( line, None ) ) ;
678
692
679
693
let matches_pointer_width = || {
680
694
name. strip_suffix ( "bit" )
@@ -723,7 +737,10 @@ impl Config {
723
737
None => false ,
724
738
} ;
725
739
726
- if is_match { ParsedNameDirective :: Match } else { ParsedNameDirective :: NoMatch }
740
+ ParsedNameDirective {
741
+ comment : comment. map ( |c| c. trim ( ) . trim_start_matches ( '-' ) . trim ( ) . to_string ( ) ) ,
742
+ outcome : if is_match { MatchOutcome :: Match } else { MatchOutcome :: NoMatch } ,
743
+ }
727
744
}
728
745
729
746
fn has_cfg_prefix ( & self , line : & str , prefix : & str ) -> bool {
@@ -992,19 +1009,40 @@ pub fn make_test_description<R: Read>(
992
1009
}
993
1010
} ;
994
1011
}
995
- ignore = match config. parse_cfg_name_directive ( ln, "ignore" ) {
996
- ParsedNameDirective :: Match => {
997
- ignore_message = Some ( "cfg -> ignore => Match" ) ;
998
- true
999
- }
1000
- ParsedNameDirective :: NoMatch => ignore,
1001
- } ;
1012
+
1013
+ {
1014
+ let parsed = config. parse_cfg_name_directive ( ln, "ignore" ) ;
1015
+ ignore = match parsed. outcome {
1016
+ MatchOutcome :: Match => {
1017
+ ignore_message = Some ( match parsed. comment {
1018
+ // The ignore reason must be a &'static str, so we have to leak memory to
1019
+ // create it. This is fine, as the header is parsed only at the start of
1020
+ // compiletest so it won't grow indefinitely.
1021
+ Some ( comment) => Box :: leak ( Box :: < str > :: from ( format ! (
1022
+ "cfg -> ignore => Match ({comment})"
1023
+ ) ) ) ,
1024
+ None => "cfg -> ignore => Match" ,
1025
+ } ) ;
1026
+ true
1027
+ }
1028
+ MatchOutcome :: NoMatch => ignore,
1029
+ } ;
1030
+ }
1002
1031
1003
1032
if config. has_cfg_prefix ( ln, "only" ) {
1004
- ignore = match config. parse_cfg_name_directive ( ln, "only" ) {
1005
- ParsedNameDirective :: Match => ignore,
1006
- ParsedNameDirective :: NoMatch => {
1007
- ignore_message = Some ( "cfg -> only => NoMatch" ) ;
1033
+ let parsed = config. parse_cfg_name_directive ( ln, "only" ) ;
1034
+ ignore = match parsed. outcome {
1035
+ MatchOutcome :: Match => ignore,
1036
+ MatchOutcome :: NoMatch => {
1037
+ ignore_message = Some ( match parsed. comment {
1038
+ // The ignore reason must be a &'static str, so we have to leak memory to
1039
+ // create it. This is fine, as the header is parsed only at the start of
1040
+ // compiletest so it won't grow indefinitely.
1041
+ Some ( comment) => Box :: leak ( Box :: < str > :: from ( format ! (
1042
+ "cfg -> only => NoMatch ({comment})"
1043
+ ) ) ) ,
1044
+ None => "cfg -> only => NoMatch" ,
1045
+ } ) ;
1008
1046
true
1009
1047
}
1010
1048
} ;
0 commit comments