@@ -268,8 +268,21 @@ macro_rules! cgoptions(
268
268
269
269
pub type CodegenSetter = fn ( & mut CodegenOptions , v: Option <& str >) -> bool ;
270
270
pub const CG_OPTIONS : & ' static [ ( & ' static str , CodegenSetter ,
271
- & ' static str ) ] =
272
- & [ $( ( stringify!( $opt) , cgsetters:: $opt, $desc) ) ,* ] ;
271
+ Option <& ' static str >, & ' static str ) ] =
272
+ & [ $( ( stringify!( $opt) , cgsetters:: $opt, cg_type_descs:: $parse, $desc) ) ,* ] ;
273
+
274
+ #[ allow( non_upper_case_globals) ]
275
+ mod cg_type_descs {
276
+ pub const parse_bool: Option <& ' static str > = None ;
277
+ pub const parse_opt_bool: Option <& ' static str > = None ;
278
+ pub const parse_string: Option <& ' static str > = Some ( "a string" ) ;
279
+ pub const parse_opt_string: Option <& ' static str > = Some ( "a string" ) ;
280
+ pub const parse_list: Option <& ' static str > = Some ( "a space-separated list of strings" ) ;
281
+ pub const parse_opt_list: Option <& ' static str > = Some ( "a space-separated list of strings" ) ;
282
+ pub const parse_uint: Option <& ' static str > = Some ( "a number" ) ;
283
+ pub const parse_passes: Option <& ' static str > =
284
+ Some ( "a space-separated list of passes, or `all`" ) ;
285
+ }
273
286
274
287
mod cgsetters {
275
288
use super :: { CodegenOptions , Passes , SomePasses , AllPasses } ;
@@ -421,19 +434,25 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
421
434
let value = iter. next ( ) ;
422
435
let option_to_lookup = key. replace ( "-" , "_" ) ;
423
436
let mut found = false ;
424
- for & ( candidate, setter, _) in CG_OPTIONS . iter ( ) {
437
+ for & ( candidate, setter, opt_type_desc , _) in CG_OPTIONS . iter ( ) {
425
438
if option_to_lookup. as_slice ( ) != candidate { continue }
426
439
if !setter ( & mut cg, value) {
427
- match value {
428
- Some ( ..) => {
440
+ match ( value, opt_type_desc ) {
441
+ ( Some ( ..) , None ) => {
429
442
early_error ( format ! ( "codegen option `{}` takes no \
430
443
value", key) . as_slice ( ) )
431
444
}
432
- None => {
445
+ ( None , Some ( type_desc ) ) => {
433
446
early_error ( format ! ( "codegen option `{0}` requires \
434
- a value (-C {0}=<value>)",
435
- key) . as_slice ( ) )
447
+ {1} (-C {0}=<value>)",
448
+ key, type_desc) . as_slice ( ) )
449
+ }
450
+ ( Some ( value) , Some ( type_desc) ) => {
451
+ early_error ( format ! ( "incorrect value `{}` for codegen \
452
+ option `{}` - {} was expected",
453
+ value, key, type_desc) . as_slice ( ) )
436
454
}
455
+ ( None , None ) => unreachable ! ( )
437
456
}
438
457
}
439
458
found = true ;
0 commit comments