@@ -39,9 +39,7 @@ use std::os;
3939use std:: vec_ng:: Vec ;
4040use std:: vec_ng;
4141use collections:: HashMap ;
42- use getopts:: { optopt, optmulti, optflag, optflagopt, opt} ;
43- use MaybeHasArg = getopts:: Maybe ;
44- use OccurOptional = getopts:: Optional ;
42+ use getopts:: { optopt, optmulti, optflag, optflagopt} ;
4543use getopts;
4644use syntax:: ast;
4745use syntax:: abi;
@@ -866,29 +864,41 @@ pub fn build_session_options(matches: &getopts::Matches)
866864 }
867865 Default
868866 } else if matches. opt_present ( "opt-level" ) {
869- match matches. opt_str ( "opt-level" ) . unwrap ( ) {
870- ~"0 " => No ,
871- ~"1 " => Less ,
872- ~"2 " => Default ,
873- ~"3 " => Aggressive ,
874- _ => {
875- early_error ( "optimization level needs to be between 0-3" )
876- }
867+ match matches. opt_str ( "opt-level" ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
868+ None |
869+ Some ( "0" ) => No ,
870+ Some ( "1" ) => Less ,
871+ Some ( "2" ) => Default ,
872+ Some ( "3" ) => Aggressive ,
873+ Some ( arg) => {
874+ early_error ( format ! ( "optimization level needs to be between 0-3 \
875+ (instead was `{}`)", arg) ) ;
876+ }
877877 }
878- } else { No }
878+ } else {
879+ No
880+ }
879881 } ;
880882 let gc = debugging_opts & session:: GC != 0 ;
881883
882- let debuginfo = match matches. opt_default ( "debuginfo" , "2" ) {
883- Some ( level) => {
884- match level {
885- ~"0 " => NoDebugInfo ,
886- ~"1 " => LimitedDebugInfo ,
887- ~"2 " => FullDebugInfo ,
888- _ => early_error ( "debug info level needs to be between 0-2" )
884+ let debuginfo = if matches. opt_present ( "g" ) {
885+ if matches. opt_present ( "debuginfo" ) {
886+ early_error ( "-g and --debuginfo both provided" ) ;
887+ }
888+ FullDebugInfo
889+ } else if matches. opt_present ( "debuginfo" ) {
890+ match matches. opt_str ( "debuginfo" ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
891+ Some ( "0" ) => NoDebugInfo ,
892+ Some ( "1" ) => LimitedDebugInfo ,
893+ None |
894+ Some ( "2" ) => FullDebugInfo ,
895+ Some ( arg) => {
896+ early_error ( format ! ( "optimization level needs to be between 0-3 \
897+ (instead was `{}`)", arg) ) ;
889898 }
890899 }
891- None => NoDebugInfo
900+ } else {
901+ NoDebugInfo
892902 } ;
893903
894904 let addl_lib_search_paths = matches. opt_strs ( "L" ) . map ( |s| {
@@ -1045,11 +1055,11 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
10451055 optflag( "" , "crate-file-name" , "Output the file(s) that would be written if compilation \
10461056 continued and exit") ,
10471057 optflag( "" , "ls" , "List the symbols defined by a library crate" ) ,
1048- opt ( "g" , "debuginfo " , "Emit DWARF debug info to the objects created:
1049- 0 = no debug info,
1050- 1 = line-tables only (for stacktraces) ,
1051- 2 = full debug info with variable, argument and type information" ,
1052- "LEVEL" , MaybeHasArg , OccurOptional ) ,
1058+ optflag ( "g" , "" , "Equivalent to --debuginfo=2" ) ,
1059+ optopt ( "" , "debuginfo" , "Emit DWARF debug info to the objects created:
1060+ 0 = no debug info ,
1061+ 1 = line-tables only (for stacktraces and breakpoints) ,
1062+ 2 = full debug info with variable and type information (same as -g)" , "LEVEL" ) ,
10531063 optflag( "" , "no-trans" , "Run all passes except translation; no output" ) ,
10541064 optflag( "" , "no-analysis" , "Parse and expand the output, but run no analysis or produce output" ) ,
10551065 optflag( "O" , "" , "Equivalent to --opt-level=2" ) ,
0 commit comments