@@ -63,8 +63,10 @@ use std::sync::mpsc::channel;
63
63
use externalfiles:: ExternalHtml ;
64
64
use serialize:: Decodable ;
65
65
use serialize:: json:: { self , Json } ;
66
+ use rustc:: session:: early_error;
66
67
use 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 ;
68
70
69
71
// reexported from `clean` so it can be easily updated with the mod itself
70
72
pub use clean:: SCHEMA_VERSION ;
@@ -187,6 +189,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
187
189
optopt( "e" , "extend-css" ,
188
190
"to redefine some css rules with a given file to generate doc with your \
189
191
own theme", "PATH" ) ,
192
+ optmulti( "Z" , "" , "internal and debugging options (only on nightly build)" , "FLAG" ) ,
190
193
)
191
194
}
192
195
@@ -196,6 +199,24 @@ pub fn usage(argv0: &str) {
196
199
& opts( ) ) ) ;
197
200
}
198
201
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
+
199
220
pub fn main_args ( args : & [ String ] ) -> isize {
200
221
let matches = match getopts:: getopts ( & args[ 1 ..] , & opts ( ) ) {
201
222
Ok ( m) => m,
@@ -258,7 +279,24 @@ pub fn main_args(args: &[String]) -> isize {
258
279
let css_file_extension = matches. opt_str ( "e" ) . map ( |s| PathBuf :: from ( & s) ) ;
259
280
let cfgs = matches. opt_strs ( "cfg" ) ;
260
281
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
+
261
298
if let Some ( ref p) = css_file_extension {
299
+ is_unstable_flag_enabled ( nightly_build, has_z_unstable_options, "extend-css" ) ;
262
300
if !p. is_file ( ) {
263
301
println ! ( "{}" , "--extend-css option must take a css file as input" ) ;
264
302
return 1 ;
0 commit comments