@@ -593,24 +593,10 @@ fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
593
593
}
594
594
595
595
pub fn build_session_options ( matches : & getopts:: Matches ) -> Options {
596
- let mut crate_types : Vec < CrateType > = Vec :: new ( ) ;
596
+
597
597
let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
598
- for unparsed_crate_type in unparsed_crate_types. iter ( ) {
599
- for part in unparsed_crate_type. as_slice ( ) . split ( ',' ) {
600
- let new_part = match part {
601
- "lib" => default_lib_output ( ) ,
602
- "rlib" => CrateTypeRlib ,
603
- "staticlib" => CrateTypeStaticlib ,
604
- "dylib" => CrateTypeDylib ,
605
- "bin" => CrateTypeExecutable ,
606
- _ => {
607
- early_error ( format ! ( "unknown crate type: `{}`" ,
608
- part) . as_slice ( ) )
609
- }
610
- } ;
611
- crate_types. push ( new_part)
612
- }
613
- }
598
+ let crate_types = parse_crate_types_from_list ( unparsed_crate_types)
599
+ . unwrap_or_else ( |e| early_error ( e. as_slice ( ) ) ) ;
614
600
615
601
let parse_only = matches. opt_present ( "parse-only" ) ;
616
602
let no_trans = matches. opt_present ( "no-trans" ) ;
@@ -804,6 +790,29 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
804
790
}
805
791
}
806
792
793
+ pub fn parse_crate_types_from_list ( crate_types_list_list : Vec < String > ) -> Result < Vec < CrateType > , String > {
794
+
795
+ let mut crate_types: Vec < CrateType > = Vec :: new ( ) ;
796
+ for unparsed_crate_type in crate_types_list_list. iter ( ) {
797
+ for part in unparsed_crate_type. as_slice ( ) . split ( ',' ) {
798
+ let new_part = match part {
799
+ "lib" => default_lib_output ( ) ,
800
+ "rlib" => CrateTypeRlib ,
801
+ "staticlib" => CrateTypeStaticlib ,
802
+ "dylib" => CrateTypeDylib ,
803
+ "bin" => CrateTypeExecutable ,
804
+ _ => {
805
+ return Err ( format ! ( "unknown crate type: `{}`" ,
806
+ part) ) ;
807
+ }
808
+ } ;
809
+ crate_types. push ( new_part)
810
+ }
811
+ }
812
+
813
+ return Ok ( crate_types) ;
814
+ }
815
+
807
816
impl fmt:: Show for CrateType {
808
817
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
809
818
match * self {
0 commit comments