Skip to content

Commit f34ae3f

Browse files
Add nightly check on rustdoc --extend-css option
1 parent ab835a1 commit f34ae3f

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/librustdoc/lib.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ use std::sync::mpsc::channel;
6565
use externalfiles::ExternalHtml;
6666
use serialize::Decodable;
6767
use serialize::json::{self, Json};
68+
use rustc::session::early_error;
6869
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;
7072

7173
// reexported from `clean` so it can be easily updated with the mod itself
7274
pub use clean::SCHEMA_VERSION;
@@ -189,6 +191,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
189191
optopt("e", "extend-css",
190192
"to redefine some css rules with a given file to generate doc with your \
191193
own theme", "PATH"),
194+
optmulti("Z", "", "internal and debugging options (only on nightly build)", "FLAG"),
192195
)
193196
}
194197

@@ -198,6 +201,20 @@ pub fn usage(argv0: &str) {
198201
&opts()));
199202
}
200203

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+
201218
pub fn main_args(args: &[String]) -> isize {
202219
let matches = match getopts::getopts(&args[1..], &opts()) {
203220
Ok(m) => m,
@@ -260,7 +277,24 @@ pub fn main_args(args: &[String]) -> isize {
260277
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
261278
let cfgs = matches.opt_strs("cfg");
262279

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+
263296
if let Some(ref p) = css_file_extension {
297+
check_unstable_flag_enabled(nightly_build, has_z_unstable_options, "extend-css");
264298
if !p.is_file() {
265299
println!("{}", "--extend-css option must take a css file as input");
266300
return 1;

0 commit comments

Comments
 (0)