Skip to content

Commit 9221d4d

Browse files
committed
[tmp] Pass TyCtxt through to the render backend
First actually useful step in rust-lang#76382 This doesn't yet compile because there's no way to get a `Lrc<Session>` from a TyCtxt, only a `&Session`.
1 parent 79ab333 commit 9221d4d

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/librustdoc/formats/renderer.rs

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

3-
use rustc_data_structures::sync::Lrc;
4-
use rustc_session::Session;
3+
use rustc_middle::ty;
54
use rustc_span::edition::Edition;
65

76
use crate::clean;
@@ -21,7 +20,7 @@ crate trait FormatRenderer: Clone {
2120
render_info: RenderInfo,
2221
edition: Edition,
2322
cache: &mut Cache,
24-
sess: Lrc<Session>,
23+
tcx: ty::TyCtxt<'_>,
2524
) -> Result<(Self, clean::Crate), Error>;
2625

2726
/// Renders a single non-module item. This means no recursive sub-item rendering is required.
@@ -52,7 +51,7 @@ crate fn run_format<T: FormatRenderer>(
5251
render_info: RenderInfo,
5352
diag: &rustc_errors::Handler,
5453
edition: Edition,
55-
sess: Lrc<Session>,
54+
tcx: ty::TyCtxt<'_>,
5655
) -> Result<(), Error> {
5756
let (krate, mut cache) = Cache::from_krate(
5857
render_info.clone(),
@@ -63,7 +62,7 @@ crate fn run_format<T: FormatRenderer>(
6362
);
6463

6564
let (mut format_renderer, mut krate) =
66-
T::init(krate, options, render_info, edition, &mut cache, sess)?;
65+
T::init(krate, options, render_info, edition, &mut cache, tcx)?;
6766

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

src/librustdoc/html/render/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use rustc_hir as hir;
5757
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
5858
use rustc_hir::Mutability;
5959
use rustc_middle::middle::stability;
60+
use rustc_middle::ty;
6061
use rustc_session::Session;
6162
use rustc_span::edition::Edition;
6263
use rustc_span::hygiene::MacroKind;
@@ -388,7 +389,7 @@ impl FormatRenderer for Context {
388389
_render_info: RenderInfo,
389390
edition: Edition,
390391
cache: &mut Cache,
391-
sess: Lrc<Session>,
392+
tcx: ty::TyCtxt<'_>,
392393
) -> Result<(Context, clean::Crate), Error> {
393394
// need to save a copy of the options for rendering the index page
394395
let md_opts = options.clone();
@@ -462,7 +463,7 @@ impl FormatRenderer for Context {
462463
}
463464
let (sender, receiver) = channel();
464465
let mut scx = SharedContext {
465-
sess,
466+
tcx,
466467
collapsed: krate.collapsed,
467468
src_root,
468469
include_sources,

src/librustdoc/json/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::rc::Rc;
1414

1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::sync::Lrc;
17+
use rustc_middle::ty;
1718
use rustc_session::Session;
1819
use rustc_span::edition::Edition;
1920

@@ -127,12 +128,12 @@ impl FormatRenderer for JsonRenderer {
127128
_render_info: RenderInfo,
128129
_edition: Edition,
129130
_cache: &mut Cache,
130-
sess: Lrc<Session>,
131+
tcx: ty::TyCtxt<'_>,
131132
) -> Result<(Self, clean::Crate), Error> {
132133
debug!("Initializing json renderer");
133134
Ok((
134135
JsonRenderer {
135-
sess,
136+
sess: tcx.sess,
136137
index: Rc::new(RefCell::new(FxHashMap::default())),
137138
out_path: options.output,
138139
},

src/librustdoc/lib.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ use std::default::Default;
6262
use std::env;
6363
use std::process;
6464

65-
use rustc_data_structures::sync::Lrc;
6665
use rustc_driver::abort_on_err;
6766
use rustc_errors::ErrorReported;
68-
use rustc_interface::interface;
67+
use rustc_middle::ty;
6968
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
7069
use rustc_session::getopts;
71-
use rustc_session::Session;
7270
use rustc_session::{early_error, early_warn};
7371

7472
#[macro_use]
@@ -476,9 +474,9 @@ fn run_renderer<T: formats::FormatRenderer>(
476474
render_info: config::RenderInfo,
477475
diag: &rustc_errors::Handler,
478476
edition: rustc_span::edition::Edition,
479-
sess: Lrc<Session>,
477+
tcx: ty::TyCtxt<'_>,
480478
) -> MainResult {
481-
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, sess) {
479+
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, tcx) {
482480
Ok(_) => Ok(()),
483481
Err(e) => {
484482
let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error));
@@ -577,7 +575,6 @@ fn main_options(options: config::Options) -> MainResult {
577575
info!("going to format");
578576
let (error_format, edition, debugging_options) = diag_opts;
579577
let diag = core::new_handler(error_format, None, &debugging_options);
580-
let sess_format = sess.clone();
581578
match output_format {
582579
None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
583580
run_renderer::<html::render::Context>(
@@ -586,7 +583,7 @@ fn main_options(options: config::Options) -> MainResult {
586583
render_info,
587584
&diag,
588585
edition,
589-
sess_format,
586+
tcx,
590587
)
591588
}),
592589
Some(config::OutputFormat::Json) => sess.time("render_json", || {
@@ -596,7 +593,7 @@ fn main_options(options: config::Options) -> MainResult {
596593
render_info,
597594
&diag,
598595
edition,
599-
sess_format,
596+
tcx,
600597
)
601598
}),
602599
}

0 commit comments

Comments
 (0)