Skip to content

Commit af6aa9f

Browse files
committed
Pass Session into renderer
1 parent 39b841d commit af6aa9f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/librustdoc/formats/renderer.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::sync::Arc;
22

3+
use rustc_data_structures::sync::Lrc;
4+
use rustc_session::Session;
35
use rustc_span::edition::Edition;
46

57
use crate::clean;
@@ -19,6 +21,7 @@ crate trait FormatRenderer: Clone {
1921
render_info: RenderInfo,
2022
edition: Edition,
2123
cache: &mut Cache,
24+
sess: Lrc<Session>,
2225
) -> Result<(Self, clean::Crate), Error>;
2326

2427
/// 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>(
4952
render_info: RenderInfo,
5053
diag: &rustc_errors::Handler,
5154
edition: Edition,
55+
sess: Lrc<Session>,
5256
) -> Result<(), Error> {
5357
let (krate, mut cache) = Cache::from_krate(
5458
render_info.clone(),
@@ -59,7 +63,7 @@ crate fn run_format<T: FormatRenderer>(
5963
);
6064

6165
let (mut format_renderer, mut krate) =
62-
T::init(krate, options, render_info, edition, &mut cache)?;
66+
T::init(krate, options, render_info, edition, &mut cache, sess)?;
6367

6468
let cache = Arc::new(cache);
6569
// Freeze the cache now that the index has been built. Put an Arc into TLS for future

src/librustdoc/html/render/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ use rustc_ast_pretty::pprust;
5252
use rustc_attr::StabilityLevel;
5353
use rustc_data_structures::flock;
5454
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55+
use rustc_data_structures::sync::Lrc;
5556
use rustc_hir as hir;
5657
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
5758
use rustc_hir::Mutability;
5859
use rustc_middle::middle::stability;
60+
use rustc_session::Session;
5961
use rustc_span::edition::Edition;
6062
use rustc_span::hygiene::MacroKind;
6163
use rustc_span::source_map::FileName;
@@ -101,6 +103,7 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
101103
/// rustdoc tree).
102104
#[derive(Clone)]
103105
crate struct Context {
106+
crate sess: Lrc<Session>,
104107
/// Current hierarchy of components leading down to what's currently being
105108
/// rendered
106109
crate current: Vec<String>,
@@ -383,6 +386,7 @@ impl FormatRenderer for Context {
383386
_render_info: RenderInfo,
384387
edition: Edition,
385388
cache: &mut Cache,
389+
sess: Lrc<Session>,
386390
) -> Result<(Context, clean::Crate), Error> {
387391
// need to save a copy of the options for rendering the index page
388392
let md_opts = options.clone();
@@ -494,6 +498,7 @@ impl FormatRenderer for Context {
494498

495499
let cache = Arc::new(cache);
496500
let mut cx = Context {
501+
sess,
497502
current: Vec::new(),
498503
dst,
499504
render_redirect_pages: false,

src/librustdoc/json/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::path::PathBuf;
1313
use std::rc::Rc;
1414

1515
use rustc_data_structures::fx::FxHashMap;
16+
use rustc_data_structures::sync::Lrc;
17+
use rustc_session::Session;
1618
use rustc_span::edition::Edition;
1719

1820
use crate::clean;
@@ -124,6 +126,7 @@ impl FormatRenderer for JsonRenderer {
124126
_render_info: RenderInfo,
125127
_edition: Edition,
126128
_cache: &mut Cache,
129+
_sess: Lrc<Session>,
127130
) -> Result<(Self, clean::Crate), Error> {
128131
debug!("Initializing json renderer");
129132
Ok((

src/librustdoc/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ use std::default::Default;
6161
use std::env;
6262
use std::process;
6363

64+
use rustc_data_structures::sync::Lrc;
6465
use rustc_errors::ErrorReported;
6566
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
6667
use rustc_session::getopts;
68+
use rustc_session::Session;
6769
use rustc_session::{early_error, early_warn};
6870

6971
#[macro_use]
@@ -483,8 +485,9 @@ fn run_renderer<T: formats::FormatRenderer>(
483485
render_info: config::RenderInfo,
484486
diag: &rustc_errors::Handler,
485487
edition: rustc_span::edition::Edition,
488+
sess: Lrc<Session>,
486489
) -> MainResult {
487-
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition) {
490+
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, sess) {
488491
Ok(_) => Ok(()),
489492
Err(e) => {
490493
let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error));
@@ -554,10 +557,12 @@ fn main_options(options: config::Options) -> MainResult {
554557
let diag = core::new_handler(error_format, None, &debugging_options);
555558
match output_format {
556559
None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
557-
run_renderer::<html::render::Context>(krate, renderopts, renderinfo, &diag, edition)
560+
run_renderer::<html::render::Context>(
561+
krate, renderopts, renderinfo, &diag, edition, sess,
562+
)
558563
}),
559564
Some(config::OutputFormat::Json) => sess.time("render_json", || {
560-
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition)
565+
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition, sess)
561566
}),
562567
}
563568
}

0 commit comments

Comments
 (0)