@@ -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 } ;
@@ -420,19 +433,25 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
420
433
let value = iter. next ( ) ;
421
434
let option_to_lookup = key. replace ( "-" , "_" ) ;
422
435
let mut found = false ;
423
- for & ( candidate, setter, _) in CG_OPTIONS . iter ( ) {
436
+ for & ( candidate, setter, opt_type_desc , _) in CG_OPTIONS . iter ( ) {
424
437
if option_to_lookup. as_slice ( ) != candidate { continue }
425
438
if !setter ( & mut cg, value) {
426
- match value {
427
- Some ( ..) => {
439
+ match ( value, opt_type_desc ) {
440
+ ( Some ( ..) , None ) => {
428
441
early_error ( format ! ( "codegen option `{}` takes no \
429
442
value", key) . as_slice ( ) )
430
443
}
431
- None => {
444
+ ( None , Some ( type_desc ) ) => {
432
445
early_error ( format ! ( "codegen option `{0}` requires \
433
- a value (-C {0}=<value>)",
434
- key) . as_slice ( ) )
446
+ {1} (-C {0}=<value>)",
447
+ key, type_desc) . as_slice ( ) )
448
+ }
449
+ ( Some ( value) , Some ( type_desc) ) => {
450
+ early_error ( format ! ( "incorrect value `{}` for codegen \
451
+ option `{}` - {} was expected",
452
+ value, key, type_desc) . as_slice ( ) )
435
453
}
454
+ ( None , None ) => unreachable ! ( )
436
455
}
437
456
}
438
457
found = true ;
0 commit comments