@@ -12,104 +12,78 @@ use lazycell::LazyCell;
12
12
use std:: collections:: HashSet ;
13
13
use test:: { ColorConfig , OutputFormat } ;
14
14
15
- #[ derive( Clone , Copy , PartialEq , Debug ) ]
16
- pub enum Mode {
17
- RunPassValgrind ,
18
- Pretty ,
19
- DebugInfo ,
20
- Codegen ,
21
- Rustdoc ,
22
- RustdocJson ,
23
- CodegenUnits ,
24
- Incremental ,
25
- RunMake ,
26
- Ui ,
27
- JsDocTest ,
28
- MirOpt ,
29
- Assembly ,
30
- }
15
+ macro_rules! string_enum {
16
+ ( $( #[ $meta: meta] ) * $vis: vis enum $name: ident { $( $variant: ident => $repr: expr, ) * } ) => {
17
+ $( #[ $meta] ) *
18
+ $vis enum $name {
19
+ $( $variant, ) *
20
+ }
31
21
32
- impl Mode {
33
- pub fn disambiguator ( self ) -> & ' static str {
34
- // Pretty-printing tests could run concurrently, and if they do,
35
- // they need to keep their output segregated.
36
- match self {
37
- Pretty => ".pretty" ,
38
- _ => "" ,
22
+ impl $name {
23
+ $vis const VARIANTS : & ' static [ Self ] = & [ $( Self :: $variant, ) * ] ;
24
+
25
+ $vis fn to_str( & self ) -> & ' static str {
26
+ match self {
27
+ $( Self :: $variant => $repr, ) *
28
+ }
29
+ }
39
30
}
40
- }
41
- }
42
31
43
- impl FromStr for Mode {
44
- type Err = ( ) ;
45
- fn from_str ( s : & str ) -> Result < Mode , ( ) > {
46
- match s {
47
- "run-pass-valgrind" => Ok ( RunPassValgrind ) ,
48
- "pretty" => Ok ( Pretty ) ,
49
- "debuginfo" => Ok ( DebugInfo ) ,
50
- "codegen" => Ok ( Codegen ) ,
51
- "rustdoc" => Ok ( Rustdoc ) ,
52
- "rustdoc-json" => Ok ( RustdocJson ) ,
53
- "codegen-units" => Ok ( CodegenUnits ) ,
54
- "incremental" => Ok ( Incremental ) ,
55
- "run-make" => Ok ( RunMake ) ,
56
- "ui" => Ok ( Ui ) ,
57
- "js-doc-test" => Ok ( JsDocTest ) ,
58
- "mir-opt" => Ok ( MirOpt ) ,
59
- "assembly" => Ok ( Assembly ) ,
60
- _ => Err ( ( ) ) ,
32
+ impl fmt:: Display for $name {
33
+ fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
34
+ fmt:: Display :: fmt( self . to_str( ) , f)
35
+ }
61
36
}
62
- }
63
- }
64
37
65
- impl fmt:: Display for Mode {
66
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
67
- let s = match * self {
68
- RunPassValgrind => "run-pass-valgrind" ,
69
- Pretty => "pretty" ,
70
- DebugInfo => "debuginfo" ,
71
- Codegen => "codegen" ,
72
- Rustdoc => "rustdoc" ,
73
- RustdocJson => "rustdoc-json" ,
74
- CodegenUnits => "codegen-units" ,
75
- Incremental => "incremental" ,
76
- RunMake => "run-make" ,
77
- Ui => "ui" ,
78
- JsDocTest => "js-doc-test" ,
79
- MirOpt => "mir-opt" ,
80
- Assembly => "assembly" ,
81
- } ;
82
- fmt:: Display :: fmt ( s, f)
38
+ impl FromStr for $name {
39
+ type Err = ( ) ;
40
+
41
+ fn from_str( s: & str ) -> Result <Self , ( ) > {
42
+ match s {
43
+ $( $repr => Ok ( Self :: $variant) , ) *
44
+ _ => Err ( ( ) ) ,
45
+ }
46
+ }
47
+ }
83
48
}
84
49
}
85
50
86
- #[ derive( Clone , Copy , PartialEq , Debug , Hash ) ]
87
- pub enum PassMode {
88
- Check ,
89
- Build ,
90
- Run ,
51
+ string_enum ! {
52
+ #[ derive( Clone , Copy , PartialEq , Debug ) ]
53
+ pub enum Mode {
54
+ RunPassValgrind => "run-pass-valgrind" ,
55
+ Pretty => "pretty" ,
56
+ DebugInfo => "debuginfo" ,
57
+ Codegen => "codegen" ,
58
+ Rustdoc => "rustdoc" ,
59
+ RustdocJson => "rustdoc-json" ,
60
+ CodegenUnits => "codegen-units" ,
61
+ Incremental => "incremental" ,
62
+ RunMake => "run-make" ,
63
+ Ui => "ui" ,
64
+ JsDocTest => "js-doc-test" ,
65
+ MirOpt => "mir-opt" ,
66
+ Assembly => "assembly" ,
67
+ }
91
68
}
92
69
93
- impl FromStr for PassMode {
94
- type Err = ( ) ;
95
- fn from_str ( s : & str ) -> Result < Self , ( ) > {
96
- match s {
97
- "check" => Ok ( PassMode :: Check ) ,
98
- "build" => Ok ( PassMode :: Build ) ,
99
- "run" => Ok ( PassMode :: Run ) ,
100
- _ => Err ( ( ) ) ,
70
+ impl Mode {
71
+ pub fn disambiguator ( self ) -> & ' static str {
72
+ // Pretty-printing tests could run concurrently, and if they do,
73
+ // they need to keep their output segregated.
74
+ match self {
75
+ Pretty => ".pretty" ,
76
+ _ => "" ,
101
77
}
102
78
}
103
79
}
104
80
105
- impl fmt:: Display for PassMode {
106
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
107
- let s = match * self {
108
- PassMode :: Check => "check" ,
109
- PassMode :: Build => "build" ,
110
- PassMode :: Run => "run" ,
111
- } ;
112
- fmt:: Display :: fmt ( s, f)
81
+ string_enum ! {
82
+ #[ derive( Clone , Copy , PartialEq , Debug , Hash ) ]
83
+ pub enum PassMode {
84
+ Check => "check" ,
85
+ Build => "build" ,
86
+ Run => "run" ,
113
87
}
114
88
}
115
89
@@ -120,69 +94,23 @@ pub enum FailMode {
120
94
Run ,
121
95
}
122
96
123
- #[ derive( Clone , Debug , PartialEq ) ]
124
- pub enum CompareMode {
125
- Polonius ,
126
- Chalk ,
127
- NextSolver ,
128
- SplitDwarf ,
129
- SplitDwarfSingle ,
130
- }
131
-
132
- impl CompareMode {
133
- pub ( crate ) const VARIANTS : & ' static [ CompareMode ] = & [
134
- CompareMode :: Polonius ,
135
- CompareMode :: Chalk ,
136
- CompareMode :: NextSolver ,
137
- CompareMode :: SplitDwarf ,
138
- CompareMode :: SplitDwarfSingle ,
139
- ] ;
140
-
141
- pub ( crate ) fn to_str ( & self ) -> & ' static str {
142
- match * self {
143
- CompareMode :: Polonius => "polonius" ,
144
- CompareMode :: Chalk => "chalk" ,
145
- CompareMode :: NextSolver => "next-solver" ,
146
- CompareMode :: SplitDwarf => "split-dwarf" ,
147
- CompareMode :: SplitDwarfSingle => "split-dwarf-single" ,
148
- }
149
- }
150
-
151
- pub fn parse ( s : String ) -> CompareMode {
152
- match s. as_str ( ) {
153
- "polonius" => CompareMode :: Polonius ,
154
- "chalk" => CompareMode :: Chalk ,
155
- "next-solver" => CompareMode :: NextSolver ,
156
- "split-dwarf" => CompareMode :: SplitDwarf ,
157
- "split-dwarf-single" => CompareMode :: SplitDwarfSingle ,
158
- x => panic ! ( "unknown --compare-mode option: {}" , x) ,
159
- }
160
- }
161
- }
162
-
163
- #[ derive( Clone , Copy , Debug , PartialEq ) ]
164
- pub enum Debugger {
165
- Cdb ,
166
- Gdb ,
167
- Lldb ,
168
- }
169
-
170
- impl Debugger {
171
- pub ( crate ) const VARIANTS : & ' static [ Debugger ] =
172
- & [ Debugger :: Cdb , Debugger :: Gdb , Debugger :: Lldb ] ;
173
-
174
- pub ( crate ) fn to_str ( & self ) -> & ' static str {
175
- match self {
176
- Debugger :: Cdb => "cdb" ,
177
- Debugger :: Gdb => "gdb" ,
178
- Debugger :: Lldb => "lldb" ,
179
- }
97
+ string_enum ! {
98
+ #[ derive( Clone , Debug , PartialEq ) ]
99
+ pub enum CompareMode {
100
+ Polonius => "polonius" ,
101
+ Chalk => "chalk" ,
102
+ NextSolver => "next-solver" ,
103
+ SplitDwarf => "split-dwarf" ,
104
+ SplitDwarfSingle => "split-dwarf-single" ,
180
105
}
181
106
}
182
107
183
- impl fmt:: Display for Debugger {
184
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
185
- fmt:: Display :: fmt ( self . to_str ( ) , f)
108
+ string_enum ! {
109
+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
110
+ pub enum Debugger {
111
+ Cdb => "cdb" ,
112
+ Gdb => "gdb" ,
113
+ Lldb => "lldb" ,
186
114
}
187
115
}
188
116
0 commit comments