about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/lib.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 75652cc17ae..d5b2f2bb83e 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -65,8 +65,10 @@ use std::sync::mpsc::channel;
 use externalfiles::ExternalHtml;
 use serialize::Decodable;
 use serialize::json::{self, Json};
+use rustc::session::early_error;
 use rustc::session::search_paths::SearchPaths;
-use rustc::session::config::ErrorOutputType;
+use rustc::session::config::{get_unstable_features_setting, ErrorOutputType};
+use syntax::feature_gate::UnstableFeatures;
 
 // reexported from `clean` so it can be easily updated with the mod itself
 pub use clean::SCHEMA_VERSION;
@@ -189,6 +191,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
         optopt("e", "extend-css",
                "to redefine some css rules with a given file to generate doc with your \
                 own theme", "PATH"),
+        optmulti("Z", "", "internal and debugging options (only on nightly build)", "FLAG"),
     )
 }
 
@@ -198,6 +201,20 @@ pub fn usage(argv0: &str) {
                             &opts()));
 }
 
+fn check_unstable_flag_enabled(nightly_build: bool, has_z_unstable_options: bool,
+                               flag_name: &str) {
+    // check if unstable for --extend-css option
+    let e = if !nightly_build {
+        format!("the option `{}` is only accepted on the nightly compiler", flag_name)
+    } else if !has_z_unstable_options {
+        format!("the `-Z unstable-options` flag must also be passed to enable the flag `{}`",
+                flag_name)
+    } else {
+        return
+    };
+    early_error(ErrorOutputType::default(), &e)
+}
+
 pub fn main_args(args: &[String]) -> isize {
     let matches = match getopts::getopts(&args[1..], &opts()) {
         Ok(m) => m,
@@ -260,7 +277,24 @@ pub fn main_args(args: &[String]) -> isize {
     let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
     let cfgs = matches.opt_strs("cfg");
 
+    // we now check if unstable options are allowed and if we're in a nightly build
+    let mut has_z_unstable_options = false;
+    for flag in matches.opt_strs("Z").iter() {
+        if *flag != "unstable-options" {
+            println!("Unknown flag for `Z` option: {}", flag);
+            return 1;
+        } else {
+            has_z_unstable_options = true;
+        }
+    }
+    let nightly_build = get_unstable_features_setting();
+    let nightly_build = match nightly_build {
+                            UnstableFeatures::Allow | UnstableFeatures::Cheat => true,
+                            _ => false,
+                        };
+
     if let Some(ref p) = css_file_extension {
+        check_unstable_flag_enabled(nightly_build, has_z_unstable_options, "extend-css");
         if !p.is_file() {
             println!("{}", "--extend-css option must take a css file as input");
             return 1;