@@ -785,12 +785,12 @@ impl RustcOptGroup {
785
785
self . stability == OptionStability :: Stable
786
786
}
787
787
788
- fn stable ( g : getopts:: OptGroup ) -> RustcOptGroup {
788
+ pub fn stable ( g : getopts:: OptGroup ) -> RustcOptGroup {
789
789
RustcOptGroup { opt_group : g, stability : OptionStability :: Stable }
790
790
}
791
791
792
792
#[ allow( dead_code) ] // currently we have no "truly unstable" options
793
- fn unstable ( g : getopts:: OptGroup ) -> RustcOptGroup {
793
+ pub fn unstable ( g : getopts:: OptGroup ) -> RustcOptGroup {
794
794
RustcOptGroup { opt_group : g, stability : OptionStability :: Unstable }
795
795
}
796
796
@@ -926,33 +926,32 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
926
926
pub fn rustc_optgroups ( ) -> Vec < RustcOptGroup > {
927
927
let mut opts = rustc_short_optgroups ( ) ;
928
928
opts. extend_from_slice ( & [
929
- opt:: multi_s ( "" , "extern" , "Specify where an external rust library is \
930
- located",
931
- "NAME=PATH" ) ,
929
+ opt:: multi_s ( "" , "extern" , "Specify where an external rust library is located" ,
930
+ "NAME=PATH" ) ,
932
931
opt:: opt_s ( "" , "sysroot" , "Override the system root" , "PATH" ) ,
933
932
opt:: multi_ubnr ( "Z" , "" , "Set internal debugging options" , "FLAG" ) ,
934
933
opt:: opt_ubnr ( "" , "error-format" ,
935
934
"How errors and other messages are produced" ,
936
935
"human|json" ) ,
937
936
opt:: opt_s ( "" , "color" , "Configure coloring of output:
938
- auto = colorize, if output goes to a tty (default);
939
- always = always colorize output;
940
- never = never colorize output" , "auto|always|never" ) ,
937
+ auto = colorize, if output goes to a tty (default);
938
+ always = always colorize output;
939
+ never = never colorize output" , "auto|always|never" ) ,
941
940
942
941
opt:: flagopt_ubnr ( "" , "pretty" ,
943
- "Pretty-print the input instead of compiling;
944
- valid types are: `normal` (un-annotated source),
945
- `expanded` (crates expanded), or
946
- `expanded,identified` (fully parenthesized, AST nodes with IDs)." ,
947
- "TYPE" ) ,
942
+ "Pretty-print the input instead of compiling;
943
+ valid types are: `normal` (un-annotated source),
944
+ `expanded` (crates expanded), or
945
+ `expanded,identified` (fully parenthesized, AST nodes with IDs)." ,
946
+ "TYPE" ) ,
948
947
opt:: flagopt_ubnr ( "" , "unpretty" ,
949
- "Present the input source, unstable (and less-pretty) variants;
950
- valid types are any of the types for `--pretty`, as well as:
951
- `flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
952
- `everybody_loops` (all function bodies replaced with `loop {}`),
953
- `hir` (the HIR), `hir,identified`, or
954
- `hir,typed` (HIR with types for each node)." ,
955
- "TYPE" ) ,
948
+ "Present the input source, unstable (and less-pretty) variants;
949
+ valid types are any of the types for `--pretty`, as well as:
950
+ `flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
951
+ `everybody_loops` (all function bodies replaced with `loop {}`),
952
+ `hir` (the HIR), `hir,identified`, or
953
+ `hir,typed` (HIR with types for each node)." ,
954
+ "TYPE" ) ,
956
955
957
956
// new options here should **not** use the `_ubnr` functions, all new
958
957
// unstable options should use the short variants to indicate that they
@@ -1263,7 +1262,6 @@ pub fn get_unstable_features_setting() -> UnstableFeatures {
1263
1262
}
1264
1263
1265
1264
pub fn parse_crate_types_from_list ( list_list : Vec < String > ) -> Result < Vec < CrateType > , String > {
1266
-
1267
1265
let mut crate_types: Vec < CrateType > = Vec :: new ( ) ;
1268
1266
for unparsed_crate_type in & list_list {
1269
1267
for part in unparsed_crate_type. split ( ',' ) {
@@ -1287,6 +1285,72 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
1287
1285
return Ok ( crate_types) ;
1288
1286
}
1289
1287
1288
+ pub mod nightly_options {
1289
+ use getopts;
1290
+ use syntax:: feature_gate:: UnstableFeatures ;
1291
+ use super :: { ErrorOutputType , OptionStability , RustcOptGroup , get_unstable_features_setting} ;
1292
+ use session:: { early_error, early_warn} ;
1293
+
1294
+ pub fn is_unstable_enabled ( matches : & getopts:: Matches ) -> bool {
1295
+ is_nightly_build ( ) && matches. opt_strs ( "Z" ) . iter ( ) . any ( |x| * x == "unstable-options" )
1296
+ }
1297
+
1298
+ fn is_nightly_build ( ) -> bool {
1299
+ match get_unstable_features_setting ( ) {
1300
+ UnstableFeatures :: Allow | UnstableFeatures :: Cheat => true ,
1301
+ _ => false ,
1302
+ }
1303
+ }
1304
+
1305
+ pub fn check_nightly_options ( matches : & getopts:: Matches , flags : & [ RustcOptGroup ] ) {
1306
+ let has_z_unstable_option = matches. opt_strs ( "Z" ) . iter ( ) . any ( |x| * x == "unstable-options" ) ;
1307
+ let really_allows_unstable_options = match get_unstable_features_setting ( ) {
1308
+ UnstableFeatures :: Disallow => false ,
1309
+ _ => true ,
1310
+ } ;
1311
+
1312
+ for opt in flags. iter ( ) {
1313
+ if opt. stability == OptionStability :: Stable {
1314
+ continue
1315
+ }
1316
+ let opt_name = if opt. opt_group . long_name . is_empty ( ) {
1317
+ & opt. opt_group . short_name
1318
+ } else {
1319
+ & opt. opt_group . long_name
1320
+ } ;
1321
+ if !matches. opt_present ( opt_name) {
1322
+ continue
1323
+ }
1324
+ if opt_name != "Z" && !has_z_unstable_option {
1325
+ early_error ( ErrorOutputType :: default ( ) ,
1326
+ & format ! ( "the `-Z unstable-options` flag must also be passed to enable \
1327
+ the flag `{}`",
1328
+ opt_name) ) ;
1329
+ }
1330
+ if really_allows_unstable_options {
1331
+ continue
1332
+ }
1333
+ match opt. stability {
1334
+ OptionStability :: Unstable => {
1335
+ let msg = format ! ( "the option `{}` is only accepted on the \
1336
+ nightly compiler", opt_name) ;
1337
+ early_error ( ErrorOutputType :: default ( ) , & msg) ;
1338
+ }
1339
+ OptionStability :: UnstableButNotReally => {
1340
+ let msg = format ! ( "the option `{}` is is unstable and should \
1341
+ only be used on the nightly compiler, but \
1342
+ it is currently accepted for backwards \
1343
+ compatibility; this will soon change, \
1344
+ see issue #31847 for more details",
1345
+ opt_name) ;
1346
+ early_warn ( ErrorOutputType :: default ( ) , & msg) ;
1347
+ }
1348
+ OptionStability :: Stable => { }
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+
1290
1354
impl fmt:: Display for CrateType {
1291
1355
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1292
1356
match * self {
0 commit comments