@@ -65,8 +65,10 @@ use std::sync::mpsc::channel;
65
65
use externalfiles:: ExternalHtml ;
66
66
use serialize:: Decodable ;
67
67
use serialize:: json:: { self , Json } ;
68
+ use rustc:: session:: early_error;
68
69
use rustc:: session:: search_paths:: SearchPaths ;
69
- use rustc:: session:: config:: ErrorOutputType ;
70
+ use rustc:: session:: config:: { get_unstable_features_setting, ErrorOutputType } ;
71
+ use syntax:: feature_gate:: UnstableFeatures ;
70
72
71
73
// reexported from `clean` so it can be easily updated with the mod itself
72
74
pub use clean:: SCHEMA_VERSION ;
@@ -189,6 +191,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
189
191
optopt( "e" , "extend-css" ,
190
192
"to redefine some css rules with a given file to generate doc with your \
191
193
own theme", "PATH" ) ,
194
+ optmulti( "Z" , "" , "internal and debugging options (only on nightly build)" , "FLAG" ) ,
192
195
)
193
196
}
194
197
@@ -198,6 +201,20 @@ pub fn usage(argv0: &str) {
198
201
& opts( ) ) ) ;
199
202
}
200
203
204
+ fn check_unstable_flag_enabled ( nightly_build : bool , has_z_unstable_options : bool ,
205
+ flag_name : & str ) {
206
+ // check if unstable for --extend-css option
207
+ let e = if !nightly_build {
208
+ format ! ( "the option `{}` is only accepted on the nightly compiler" , flag_name)
209
+ } else if !has_z_unstable_options {
210
+ format ! ( "the `-Z unstable-options` flag must also be passed to enable the flag `{}`" ,
211
+ flag_name)
212
+ } else {
213
+ return
214
+ } ;
215
+ early_error ( ErrorOutputType :: default ( ) , & e)
216
+ }
217
+
201
218
pub fn main_args ( args : & [ String ] ) -> isize {
202
219
let matches = match getopts:: getopts ( & args[ 1 ..] , & opts ( ) ) {
203
220
Ok ( m) => m,
@@ -260,7 +277,24 @@ pub fn main_args(args: &[String]) -> isize {
260
277
let css_file_extension = matches. opt_str ( "e" ) . map ( |s| PathBuf :: from ( & s) ) ;
261
278
let cfgs = matches. opt_strs ( "cfg" ) ;
262
279
280
+ // we now check if unstable options are allowed and if we're in a nightly build
281
+ let mut has_z_unstable_options = false ;
282
+ for flag in matches. opt_strs ( "Z" ) . iter ( ) {
283
+ if * flag != "unstable-options" {
284
+ println ! ( "Unknown flag for `Z` option: {}" , flag) ;
285
+ return 1 ;
286
+ } else {
287
+ has_z_unstable_options = true ;
288
+ }
289
+ }
290
+ let nightly_build = get_unstable_features_setting ( ) ;
291
+ let nightly_build = match nightly_build {
292
+ UnstableFeatures :: Allow | UnstableFeatures :: Cheat => true ,
293
+ _ => false ,
294
+ } ;
295
+
263
296
if let Some ( ref p) = css_file_extension {
297
+ check_unstable_flag_enabled ( nightly_build, has_z_unstable_options, "extend-css" ) ;
264
298
if !p. is_file ( ) {
265
299
println ! ( "{}" , "--extend-css option must take a css file as input" ) ;
266
300
return 1 ;
0 commit comments