1
Fork 0

Pass Session into renderer

This commit is contained in:
Joshua Nelson 2020-12-11 22:36:51 -05:00
parent 39b841dfe3
commit af6aa9f431
4 changed files with 21 additions and 4 deletions

View file

@ -1,5 +1,7 @@
use std::sync::Arc;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition;
use crate::clean;
@ -19,6 +21,7 @@ crate trait FormatRenderer: Clone {
render_info: RenderInfo,
edition: Edition,
cache: &mut Cache,
sess: Lrc<Session>,
) -> Result<(Self, clean::Crate), Error>;
/// Renders a single non-module item. This means no recursive sub-item rendering is required.
@ -49,6 +52,7 @@ crate fn run_format<T: FormatRenderer>(
render_info: RenderInfo,
diag: &rustc_errors::Handler,
edition: Edition,
sess: Lrc<Session>,
) -> Result<(), Error> {
let (krate, mut cache) = Cache::from_krate(
render_info.clone(),
@ -59,7 +63,7 @@ crate fn run_format<T: FormatRenderer>(
);
let (mut format_renderer, mut krate) =
T::init(krate, options, render_info, edition, &mut cache)?;
T::init(krate, options, render_info, edition, &mut cache, sess)?;
let cache = Arc::new(cache);
// Freeze the cache now that the index has been built. Put an Arc into TLS for future

View file

@ -52,10 +52,12 @@ use rustc_ast_pretty::pprust;
use rustc_attr::StabilityLevel;
use rustc_data_structures::flock;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::Mutability;
use rustc_middle::middle::stability;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::FileName;
@ -101,6 +103,7 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
/// rustdoc tree).
#[derive(Clone)]
crate struct Context {
crate sess: Lrc<Session>,
/// Current hierarchy of components leading down to what's currently being
/// rendered
crate current: Vec<String>,
@ -383,6 +386,7 @@ impl FormatRenderer for Context {
_render_info: RenderInfo,
edition: Edition,
cache: &mut Cache,
sess: Lrc<Session>,
) -> Result<(Context, clean::Crate), Error> {
// need to save a copy of the options for rendering the index page
let md_opts = options.clone();
@ -494,6 +498,7 @@ impl FormatRenderer for Context {
let cache = Arc::new(cache);
let mut cx = Context {
sess,
current: Vec::new(),
dst,
render_redirect_pages: false,

View file

@ -13,6 +13,8 @@ use std::path::PathBuf;
use std::rc::Rc;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition;
use crate::clean;
@ -124,6 +126,7 @@ impl FormatRenderer for JsonRenderer {
_render_info: RenderInfo,
_edition: Edition,
_cache: &mut Cache,
_sess: Lrc<Session>,
) -> Result<(Self, clean::Crate), Error> {
debug!("Initializing json renderer");
Ok((

View file

@ -61,9 +61,11 @@ use std::default::Default;
use std::env;
use std::process;
use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorReported;
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
use rustc_session::getopts;
use rustc_session::Session;
use rustc_session::{early_error, early_warn};
#[macro_use]
@ -483,8 +485,9 @@ fn run_renderer<T: formats::FormatRenderer>(
render_info: config::RenderInfo,
diag: &rustc_errors::Handler,
edition: rustc_span::edition::Edition,
sess: Lrc<Session>,
) -> MainResult {
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition) {
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, sess) {
Ok(_) => Ok(()),
Err(e) => {
let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error));
@ -554,10 +557,12 @@ fn main_options(options: config::Options) -> MainResult {
let diag = core::new_handler(error_format, None, &debugging_options);
match output_format {
None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
run_renderer::<html::render::Context>(krate, renderopts, renderinfo, &diag, edition)
run_renderer::<html::render::Context>(
krate, renderopts, renderinfo, &diag, edition, sess,
)
}),
Some(config::OutputFormat::Json) => sess.time("render_json", || {
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition)
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition, sess)
}),
}
}