|
1 | 1 | 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}; |
3 | 3 | use rustc_data_structures::fx::FxHashMap; |
| 4 | +use rustc_middle::ty::TyCtxt; |
4 | 5 | use rustc_span::source_map::SourceMap; |
5 | 6 | use rustc_span::{BytePos, Span}; |
6 | 7 |
|
7 | 8 | use crate::config::{OutputFormat, RenderOptions}; |
8 | 9 |
|
9 | 10 | /// It returns the expanded macros correspondence map. |
10 | 11 | pub(crate) fn source_macro_expansion( |
11 | | - krate: &Crate, |
12 | 12 | render_options: &RenderOptions, |
13 | 13 | output_format: OutputFormat, |
14 | | - source_map: &SourceMap, |
| 14 | + tcx: TyCtxt<'_>, |
15 | 15 | ) -> FxHashMap<BytePos, Vec<ExpandedCode>> { |
16 | | - if output_format == OutputFormat::Html |
| 16 | + if render_options.generate_macro_expansion |
| 17 | + && output_format == OutputFormat::Html |
17 | 18 | && !render_options.html_no_source |
18 | | - && render_options.generate_macro_expansion |
19 | 19 | { |
| 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 | + |
20 | 25 | let mut expanded_visitor = ExpandedCodeVisitor { expanded_codes: Vec::new(), source_map }; |
21 | 26 | walk_crate(&mut expanded_visitor, krate); |
22 | 27 | expanded_visitor.compute_expanded() |
|
0 commit comments