Skip to content

Commit 6b50bc5

Browse files
committed
[perf] rustdoc: Don't obtain early resolver unless --generate-macro-expansion
1 parent a171994 commit 6b50bc5

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/librustdoc/core.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,7 @@ pub(crate) fn run_global_ctxt(
340340
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
341341
// so type-check everything other than function bodies in this crate before running lints.
342342

343-
let expanded_macros = {
344-
// We need for these variables to be removed to ensure that the `Crate` won't be "stolen"
345-
// anymore.
346-
let (_resolver, krate) = &*tcx.resolver_for_lowering().borrow();
347-
348-
source_macro_expansion(&krate, &render_options, output_format, tcx.sess.source_map())
349-
};
343+
let expanded_macros = source_macro_expansion(&render_options, output_format, tcx);
350344

351345
// NOTE: this does not call `tcx.analysis()` so that we won't
352346
// typeck function bodies or run the default rustc lints.

src/librustdoc/html/macro_expansion.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
use rustc_ast::visit::{Visitor, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt};
2-
use rustc_ast::{Crate, Expr, Item, Pat, Stmt};
2+
use rustc_ast::{Expr, Item, Pat, Stmt};
33
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_middle::ty::TyCtxt;
45
use rustc_span::source_map::SourceMap;
56
use rustc_span::{BytePos, Span};
67

78
use crate::config::{OutputFormat, RenderOptions};
89

910
/// It returns the expanded macros correspondence map.
1011
pub(crate) fn source_macro_expansion(
11-
krate: &Crate,
1212
render_options: &RenderOptions,
1313
output_format: OutputFormat,
14-
source_map: &SourceMap,
14+
tcx: TyCtxt<'_>,
1515
) -> FxHashMap<BytePos, Vec<ExpandedCode>> {
16-
if output_format == OutputFormat::Html
16+
if render_options.generate_macro_expansion
17+
&& output_format == OutputFormat::Html
1718
&& !render_options.html_no_source
18-
&& render_options.generate_macro_expansion
1919
{
20+
// We need for these variables to be removed to ensure that the `Crate` won't be "stolen"
21+
// anymore.
22+
let (_resolver, krate) = &*tcx.resolver_for_lowering().borrow();
23+
let source_map = tcx.sess.source_map();
24+
2025
let mut expanded_visitor = ExpandedCodeVisitor { expanded_codes: Vec::new(), source_map };
2126
walk_crate(&mut expanded_visitor, krate);
2227
expanded_visitor.compute_expanded()

0 commit comments

Comments
 (0)