Skip to content

Commit 6bd9305

Browse files
XanewokMark-Simulacrum
authored andcommitted
Use empty typeck tables when nesting on items without those
1 parent ba9b8be commit 6bd9305

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 10 additions & 8 deletions
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

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

0 commit comments

Comments
 (0)