@@ -138,6 +138,34 @@ impl OutputType {
138
138
}
139
139
}
140
140
141
+ fn from_shorthand ( shorthand : & str ) -> Option < Self > {
142
+ Some ( match shorthand {
143
+ "asm" => OutputType :: Assembly ,
144
+ "llvm-ir" => OutputType :: LlvmAssembly ,
145
+ "mir" => OutputType :: Mir ,
146
+ "llvm-bc" => OutputType :: Bitcode ,
147
+ "obj" => OutputType :: Object ,
148
+ "metadata" => OutputType :: Metadata ,
149
+ "link" => OutputType :: Exe ,
150
+ "dep-info" => OutputType :: DepInfo ,
151
+ _ => return None ,
152
+ } )
153
+ }
154
+
155
+ fn shorthands_display ( ) -> String {
156
+ format ! (
157
+ "`{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`" ,
158
+ OutputType :: Bitcode . shorthand( ) ,
159
+ OutputType :: Assembly . shorthand( ) ,
160
+ OutputType :: LlvmAssembly . shorthand( ) ,
161
+ OutputType :: Mir . shorthand( ) ,
162
+ OutputType :: Object . shorthand( ) ,
163
+ OutputType :: Metadata . shorthand( ) ,
164
+ OutputType :: Exe . shorthand( ) ,
165
+ OutputType :: DepInfo . shorthand( ) ,
166
+ )
167
+ }
168
+
141
169
pub fn extension ( & self ) -> & ' static str {
142
170
match * self {
143
171
OutputType :: Bitcode => "bc" ,
@@ -1488,19 +1516,13 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1488
1516
for list in matches. opt_strs ( "emit" ) {
1489
1517
for output_type in list. split ( ',' ) {
1490
1518
let mut parts = output_type. splitn ( 2 , '=' ) ;
1491
- let output_type = match parts. next ( ) . unwrap ( ) {
1492
- "asm" => OutputType :: Assembly ,
1493
- "llvm-ir" => OutputType :: LlvmAssembly ,
1494
- "mir" => OutputType :: Mir ,
1495
- "llvm-bc" => OutputType :: Bitcode ,
1496
- "obj" => OutputType :: Object ,
1497
- "metadata" => OutputType :: Metadata ,
1498
- "link" => OutputType :: Exe ,
1499
- "dep-info" => OutputType :: DepInfo ,
1500
- part => {
1501
- early_error ( error_format, & format ! ( "unknown emission type: `{}`" ,
1502
- part) )
1503
- }
1519
+ let shorthand = parts. next ( ) . unwrap ( ) ;
1520
+ let output_type = match OutputType :: from_shorthand ( shorthand) {
1521
+ Some ( output_type) => output_type,
1522
+ None => early_error ( error_format, & format ! (
1523
+ "unknown emission type: `{}` - expected one of: {}" ,
1524
+ shorthand, OutputType :: shorthands_display( ) ,
1525
+ ) ) ,
1504
1526
} ;
1505
1527
let path = parts. next ( ) . map ( PathBuf :: from) ;
1506
1528
output_types. insert ( output_type, path) ;
0 commit comments