diff options
Diffstat (limited to 'src/librustdoc/lib.rs')
| -rw-r--r-- | src/librustdoc/lib.rs | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 28dbd8ba7d3..f62eba4b3c1 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -1,4 +1,5 @@ // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(round_char_boundary))] #![doc( html_root_url = "https://doc.rust-lang.org/nightly/", html_playground_url = "https://play.rust-lang.org/" @@ -11,8 +12,8 @@ #![feature(file_buffered)] #![feature(format_args_nl)] #![feature(if_let_guard)] +#![feature(iter_advance_by)] #![feature(iter_intersperse)] -#![feature(round_char_boundary)] #![feature(rustc_private)] #![feature(test)] #![warn(rustc::internal)] @@ -80,6 +81,8 @@ use rustc_session::{EarlyDiagCtxt, getopts}; use tracing::info; use crate::clean::utils::DOC_RUST_LANG_ORG_VERSION; +use crate::error::Error; +use crate::formats::cache::Cache; /// A macro to create a FxHashMap. /// @@ -663,6 +666,14 @@ fn opts() -> Vec<RustcOptGroup> { "disable the minification of CSS/JS files (perma-unstable, do not use with cached files)", "", ), + opt( + Unstable, + Flag, + "", + "generate-macro-expansion", + "Add possibility to expand macros in the HTML source code pages", + "", + ), // deprecated / removed options opt( Stable, @@ -726,20 +737,32 @@ pub(crate) fn wrap_return(dcx: DiagCtxtHandle<'_>, res: Result<(), String>) { } } -fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( +fn run_renderer< + 'tcx, + T: formats::FormatRenderer<'tcx>, + F: FnOnce( + clean::Crate, + config::RenderOptions, + Cache, + TyCtxt<'tcx>, + ) -> Result<(T, clean::Crate), Error>, +>( krate: clean::Crate, renderopts: config::RenderOptions, cache: formats::cache::Cache, tcx: TyCtxt<'tcx>, + init: F, ) { - match formats::run_format::<T>(krate, renderopts, cache, tcx) { + match formats::run_format::<T, F>(krate, renderopts, cache, tcx, init) { Ok(_) => tcx.dcx().abort_if_errors(), Err(e) => { let mut msg = tcx.dcx().struct_fatal(format!("couldn't generate documentation: {}", e.error)); let file = e.file.display().to_string(); if !file.is_empty() { - msg.note(format!("failed to create or modify \"{file}\"")); + msg.note(format!("failed to create or modify {e}")); + } else { + msg.note(format!("failed to create or modify file: {e}")); } msg.emit(); } @@ -862,6 +885,7 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { let scrape_examples_options = options.scrape_examples_options.clone(); let bin_crate = options.bin_crate; + let output_format = options.output_format; let config = core::create_config(input, options, &render_options); let registered_lints = config.register_lints.is_some(); @@ -886,9 +910,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { sess.dcx().fatal("Compilation failed, aborting rustdoc"); } - let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || { - core::run_global_ctxt(tcx, show_coverage, render_options, output_format) - }); + let (krate, render_opts, mut cache, expanded_macros) = sess + .time("run_global_ctxt", || { + core::run_global_ctxt(tcx, show_coverage, render_options, output_format) + }); info!("finished with rustc"); if let Some(options) = scrape_examples_options { @@ -919,10 +944,24 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { info!("going to format"); match output_format { config::OutputFormat::Html => sess.time("render_html", || { - run_renderer::<html::render::Context<'_>>(krate, render_opts, cache, tcx) + run_renderer( + krate, + render_opts, + cache, + tcx, + |krate, render_opts, cache, tcx| { + html::render::Context::init( + krate, + render_opts, + cache, + tcx, + expanded_macros, + ) + }, + ) }), config::OutputFormat::Json => sess.time("render_json", || { - run_renderer::<json::JsonRenderer<'_>>(krate, render_opts, cache, tcx) + run_renderer(krate, render_opts, cache, tcx, json::JsonRenderer::init) }), // Already handled above with doctest runners. config::OutputFormat::Doctest => unreachable!(), |
