Skip to content

Commit

Permalink
Use empty typeck tables when nesting on items without those
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Oct 13, 2019
1 parent 429fc9d commit 7b3cd1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/librustc_save_analysis/dump_visitor.rs
Expand Up @@ -115,15 +115,17 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
F: FnOnce(&mut Self),
{
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
if self.tcx.has_typeck_tables(item_def_id) {
let tables = self.tcx.typeck_tables_of(item_def_id);
let old_tables = self.save_ctxt.tables;
self.save_ctxt.tables = tables;
f(self);
self.save_ctxt.tables = old_tables;

let tables = if self.tcx.has_typeck_tables(item_def_id) {
self.tcx.typeck_tables_of(item_def_id)
} else {
f(self);
}
self.save_ctxt.empty_tables
};

let old_tables = self.save_ctxt.tables;
self.save_ctxt.tables = tables;
f(self);
self.save_ctxt.tables = old_tables;
}

fn span_from_span(&self, span: Span) -> SpanData {
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_save_analysis/lib.rs
Expand Up @@ -48,6 +48,9 @@ use log::{debug, error, info};
pub struct SaveContext<'l, 'tcx> {
tcx: TyCtxt<'tcx>,
tables: &'l ty::TypeckTables<'tcx>,
/// Used as a fallback when nesting the typeck tables during item processing
/// (if these are not available for that item, e.g. don't own a body)
empty_tables: &'l ty::TypeckTables<'tcx>,
access_levels: &'l AccessLevels,
span_utils: SpanUtils<'tcx>,
config: Config,
Expand Down Expand Up @@ -1114,6 +1117,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
let save_ctxt = SaveContext {
tcx,
tables: &ty::TypeckTables::empty(None),
empty_tables: &ty::TypeckTables::empty(None),
access_levels: &access_levels,
span_utils: SpanUtils::new(&tcx.sess),
config: find_config(config),
Expand Down

0 comments on commit 7b3cd1b

Please sign in to comment.