@@ -1135,9 +1135,9 @@ pub enum OptionStability {
1135
1135
Unstable ,
1136
1136
}
1137
1137
1138
- #[ derive( Clone , PartialEq , Eq ) ]
1139
1138
pub struct RustcOptGroup {
1140
- pub opt_group : getopts:: OptGroup ,
1139
+ pub apply : Box < Fn ( & mut getopts:: Options ) -> & mut getopts:: Options > ,
1140
+ pub name : & ' static str ,
1141
1141
pub stability : OptionStability ,
1142
1142
}
1143
1143
@@ -1146,12 +1146,24 @@ impl RustcOptGroup {
1146
1146
self . stability == OptionStability :: Stable
1147
1147
}
1148
1148
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
+ }
1151
1157
}
1152
1158
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
+ }
1155
1167
}
1156
1168
}
1157
1169
@@ -1170,55 +1182,65 @@ mod opt {
1170
1182
use super :: RustcOptGroup ;
1171
1183
1172
1184
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
+ }
1174
1192
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
+ }
1177
1206
1178
1207
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) )
1180
1209
}
1181
1210
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) )
1183
1212
}
1184
1213
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) )
1186
1215
}
1187
1216
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) )
1189
1218
}
1190
1219
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) )
1192
1221
}
1193
1222
1194
1223
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) )
1196
1225
}
1197
1226
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) )
1199
1228
}
1200
1229
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) )
1202
1231
}
1203
1232
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) )
1205
1234
}
1206
1235
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) )
1208
1237
}
1209
1238
}
1210
1239
1211
1240
/// Returns the "short" subset of the rustc command line options,
1212
1241
/// including metadata for each option, such as whether the option is
1213
1242
/// part of the stable long-term interface for rustc.
1214
1243
pub 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
-
1222
1244
vec ! [
1223
1245
opt:: flag_s( "h" , "help" , "Display this message" ) ,
1224
1246
opt:: multi_s( "" , "cfg" , "Configure the compilation environment" , "SPEC" ) ,
@@ -1238,8 +1260,10 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1238
1260
the compiler to emit",
1239
1261
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]" ) ,
1240
1262
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]") ,
1243
1267
opt:: flagmulti_s( "g" , "" , "Equivalent to -C debuginfo=2" ) ,
1244
1268
opt:: flagmulti_s( "O" , "" , "Equivalent to -C opt-level=2" ) ,
1245
1269
opt:: opt_s( "o" , "" , "Write output to <filename>" , "FILENAME" ) ,
@@ -1267,7 +1291,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1267
1291
/// long-term interface for rustc.
1268
1292
pub fn rustc_optgroups ( ) -> Vec < RustcOptGroup > {
1269
1293
let mut opts = rustc_short_optgroups ( ) ;
1270
- opts. extend_from_slice ( & [
1294
+ opts. extend ( vec ! [
1271
1295
opt:: multi_s( "" , "extern" , "Specify where an external rust library is located" ,
1272
1296
"NAME=PATH" ) ,
1273
1297
opt:: opt_s( "" , "sysroot" , "Override the system root" , "PATH" ) ,
@@ -1680,27 +1704,22 @@ pub mod nightly_options {
1680
1704
if opt. stability == OptionStability :: Stable {
1681
1705
continue
1682
1706
}
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 ) {
1689
1708
continue
1690
1709
}
1691
- if opt_name != "Z" && !has_z_unstable_option {
1710
+ if opt . name != "Z" && !has_z_unstable_option {
1692
1711
early_error ( ErrorOutputType :: default ( ) ,
1693
1712
& format ! ( "the `-Z unstable-options` flag must also be passed to enable \
1694
1713
the flag `{}`",
1695
- opt_name ) ) ;
1714
+ opt . name ) ) ;
1696
1715
}
1697
1716
if really_allows_unstable_options {
1698
1717
continue
1699
1718
}
1700
1719
match opt. stability {
1701
1720
OptionStability :: Unstable => {
1702
1721
let msg = format ! ( "the option `{}` is only accepted on the \
1703
- nightly compiler", opt_name ) ;
1722
+ nightly compiler", opt . name ) ;
1704
1723
early_error ( ErrorOutputType :: default ( ) , & msg) ;
1705
1724
}
1706
1725
OptionStability :: Stable => { }
@@ -1869,7 +1888,7 @@ mod dep_tracking {
1869
1888
mod tests {
1870
1889
use dep_graph:: DepGraph ;
1871
1890
use errors;
1872
- use getopts:: { getopts , OptGroup } ;
1891
+ use getopts;
1873
1892
use lint;
1874
1893
use middle:: cstore:: { self , DummyCrateStore } ;
1875
1894
use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
@@ -1882,10 +1901,12 @@ mod tests {
1882
1901
use rustc_back:: PanicStrategy ;
1883
1902
use syntax:: symbol:: Symbol ;
1884
1903
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
1889
1910
}
1890
1911
1891
1912
fn mk_map < K : Ord , V > ( entries : Vec < ( K , V ) > ) -> BTreeMap < K , V > {
@@ -1901,7 +1922,7 @@ mod tests {
1901
1922
fn test_switch_implies_cfg_test ( ) {
1902
1923
let dep_graph = DepGraph :: new ( false ) ;
1903
1924
let matches =
1904
- & match getopts ( & [ "--test" . to_string ( ) ] , & optgroups ( ) ) {
1925
+ & match optgroups ( ) . parse ( & [ "--test" . to_string ( ) ] ) {
1905
1926
Ok ( m) => m,
1906
1927
Err ( f) => panic ! ( "test_switch_implies_cfg_test: {}" , f)
1907
1928
} ;
@@ -1918,8 +1939,7 @@ mod tests {
1918
1939
fn test_switch_implies_cfg_test_unless_cfg_test ( ) {
1919
1940
let dep_graph = DepGraph :: new ( false ) ;
1920
1941
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 ( ) ] ) {
1923
1943
Ok ( m) => m,
1924
1944
Err ( f) => {
1925
1945
panic ! ( "test_switch_implies_cfg_test_unless_cfg_test: {}" , f)
@@ -1939,9 +1959,9 @@ mod tests {
1939
1959
fn test_can_print_warnings ( ) {
1940
1960
let dep_graph = DepGraph :: new ( false ) ;
1941
1961
{
1942
- let matches = getopts ( & [
1962
+ let matches = optgroups ( ) . parse ( & [
1943
1963
"-Awarnings" . to_string ( )
1944
- ] , & optgroups ( ) ) . unwrap ( ) ;
1964
+ ] ) . unwrap ( ) ;
1945
1965
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
1946
1966
let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
1947
1967
let sess = build_session ( sessopts, & dep_graph, None , registry,
@@ -1950,10 +1970,10 @@ mod tests {
1950
1970
}
1951
1971
1952
1972
{
1953
- let matches = getopts ( & [
1973
+ let matches = optgroups ( ) . parse ( & [
1954
1974
"-Awarnings" . to_string ( ) ,
1955
1975
"-Dwarnings" . to_string ( )
1956
- ] , & optgroups ( ) ) . unwrap ( ) ;
1976
+ ] ) . unwrap ( ) ;
1957
1977
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
1958
1978
let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
1959
1979
let sess = build_session ( sessopts, & dep_graph, None , registry,
@@ -1962,9 +1982,9 @@ mod tests {
1962
1982
}
1963
1983
1964
1984
{
1965
- let matches = getopts ( & [
1985
+ let matches = optgroups ( ) . parse ( & [
1966
1986
"-Adead_code" . to_string ( )
1967
- ] , & optgroups ( ) ) . unwrap ( ) ;
1987
+ ] ) . unwrap ( ) ;
1968
1988
let registry = errors:: registry:: Registry :: new ( & [ ] ) ;
1969
1989
let ( sessopts, _) = build_session_options_and_crate_config ( & matches) ;
1970
1990
let sess = build_session ( sessopts, & dep_graph, None , registry,
0 commit comments