1 use std::collections::BTreeMap;
2 use std::convert::TryFrom;
5 use std::path::PathBuf;
8 use rustc_data_structures::fx::FxHashMap;
9 use rustc_driver::print_flag_list;
10 use rustc_session::config::{
11 self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
13 use rustc_session::config::{get_cmd_lint_options, nightly_options};
14 use rustc_session::config::{
15 CodegenOptions, ErrorOutputType, Externs, JsonUnusedExterns, UnstableOptions,
17 use rustc_session::getopts;
18 use rustc_session::lint::Level;
19 use rustc_session::search_paths::SearchPath;
20 use rustc_span::edition::Edition;
21 use rustc_target::spec::TargetTriple;
23 use crate::core::new_handler;
24 use crate::externalfiles::ExternalHtml;
26 use crate::html::markdown::IdMap;
27 use crate::html::render::StylePath;
28 use crate::html::static_files;
30 use crate::passes::{self, Condition};
31 use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions};
34 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
35 pub(crate) enum OutputFormat {
40 impl Default for OutputFormat {
41 fn default() -> OutputFormat {
47 pub(crate) fn is_json(&self) -> bool {
48 matches!(self, OutputFormat::Json)
52 impl TryFrom<&str> for OutputFormat {
55 fn try_from(value: &str) -> Result<Self, Self::Error> {
57 "json" => Ok(OutputFormat::Json),
58 "html" => Ok(OutputFormat::Html),
59 _ => Err(format!("unknown output format `{}`", value)),
64 /// Configuration options for rustdoc.
66 pub(crate) struct Options {
67 // Basic options / Options passed directly to rustc
68 /// The crate root or Markdown file to load.
69 pub(crate) input: PathBuf,
70 /// The name of the crate being documented.
71 pub(crate) crate_name: Option<String>,
72 /// Whether or not this is a proc-macro crate
73 pub(crate) proc_macro_crate: bool,
74 /// How to format errors and warnings.
75 pub(crate) error_format: ErrorOutputType,
76 /// Width of output buffer to truncate errors appropriately.
77 pub(crate) diagnostic_width: Option<usize>,
78 /// Library search paths to hand to the compiler.
79 pub(crate) libs: Vec<SearchPath>,
80 /// Library search paths strings to hand to the compiler.
81 pub(crate) lib_strs: Vec<String>,
82 /// The list of external crates to link against.
83 pub(crate) externs: Externs,
84 /// The list of external crates strings to link against.
85 pub(crate) extern_strs: Vec<String>,
86 /// List of `cfg` flags to hand to the compiler. Always includes `rustdoc`.
87 pub(crate) cfgs: Vec<String>,
88 /// List of check cfg flags to hand to the compiler.
89 pub(crate) check_cfgs: Vec<String>,
90 /// Codegen options to hand to the compiler.
91 pub(crate) codegen_options: CodegenOptions,
92 /// Codegen options strings to hand to the compiler.
93 pub(crate) codegen_options_strs: Vec<String>,
94 /// Unstable (`-Z`) options to pass to the compiler.
95 pub(crate) unstable_opts: UnstableOptions,
96 /// Unstable (`-Z`) options strings to pass to the compiler.
97 pub(crate) unstable_opts_strs: Vec<String>,
98 /// The target used to compile the crate against.
99 pub(crate) target: TargetTriple,
100 /// Edition used when reading the crate. Defaults to "2015". Also used by default when
101 /// compiling doctests from the crate.
102 pub(crate) edition: Edition,
103 /// The path to the sysroot. Used during the compilation process.
104 pub(crate) maybe_sysroot: Option<PathBuf>,
105 /// Lint information passed over the command-line.
106 pub(crate) lint_opts: Vec<(String, Level)>,
107 /// Whether to ask rustc to describe the lints it knows.
108 pub(crate) describe_lints: bool,
109 /// What level to cap lints at.
110 pub(crate) lint_cap: Option<Level>,
112 // Options specific to running doctests
113 /// Whether we should run doctests instead of generating docs.
114 pub(crate) should_test: bool,
115 /// List of arguments to pass to the test harness, if running tests.
116 pub(crate) test_args: Vec<String>,
117 /// The working directory in which to run tests.
118 pub(crate) test_run_directory: Option<PathBuf>,
119 /// Optional path to persist the doctest executables to, defaults to a
120 /// temporary directory if not set.
121 pub(crate) persist_doctests: Option<PathBuf>,
122 /// Runtool to run doctests with
123 pub(crate) runtool: Option<String>,
124 /// Arguments to pass to the runtool
125 pub(crate) runtool_args: Vec<String>,
126 /// Whether to allow ignoring doctests on a per-target basis
127 /// For example, using ignore-foo to ignore running the doctest on any target that
128 /// contains "foo" as a substring
129 pub(crate) enable_per_target_ignores: bool,
130 /// Do not run doctests, compile them if should_test is active.
131 pub(crate) no_run: bool,
133 /// The path to a rustc-like binary to build tests with. If not set, we
134 /// default to loading from `$sysroot/bin/rustc`.
135 pub(crate) test_builder: Option<PathBuf>,
137 // Options that affect the documentation process
138 /// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
139 /// with and without documentation.
140 pub(crate) show_coverage: bool,
142 // Options that alter generated documentation pages
143 /// Crate version to note on the sidebar of generated docs.
144 pub(crate) crate_version: Option<String>,
145 /// The format that we output when rendering.
147 /// Currently used only for the `--show-coverage` option.
148 pub(crate) output_format: OutputFormat,
149 /// If this option is set to `true`, rustdoc will only run checks and not generate
151 pub(crate) run_check: bool,
152 /// Whether doctests should emit unused externs
153 pub(crate) json_unused_externs: JsonUnusedExterns,
154 /// Whether to skip capturing stdout and stderr of tests.
155 pub(crate) nocapture: bool,
157 /// Configuration for scraping examples from the current crate. If this option is Some(..) then
158 /// the compiler will scrape examples and not generate documentation.
159 pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>,
161 /// Note: this field is duplicated in `RenderOptions` because it's useful
162 /// to have it in both places.
163 pub(crate) unstable_features: rustc_feature::UnstableFeatures,
166 impl fmt::Debug for Options {
167 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168 struct FmtExterns<'a>(&'a Externs);
170 impl<'a> fmt::Debug for FmtExterns<'a> {
171 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
172 f.debug_map().entries(self.0.iter()).finish()
176 f.debug_struct("Options")
177 .field("input", &self.input)
178 .field("crate_name", &self.crate_name)
179 .field("proc_macro_crate", &self.proc_macro_crate)
180 .field("error_format", &self.error_format)
181 .field("libs", &self.libs)
182 .field("externs", &FmtExterns(&self.externs))
183 .field("cfgs", &self.cfgs)
184 .field("check-cfgs", &self.check_cfgs)
185 .field("codegen_options", &"...")
186 .field("unstable_options", &"...")
187 .field("target", &self.target)
188 .field("edition", &self.edition)
189 .field("maybe_sysroot", &self.maybe_sysroot)
190 .field("lint_opts", &self.lint_opts)
191 .field("describe_lints", &self.describe_lints)
192 .field("lint_cap", &self.lint_cap)
193 .field("should_test", &self.should_test)
194 .field("test_args", &self.test_args)
195 .field("test_run_directory", &self.test_run_directory)
196 .field("persist_doctests", &self.persist_doctests)
197 .field("show_coverage", &self.show_coverage)
198 .field("crate_version", &self.crate_version)
199 .field("runtool", &self.runtool)
200 .field("runtool_args", &self.runtool_args)
201 .field("enable-per-target-ignores", &self.enable_per_target_ignores)
202 .field("run_check", &self.run_check)
203 .field("no_run", &self.no_run)
204 .field("nocapture", &self.nocapture)
205 .field("scrape_examples_options", &self.scrape_examples_options)
206 .field("unstable_features", &self.unstable_features)
211 /// Configuration options for the HTML page-creation process.
212 #[derive(Clone, Debug)]
213 pub(crate) struct RenderOptions {
214 /// Output directory to generate docs into. Defaults to `doc`.
215 pub(crate) output: PathBuf,
216 /// External files to insert into generated pages.
217 pub(crate) external_html: ExternalHtml,
218 /// A pre-populated `IdMap` with the default headings and any headings added by Markdown files
219 /// processed by `external_html`.
220 pub(crate) id_map: IdMap,
221 /// If present, playground URL to use in the "Run" button added to code samples.
223 /// Be aware: This option can come both from the CLI and from crate attributes!
224 pub(crate) playground_url: Option<String>,
225 /// What sorting mode to use for module pages.
226 /// `ModuleSorting::Alphabetical` by default.
227 pub(crate) module_sorting: ModuleSorting,
228 /// List of themes to extend the docs with. Original argument name is included to assist in
229 /// displaying errors if it fails a theme check.
230 pub(crate) themes: Vec<StylePath>,
231 /// If present, CSS file that contains rules to add to the default CSS.
232 pub(crate) extension_css: Option<PathBuf>,
233 /// A map of crate names to the URL to use instead of querying the crate's `html_root_url`.
234 pub(crate) extern_html_root_urls: BTreeMap<String, String>,
235 /// Whether to give precedence to `html_root_url` or `--exten-html-root-url`.
236 pub(crate) extern_html_root_takes_precedence: bool,
237 /// A map of the default settings (values are as for DOM storage API). Keys should lack the
238 /// `rustdoc-` prefix.
239 pub(crate) default_settings: FxHashMap<String, String>,
240 /// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
241 pub(crate) resource_suffix: String,
242 /// Whether to create an index page in the root of the output directory. If this is true but
243 /// `enable_index_page` is None, generate a static listing of crates instead.
244 pub(crate) enable_index_page: bool,
245 /// A file to use as the index page at the root of the output directory. Overrides
246 /// `enable_index_page` to be true if set.
247 pub(crate) index_page: Option<PathBuf>,
248 /// An optional path to use as the location of static files. If not set, uses combinations of
249 /// `../` to reach the documentation root.
250 pub(crate) static_root_path: Option<String>,
252 // Options specific to reading standalone Markdown files
253 /// Whether to generate a table of contents on the output file when reading a standalone
255 pub(crate) markdown_no_toc: bool,
256 /// Additional CSS files to link in pages generated from standalone Markdown files.
257 pub(crate) markdown_css: Vec<String>,
258 /// If present, playground URL to use in the "Run" button added to code samples generated from
259 /// standalone Markdown files. If not present, `playground_url` is used.
260 pub(crate) markdown_playground_url: Option<String>,
261 /// Document items that have lower than `pub` visibility.
262 pub(crate) document_private: bool,
263 /// Document items that have `doc(hidden)`.
264 pub(crate) document_hidden: bool,
265 /// If `true`, generate a JSON file in the crate folder instead of HTML redirection files.
266 pub(crate) generate_redirect_map: bool,
267 /// Show the memory layout of types in the docs.
268 pub(crate) show_type_layout: bool,
269 /// Note: this field is duplicated in `Options` because it's useful to have
270 /// it in both places.
271 pub(crate) unstable_features: rustc_feature::UnstableFeatures,
272 pub(crate) emit: Vec<EmitType>,
273 /// If `true`, HTML source pages will generate links for items to their definition.
274 pub(crate) generate_link_to_definition: bool,
275 /// Set of function-call locations to include as examples
276 pub(crate) call_locations: AllCallLocations,
277 /// If `true`, Context::init will not emit shared files.
278 pub(crate) no_emit_shared: bool,
281 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
282 pub(crate) enum ModuleSorting {
287 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
288 pub(crate) enum EmitType {
294 impl FromStr for EmitType {
297 fn from_str(s: &str) -> Result<Self, Self::Err> {
300 "unversioned-shared-resources" => Ok(Unversioned),
301 "toolchain-shared-resources" => Ok(Toolchain),
302 "invocation-specific" => Ok(InvocationSpecific),
309 pub(crate) fn should_emit_crate(&self) -> bool {
310 self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific)
315 /// Parses the given command-line for options. If an error message or other early-return has
316 /// been printed, returns `Err` with the exit code.
317 pub(crate) fn from_matches(
318 matches: &getopts::Matches,
320 ) -> Result<(Options, RenderOptions), i32> {
321 let args = &args[1..];
322 // Check for unstable options.
323 nightly_options::check_nightly_options(matches, &opts());
325 if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") {
326 crate::usage("rustdoc");
328 } else if matches.opt_present("version") {
329 rustc_driver::version!("rustdoc", matches);
333 let z_flags = matches.opt_strs("Z");
334 if z_flags.iter().any(|x| *x == "help") {
335 print_flag_list("-Z", config::Z_OPTIONS);
338 let c_flags = matches.opt_strs("C");
339 if c_flags.iter().any(|x| *x == "help") {
340 print_flag_list("-C", config::CG_OPTIONS);
344 let color = config::parse_color(matches);
345 let config::JsonConfig { json_rendered, json_unused_externs, .. } =
346 config::parse_json(matches);
347 let error_format = config::parse_error_format(matches, color, json_rendered);
348 let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();
350 let codegen_options = CodegenOptions::build(matches, error_format);
351 let unstable_opts = UnstableOptions::build(matches, error_format);
353 let diag = new_handler(error_format, None, diagnostic_width, &unstable_opts);
355 // check for deprecated options
356 check_deprecated_options(matches, &diag);
358 if matches.opt_strs("passes") == ["list"] {
359 println!("Available passes for running rustdoc:");
360 for pass in passes::PASSES {
361 println!("{:>20} - {}", pass.name, pass.description);
363 println!("\nDefault passes for rustdoc:");
364 for p in passes::DEFAULT_PASSES {
365 print!("{:>20}", p.pass.name);
366 println_condition(p.condition);
369 if nightly_options::match_is_nightly_build(matches) {
370 println!("\nPasses run with `--show-coverage`:");
371 for p in passes::COVERAGE_PASSES {
372 print!("{:>20}", p.pass.name);
373 println_condition(p.condition);
377 fn println_condition(condition: Condition) {
380 Always => println!(),
381 WhenDocumentPrivate => println!(" (when --document-private-items)"),
382 WhenNotDocumentPrivate => println!(" (when not --document-private-items)"),
383 WhenNotDocumentHidden => println!(" (when not --document-hidden-items)"),
390 let mut emit = Vec::new();
391 for list in matches.opt_strs("emit") {
392 for kind in list.split(',') {
394 Ok(kind) => emit.push(kind),
396 diag.err(&format!("unrecognized emission type: {}", kind));
403 // check for `--output-format=json`
404 if !matches!(matches.opt_str("output-format").as_deref(), None | Some("html"))
405 && !matches.opt_present("show-coverage")
406 && !nightly_options::is_unstable_enabled(matches)
408 rustc_session::early_error(
410 "the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com/rust-lang/rust/issues/76578)",
414 let to_check = matches.opt_strs("check-theme");
415 if !to_check.is_empty() {
416 let paths = match theme::load_css_paths(
417 std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
421 diag.struct_err(e).emit();
427 println!("rustdoc: [check-theme] Starting tests! (Ignoring all other arguments)");
428 for theme_file in to_check.iter() {
429 print!(" - Checking \"{}\"...", theme_file);
430 let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag);
431 if !differences.is_empty() || !success {
434 if !differences.is_empty() {
435 println!("{}", differences.join("\n"));
447 let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
449 let input = PathBuf::from(if describe_lints {
450 "" // dummy, this won't be used
451 } else if matches.free.is_empty() {
452 diag.struct_err("missing file operand").emit();
454 } else if matches.free.len() > 1 {
455 diag.struct_err("too many file operands").emit();
464 .map(|s| SearchPath::from_cli_opt(s, error_format))
466 let externs = parse_externs(matches, &unstable_opts, error_format);
467 let extern_html_root_urls = match parse_extern_html_roots(matches) {
470 diag.struct_err(err).emit();
475 let default_settings: Vec<Vec<(String, String)>> = vec![
477 .opt_str("default-theme")
481 ("use-system-theme".to_string(), "false".to_string()),
482 ("theme".to_string(), theme.to_string()),
487 .opt_strs("default-setting")
489 .map(|s| match s.split_once('=') {
490 None => (s.clone(), "true".to_string()),
491 Some((k, v)) => (k.to_string(), v.to_string()),
495 let default_settings = default_settings
499 // The keys here become part of `data-` attribute names in the generated HTML. The
500 // browser does a strange mapping when converting them into attributes on the
501 // `dataset` property on the DOM HTML Node:
502 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
504 // The original key values we have are the same as the DOM storage API keys and the
505 // command line options, so contain `-`. Our Javascript needs to be able to look
506 // these values up both in `dataset` and in the storage API, so it needs to be able
507 // to convert the names back and forth. Despite doing this kebab-case to
508 // StudlyCaps transformation automatically, the JS DOM API does not provide a
509 // mechanism for doing the just transformation on a string. So we want to avoid
510 // the StudlyCaps representation in the `dataset` property.
512 // We solve this by replacing all the `-`s with `_`s. We do that here, when we
513 // generate the `data-` attributes, and in the JS, when we look them up. (See
514 // `getSettingValue` in `storage.js.`) Converting `-` to `_` is simple in JS.
516 // The values will be HTML-escaped by the default Tera escaping.
517 |(k, v)| (k.replace('-', "_"), v),
521 let test_args = matches.opt_strs("test-args");
522 let test_args: Vec<String> =
523 test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
525 let should_test = matches.opt_present("test");
526 let no_run = matches.opt_present("no-run");
528 if !should_test && no_run {
529 diag.err("the `--test` flag must be passed to enable `--no-run`");
533 let out_dir = matches.opt_str("out-dir").map(|s| PathBuf::from(&s));
534 let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
535 let output = match (out_dir, output) {
536 (Some(_), Some(_)) => {
537 diag.struct_err("cannot use both 'out-dir' and 'output' at once").emit();
540 (Some(out_dir), None) => out_dir,
541 (None, Some(output)) => output,
542 (None, None) => PathBuf::from("doc"),
545 let cfgs = matches.opt_strs("cfg");
546 let check_cfgs = matches.opt_strs("check-cfg");
548 let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));
550 if let Some(ref p) = extension_css {
552 diag.struct_err("option --extend-css argument must be a file").emit();
557 let mut themes = Vec::new();
558 if matches.opt_present("theme") {
559 let paths = match theme::load_css_paths(
560 std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
564 diag.struct_err(e).emit();
569 for (theme_file, theme_s) in
570 matches.opt_strs("theme").iter().map(|s| (PathBuf::from(&s), s.to_owned()))
572 if !theme_file.is_file() {
573 diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
574 .help("arguments to --theme must be files")
578 if theme_file.extension() != Some(OsStr::new("css")) {
579 diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
580 .help("arguments to --theme must have a .css extension")
584 let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
586 diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit();
588 } else if !ret.is_empty() {
589 diag.struct_warn(&format!(
590 "theme file \"{}\" is missing CSS rules from the default theme",
593 .warn("the theme may appear incorrect when loaded")
595 "to see what rules are missing, call `rustdoc --check-theme \"{}\"`",
600 themes.push(StylePath { path: theme_file });
604 let edition = config::parse_crate_edition(matches);
606 let mut id_map = html::markdown::IdMap::new();
607 let Some(external_html) = ExternalHtml::load(
608 &matches.opt_strs("html-in-header"),
609 &matches.opt_strs("html-before-content"),
610 &matches.opt_strs("html-after-content"),
611 &matches.opt_strs("markdown-before-content"),
612 &matches.opt_strs("markdown-after-content"),
613 nightly_options::match_is_nightly_build(matches),
622 match matches.opt_str("r").as_deref() {
623 Some("rust") | None => {}
625 diag.struct_err(&format!("unknown input format: {}", s)).emit();
630 let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s));
631 if let Some(ref index_page) = index_page {
632 if !index_page.is_file() {
633 diag.struct_err("option `--index-page` argument must be a file").emit();
638 let target = parse_target_triple(matches, error_format);
640 let show_coverage = matches.opt_present("show-coverage");
642 let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
645 diag.struct_err(&format!("unknown crate type: {}", e)).emit();
650 let output_format = match matches.opt_str("output-format") {
651 Some(s) => match OutputFormat::try_from(s.as_str()) {
653 if !out_fmt.is_json() && show_coverage {
655 "html output format isn't supported for the --show-coverage option",
663 diag.struct_err(&e).emit();
667 None => OutputFormat::default(),
669 let crate_name = matches.opt_str("crate-name");
670 let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
671 let playground_url = matches.opt_str("playground-url");
672 let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
673 let module_sorting = if matches.opt_present("sort-modules-by-appearance") {
674 ModuleSorting::DeclarationOrder
676 ModuleSorting::Alphabetical
678 let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
679 let markdown_no_toc = matches.opt_present("markdown-no-toc");
680 let markdown_css = matches.opt_strs("markdown-css");
681 let markdown_playground_url = matches.opt_str("markdown-playground-url");
682 let crate_version = matches.opt_str("crate-version");
683 let enable_index_page = matches.opt_present("enable-index-page") || index_page.is_some();
684 let static_root_path = matches.opt_str("static-root-path");
685 let test_run_directory = matches.opt_str("test-run-directory").map(PathBuf::from);
686 let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
687 let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
688 let codegen_options_strs = matches.opt_strs("C");
689 let unstable_opts_strs = matches.opt_strs("Z");
690 let lib_strs = matches.opt_strs("L");
691 let extern_strs = matches.opt_strs("extern");
692 let runtool = matches.opt_str("runtool");
693 let runtool_args = matches.opt_strs("runtool-arg");
694 let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
695 let document_private = matches.opt_present("document-private-items");
696 let document_hidden = matches.opt_present("document-hidden-items");
697 let run_check = matches.opt_present("check");
698 let generate_redirect_map = matches.opt_present("generate-redirect-map");
699 let show_type_layout = matches.opt_present("show-type-layout");
700 let nocapture = matches.opt_present("nocapture");
701 let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
702 let extern_html_root_takes_precedence =
703 matches.opt_present("extern-html-root-takes-precedence");
705 if generate_link_to_definition && (show_coverage || output_format != OutputFormat::Html) {
707 "--generate-link-to-definition option can only be used with HTML output format",
713 let scrape_examples_options = ScrapeExamplesOptions::new(matches, &diag)?;
714 let with_examples = matches.opt_strs("with-examples");
715 let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
717 let unstable_features =
718 rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
719 let options = Options {
731 codegen_options_strs,
748 enable_per_target_ignores,
756 scrape_examples_options,
759 let render_options = RenderOptions {
767 extern_html_root_urls,
768 extern_html_root_takes_precedence,
776 markdown_playground_url,
779 generate_redirect_map,
783 generate_link_to_definition,
785 no_emit_shared: false,
787 Ok((options, render_options))
790 /// Returns `true` if the file given as `self.input` is a Markdown file.
791 pub(crate) fn markdown_input(&self) -> bool {
792 self.input.extension().map_or(false, |e| e == "md" || e == "markdown")
796 /// Prints deprecation warnings for deprecated options
797 fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Handler) {
798 let deprecated_flags = [];
800 for &flag in deprecated_flags.iter() {
801 if matches.opt_present(flag) {
802 diag.struct_warn(&format!("the `{}` flag is deprecated", flag))
804 "see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
805 for more information",
811 let removed_flags = ["plugins", "plugin-path", "no-defaults", "passes", "input-format"];
813 for &flag in removed_flags.iter() {
814 if matches.opt_present(flag) {
815 let mut err = diag.struct_warn(&format!("the `{}` flag no longer functions", flag));
817 "see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
818 for more information",
821 if flag == "no-defaults" || flag == "passes" {
822 err.help("you may want to use --document-private-items");
823 } else if flag == "plugins" || flag == "plugin-path" {
824 err.warn("see CVE-2018-1000622");
832 /// Extracts `--extern-html-root-url` arguments from `matches` and returns a map of crate names to
833 /// the given URLs. If an `--extern-html-root-url` argument was ill-formed, returns an error
834 /// describing the issue.
835 fn parse_extern_html_roots(
836 matches: &getopts::Matches,
837 ) -> Result<BTreeMap<String, String>, &'static str> {
838 let mut externs = BTreeMap::new();
839 for arg in &matches.opt_strs("extern-html-root-url") {
841 arg.split_once('=').ok_or("--extern-html-root-url must be of the form name=url")?;
842 externs.insert(name.to_string(), url.to_string());