@@ -63,8 +63,10 @@ use std::sync::mpsc::channel;
6363use externalfiles:: ExternalHtml ;
6464use serialize:: Decodable ;
6565use serialize:: json:: { self , Json } ;
66+ use rustc:: session:: early_error;
6667use rustc:: session:: search_paths:: SearchPaths ;
67- use rustc:: session:: config:: ErrorOutputType ;
68+ use rustc:: session:: config:: { get_unstable_features_setting, ErrorOutputType } ;
69+ use syntax:: feature_gate:: UnstableFeatures ;
6870
6971// reexported from `clean` so it can be easily updated with the mod itself
7072pub use clean:: SCHEMA_VERSION ;
@@ -187,6 +189,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
187189 optopt( "e" , "extend-css" ,
188190 "to redefine some css rules with a given file to generate doc with your \
189191 own theme", "PATH" ) ,
192+ optmulti( "Z" , "" , "internal and debugging options (only on nightly build)" , "FLAG" ) ,
190193 )
191194}
192195
@@ -196,6 +199,24 @@ pub fn usage(argv0: &str) {
196199 & opts( ) ) ) ;
197200}
198201
202+ fn is_unstable_flag_enabled ( nightly_build : bool , has_z_unstable_options : bool ,
203+ flag_name : & str ) {
204+ // check if unstable for --extend-css option
205+ match if !nightly_build {
206+ Some ( format ! ( "the option `{}` is only accepted on the nightly compiler" , flag_name) )
207+ } else if !has_z_unstable_options {
208+ Some ( format ! ( "the `-Z unstable-options` flag must also be passed to enable the flag `{}`" ,
209+ flag_name) )
210+ } else {
211+ None
212+ } {
213+ Some ( e) => {
214+ early_error ( ErrorOutputType :: default ( ) , & e)
215+ }
216+ None => { }
217+ }
218+ }
219+
199220pub fn main_args ( args : & [ String ] ) -> isize {
200221 let matches = match getopts:: getopts ( & args[ 1 ..] , & opts ( ) ) {
201222 Ok ( m) => m,
@@ -258,7 +279,24 @@ pub fn main_args(args: &[String]) -> isize {
258279 let css_file_extension = matches. opt_str ( "e" ) . map ( |s| PathBuf :: from ( & s) ) ;
259280 let cfgs = matches. opt_strs ( "cfg" ) ;
260281
282+ // we now check if unstable options are allowed and if we're in a nightly build
283+ let mut has_z_unstable_options = false ;
284+ for flag in matches. opt_strs ( "Z" ) . iter ( ) {
285+ if * flag != "unstable-options" {
286+ println ! ( "Unknown flag for `Z` option: {}" , flag) ;
287+ return 1 ;
288+ } else if * flag == "unstable-options" {
289+ has_z_unstable_options = true ;
290+ }
291+ }
292+ let nightly_build = get_unstable_features_setting ( ) ;
293+ let nightly_build = match nightly_build {
294+ UnstableFeatures :: Allow | UnstableFeatures :: Cheat => true ,
295+ _ => false ,
296+ } ;
297+
261298 if let Some ( ref p) = css_file_extension {
299+ is_unstable_flag_enabled ( nightly_build, has_z_unstable_options, "extend-css" ) ;
262300 if !p. is_file ( ) {
263301 println ! ( "{}" , "--extend-css option must take a css file as input" ) ;
264302 return 1 ;
0 commit comments