Skip to content

Commit 7b3cd1b

Browse files
committed
Use empty typeck tables when nesting on items without those
1 parent 429fc9d commit 7b3cd1b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/librustc_save_analysis/dump_visitor.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
115115
F: FnOnce(&mut Self),
116116
{
117117
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
118-
if self.tcx.has_typeck_tables(item_def_id) {
119-
let tables = self.tcx.typeck_tables_of(item_def_id);
120-
let old_tables = self.save_ctxt.tables;
121-
self.save_ctxt.tables = tables;
122-
f(self);
123-
self.save_ctxt.tables = old_tables;
118+
119+
let tables = if self.tcx.has_typeck_tables(item_def_id) {
120+
self.tcx.typeck_tables_of(item_def_id)
124121
} else {
125-
f(self);
126-
}
122+
self.save_ctxt.empty_tables
123+
};
124+
125+
let old_tables = self.save_ctxt.tables;
126+
self.save_ctxt.tables = tables;
127+
f(self);
128+
self.save_ctxt.tables = old_tables;
127129
}
128130

129131
fn span_from_span(&self, span: Span) -> SpanData {

src/librustc_save_analysis/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ use log::{debug, error, info};
4848
pub struct SaveContext<'l, 'tcx> {
4949
tcx: TyCtxt<'tcx>,
5050
tables: &'l ty::TypeckTables<'tcx>,
51+
/// Used as a fallback when nesting the typeck tables during item processing
52+
/// (if these are not available for that item, e.g. don't own a body)
53+
empty_tables: &'l ty::TypeckTables<'tcx>,
5154
access_levels: &'l AccessLevels,
5255
span_utils: SpanUtils<'tcx>,
5356
config: Config,
@@ -1114,6 +1117,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11141117
let save_ctxt = SaveContext {
11151118
tcx,
11161119
tables: &ty::TypeckTables::empty(None),
1120+
empty_tables: &ty::TypeckTables::empty(None),
11171121
access_levels: &access_levels,
11181122
span_utils: SpanUtils::new(&tcx.sess),
11191123
config: find_config(config),

0 commit comments

Comments
 (0)