@@ -1135,9 +1135,9 @@ pub enum OptionStability {
11351135 Unstable ,
11361136}
11371137
1138- #[ derive( Clone , PartialEq , Eq ) ]
11391138pub struct RustcOptGroup {
1140- pub opt_group : getopts:: OptGroup ,
1139+ pub apply : Box < Fn ( & mut getopts:: Options ) -> & mut getopts:: Options > ,
1140+ pub name : & ' static str ,
11411141 pub stability : OptionStability ,
11421142}
11431143
@@ -1146,12 +1146,24 @@ impl RustcOptGroup {
11461146 self . stability == OptionStability :: Stable
11471147 }
11481148
1149- pub fn stable ( g : getopts:: OptGroup ) -> RustcOptGroup {
1150- RustcOptGroup { opt_group : g, stability : OptionStability :: Stable }
1149+ pub fn stable < F > ( name : & ' static str , f : F ) -> RustcOptGroup
1150+ where F : Fn ( & mut getopts:: Options ) -> & mut getopts:: Options + ' static ,
1151+ {
1152+ RustcOptGroup {
1153+ name : name,
1154+ apply : Box :: new ( f) ,
1155+ stability : OptionStability :: Stable ,
1156+ }
11511157 }
11521158
1153- pub fn unstable ( g : getopts:: OptGroup ) -> RustcOptGroup {
1154- RustcOptGroup { opt_group : g, stability : OptionStability :: Unstable }
1159+ pub fn unstable < F > ( name : & ' static str , f : F ) -> RustcOptGroup
1160+ where F : Fn ( & mut getopts:: Options ) -> & mut getopts:: Options + ' static ,
1161+ {
1162+ RustcOptGroup {
1163+ name : name,
1164+ apply : Box :: new ( f) ,
1165+ stability : OptionStability :: Unstable ,
1166+ }
11551167 }
11561168}
11571169
@@ -1170,55 +1182,65 @@ mod opt {
11701182 use super :: RustcOptGroup ;
11711183
11721184 pub type R = RustcOptGroup ;
1173- pub type S < ' a > = & ' a str ;
1185+ pub type S = & ' static str ;
1186+
1187+ fn stable < F > ( name : S , f : F ) -> R
1188+ where F : Fn ( & mut getopts:: Options ) -> & mut getopts:: Options + ' static
1189+ {
1190+ RustcOptGroup :: stable ( name, f)
1191+ }
11741192
1175- fn stable ( g : getopts:: OptGroup ) -> R { RustcOptGroup :: stable ( g) }
1176- fn unstable ( g : getopts:: OptGroup ) -> R { RustcOptGroup :: unstable ( g) }
1193+ fn unstable < F > ( name : S , f : F ) -> R
1194+ where F : Fn ( & mut getopts:: Options ) -> & mut getopts:: Options + ' static
1195+ {
1196+ RustcOptGroup :: unstable ( name, f)
1197+ }
1198+
1199+ fn longer ( a : S , b : S ) -> S {
1200+ if a. len ( ) > b. len ( ) {
1201+ a
1202+ } else {
1203+ b
1204+ }
1205+ }
11771206
11781207 pub fn opt_s ( a : S , b : S , c : S , d : S ) -> R {
1179- stable ( getopts :: optopt ( a, b, c, d) )
1208+ stable ( longer ( a , b ) , move |opts| opts . optopt ( a, b, c, d) )
11801209 }
11811210 pub fn multi_s ( a : S , b : S , c : S , d : S ) -> R {
1182- stable ( getopts :: optmulti ( a, b, c, d) )
1211+ stable ( longer ( a , b ) , move |opts| opts . optmulti ( a, b, c, d) )
11831212 }
11841213 pub fn flag_s ( a : S , b : S , c : S ) -> R {
1185- stable ( getopts :: optflag ( a, b, c) )
1214+ stable ( longer ( a , b ) , move |opts| opts . optflag ( a, b, c) )
11861215 }
11871216 pub fn flagopt_s ( a : S , b : S , c : S , d : S ) -> R {
1188- stable ( getopts :: optflagopt ( a, b, c, d) )
1217+ stable ( longer ( a , b ) , move |opts| opts . optflagopt ( a, b, c, d) )
11891218 }
11901219 pub fn flagmulti_s ( a : S , b : S , c : S ) -> R {
1191- stable ( getopts :: optflagmulti ( a, b, c) )
1220+ stable ( longer ( a , b ) , move |opts| opts . optflagmulti ( a, b, c) )
11921221 }
11931222
11941223 pub fn opt ( a : S , b : S , c : S , d : S ) -> R {
1195- unstable ( getopts :: optopt ( a, b, c, d) )
1224+ unstable ( longer ( a , b ) , move |opts| opts . optopt ( a, b, c, d) )
11961225 }
11971226 pub fn multi ( a : S , b : S , c : S , d : S ) -> R {
1198- unstable ( getopts :: optmulti ( a, b, c, d) )
1227+ unstable ( longer ( a , b ) , move |opts| opts . optmulti ( a, b, c, d) )
11991228 }
12001229 pub fn flag ( a : S , b : S , c : S ) -> R {
1201- unstable ( getopts :: optflag ( a, b, c) )
1230+ unstable ( longer ( a , b ) , move |opts| opts . optflag ( a, b, c) )
12021231 }
12031232 pub fn flagopt ( a : S , b : S , c : S , d : S ) -> R {
1204- unstable ( getopts :: optflagopt ( a, b, c, d) )
1233+ unstable ( longer ( a , b ) , move |opts| opts . optflagopt ( a, b, c, d) )
12051234 }
12061235 pub fn flagmulti ( a : S , b : S , c : S ) -> R {
1207- unstable ( getopts :: optflagmulti ( a, b, c) )
1236+ unstable ( longer ( a , b ) , move |opts| opts . optflagmulti ( a, b, c) )
12081237 }
12091238}
12101239
12111240/// Returns the "short" subset of the rustc command line options,
12121241/// including metadata for each option, such as whether the option is
12131242/// part of the stable long-term interface for rustc.
12141243pub fn rustc_short_optgroups ( ) -> Vec < RustcOptGroup > {
1215- let mut print_opts = vec ! [ "crate-name" , "file-names" , "sysroot" , "cfg" ,
1216- "target-list" , "target-cpus" , "target-features" ,
1217- "relocation-models" , "code-models" ] ;
1218- if nightly_options:: is_nightly_build ( ) {
1219- print_opts. push ( "target-spec-json" ) ;
1220- }
1221-
12221244 vec ! [
12231245 opt:: flag_s( "h" , "help" , "Display this message" ) ,
12241246 opt:: multi_s( "" , "cfg" , "Configure the compilation environment" , "SPEC" ) ,
@@ -1238,8 +1260,10 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
12381260 the compiler to emit",
12391261 "[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]" ) ,
12401262 opt:: multi_s( "" , "print" , "Comma separated list of compiler information to \
1241- print on stdout", & format!( "[{}]" ,
1242- & print_opts. join( "|" ) ) ) ,
1263+ print on stdout",
1264+ "[crate-name|file-names|sysroot|cfg|target-list|\
1265+ target-cpus|target-features|relocation-models|\
1266+ code-models|target-spec-json]") ,
12431267 opt:: flagmulti_s( "g" , "" , "Equivalent to -C debuginfo=2" ) ,
12441268 opt:: flagmulti_s( "O" , "" , "Equivalent to -C opt-level=2" ) ,
12451269 opt:: opt_s( "o" , "" , "Write output to <filename>" , "FILENAME" ) ,
@@ -1267,7 +1291,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
12671291/// long-term interface for rustc.
12681292pub fn rustc_optgroups ( ) -> Vec < RustcOptGroup > {
12691293 let mut opts = rustc_short_optgroups ( ) ;
1270- opts. extend_from_slice ( & [
1294+ opts. extend ( vec ! [
12711295 opt:: multi_s( "" , "extern" , "Specify where an external rust library is located" ,
12721296 "NAME=PATH" ) ,
12731297 opt:: opt_s( "" , "sysroot" , "Override the system root" , "PATH" ) ,
@@ -1680,27 +1704,22 @@ pub mod nightly_options {
16801704 if opt. stability == OptionStability :: Stable {
16811705 continue
16821706 }
1683- let opt_name = if opt. opt_group . long_name . is_empty ( ) {
1684- & opt. opt_group . short_name
1685- } else {
1686- & opt. opt_group . long_name
1687- } ;
1688- if !matches. opt_present ( opt_name) {
1707+ if !matches. opt_present ( opt. name ) {
16891708 continue
16901709 }
1691- if opt_name != "Z" && !has_z_unstable_option {
1710+ if opt . name != "Z" && !has_z_unstable_option {
16921711 early_error ( ErrorOutputType :: default ( ) ,
16931712 & format ! ( "the `-Z unstable-options` flag must also be passed to enable \
16941713 the flag `{}`",
1695- opt_name ) ) ;
1714+ opt . name ) ) ;
16961715 }
16971716 if really_allows_unstable_options {
16981717 continue
16991718 }
17001719 match opt. stability {
17011720 OptionStability :: Unstable => {
17021721 let msg = format ! ( "the option `{}` is only accepted on the \
1703- nightly compiler", opt_name ) ;
1722+ nightly compiler", opt . name ) ;
17041723 early_error ( ErrorOutputType :: default ( ) , & msg) ;
17051724 }
17061725 OptionStability :: Stable => { }
@@ -1869,7 +1888,7 @@ mod dep_tracking {
18691888mod tests {
18701889 use dep_graph:: DepGraph ;
18711890 use errors;
1872- use getopts:: { getopts , OptGroup } ;
1891+ use getopts;
18731892 use lint;
18741893 use middle:: cstore:: { self , DummyCrateStore } ;
18751894 use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
@@ -1882,10 +1901,12 @@ mod tests {
18821901 use rustc_back:: PanicStrategy ;
18831902 use syntax:: symbol:: Symbol ;
18841903
1885- fn optgroups ( ) -> Vec < OptGroup > {
1886- super :: rustc_optgroups ( ) . into_iter ( )
1887- . map ( |a| a. opt_group )
1888- . collect ( )
1904+ fn optgroups ( ) -> getopts:: Options {
1905+ let mut opts = getopts:: Options :: new ( ) ;
1906+ for group in super :: rustc_optgroups ( ) {
1907+ ( group. apply ) ( & mut opts) ;
1908+ }
1909+ return opts
18891910 }
18901911
18911912 fn mk_map < K : Ord , V > ( entries : Vec < ( K , V ) > ) -> BTreeMap < K , V > {
@@ -1901,7 +1922,7 @@ mod tests {
19011922 fn test_switch_implies_cfg_test ( ) {
19021923 let dep_graph = DepGraph :: new ( false ) ;
19031924 let matches =
1904- & match getopts ( & [ "--test" . to_string ( ) ] , & optgroups ( ) ) {
1925+ & match optgroups ( ) . parse ( & [ "--test" . to_string ( ) ] ) {
19051926 Ok ( m) => m,
19061927 Err ( f) => panic ! ( "test_switch_implies_cfg_test: {}" , f)
19071928 } ;
@@ -1918,8 +1939,7 @@ mod tests {
19181939 fn test_switch_implies_cfg_test_unless_cfg_test ( ) {
19191940 let dep_graph = DepGraph :: new ( false ) ;
19201941 let matches =
1921- & match getopts ( & [ "--test" . to_string ( ) , "--cfg=test" . to_string ( ) ] ,
1922- & optgroups ( ) ) {
1942+ & match optgroups ( ) . parse ( & [ "--test" . to_string ( ) , "--cfg=test" . to_string ( ) ] ) {
19231943 Ok ( m) => m,
19241944 Err ( f) => {
19251945 panic ! ( "test_switch_implies_cfg_test_unless_cfg_test: {}" , f)
@@ -1939,9 +1959,9 @@ mod tests {
19391959 fn test_can_print_warnings ( ) {
19401960 let dep_graph = DepGraph :: new ( false ) ;
19411961 {
1942- let matches = getopts ( & [
1962+ let matches = optgroups ( ) . parse ( & [
19431963 "-Awarnings" . to_string ( )
1944- ] , & optgroups ( ) ) . unwrap ( ) ;
1964+ ] ) . unwrap ( ) ;
19451965 let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
19461966 let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
19471967 let sess = build_session ( sessopts, & dep_graph, None , registry,
@@ -1950,10 +1970,10 @@ mod tests {
19501970 }
19511971
19521972 {
1953- let matches = getopts ( & [
1973+ let matches = optgroups ( ) . parse ( & [
19541974 "-Awarnings" . to_string ( ) ,
19551975 "-Dwarnings" . to_string ( )
1956- ] , & optgroups ( ) ) . unwrap ( ) ;
1976+ ] ) . unwrap ( ) ;
19571977 let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
19581978 let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
19591979 let sess = build_session ( sessopts, & dep_graph, None , registry,
@@ -1962,9 +1982,9 @@ mod tests {
19621982 }
19631983
19641984 {
1965- let matches = getopts ( & [
1985+ let matches = optgroups ( ) . parse ( & [
19661986 "-Adead_code" . to_string ( )
1967- ] , & optgroups ( ) ) . unwrap ( ) ;
1987+ ] ) . unwrap ( ) ;
19681988 let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
19691989 let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
19701990 let sess = build_session ( sessopts, & dep_graph, None , registry,
0 commit comments