Remove ResolverTree

This commit is contained in:
Oli Scherer 2023-02-18 08:12:49 +00:00
parent 2a47113efa
commit 0847b79ada
2 changed files with 4 additions and 25 deletions

View File

@ -1,4 +1,4 @@
use crate::{NameBinding, NameBindingKind, Resolver, ResolverTree};
use crate::{NameBinding, NameBindingKind, Resolver};
use rustc_ast::ast;
use rustc_ast::visit;
use rustc_ast::visit::Visitor;
@ -100,11 +100,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
for (binding, eff_vis) in visitor.import_effective_visibilities.iter() {
let NameBindingKind::Import { import, .. } = binding.kind else { unreachable!() };
if let Some(node_id) = import.id() {
r.effective_visibilities.update_eff_vis(
r.local_def_id(node_id),
eff_vis,
ResolverTree(&r.tcx.untracked()),
)
r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx)
}
}

View File

@ -44,7 +44,7 @@ use rustc_middle::span_bug;
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, TyCtxt};
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::cstore::{CrateStore, Untracked};
use rustc_session::cstore::CrateStore;
use rustc_session::lint::LintBuffer;
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
use rustc_span::source_map::Spanned;
@ -1113,27 +1113,10 @@ impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for Resolver<'a, 'tcx> {
}
}
/// A minimal subset of resolver that can implemenent `DefIdTree`, sometimes
/// required to satisfy borrow checker by avoiding borrowing the whole resolver.
#[derive(Clone, Copy)]
struct ResolverTree<'a>(&'a Untracked);
impl DefIdTree for ResolverTree<'_> {
#[inline]
fn opt_parent(self, id: DefId) -> Option<DefId> {
let ResolverTree(Untracked { definitions, cstore, .. }) = self;
match id.as_local() {
Some(id) => definitions.read().def_key(id).parent,
None => cstore.read().as_any().downcast_ref::<CStore>().unwrap().def_key(id).parent,
}
.map(|index| DefId { index, ..id })
}
}
impl<'a, 'b, 'tcx> DefIdTree for &'a Resolver<'b, 'tcx> {
#[inline]
fn opt_parent(self, id: DefId) -> Option<DefId> {
ResolverTree(&self.tcx.untracked()).opt_parent(id)
self.tcx.opt_parent(id)
}
}