@@ -785,12 +785,12 @@ impl RustcOptGroup {
785785 self . stability == OptionStability :: Stable
786786 }
787787
788- fn stable ( g : getopts:: OptGroup ) -> RustcOptGroup {
788+ pub fn stable ( g : getopts:: OptGroup ) -> RustcOptGroup {
789789 RustcOptGroup { opt_group : g, stability : OptionStability :: Stable }
790790 }
791791
792792 #[ 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 {
794794 RustcOptGroup { opt_group : g, stability : OptionStability :: Unstable }
795795 }
796796
@@ -926,33 +926,32 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
926926pub fn rustc_optgroups ( ) -> Vec < RustcOptGroup > {
927927 let mut opts = rustc_short_optgroups ( ) ;
928928 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" ) ,
932931 opt:: opt_s ( "" , "sysroot" , "Override the system root" , "PATH" ) ,
933932 opt:: multi_ubnr ( "Z" , "" , "Set internal debugging options" , "FLAG" ) ,
934933 opt:: opt_ubnr ( "" , "error-format" ,
935934 "How errors and other messages are produced" ,
936935 "human|json" ) ,
937936 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" ) ,
941940
942941 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" ) ,
948947 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" ) ,
956955
957956 // new options here should **not** use the `_ubnr` functions, all new
958957 // unstable options should use the short variants to indicate that they
@@ -1263,7 +1262,6 @@ pub fn get_unstable_features_setting() -> UnstableFeatures {
12631262}
12641263
12651264pub fn parse_crate_types_from_list ( list_list : Vec < String > ) -> Result < Vec < CrateType > , String > {
1266-
12671265 let mut crate_types: Vec < CrateType > = Vec :: new ( ) ;
12681266 for unparsed_crate_type in & list_list {
12691267 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
12871285 return Ok ( crate_types) ;
12881286}
12891287
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+
12901354impl fmt:: Display for CrateType {
12911355 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
12921356 match * self {
0 commit comments