Auto merge of #108351 - petrochenkov:rmdit, r=cjgillot
rustc_middle: Remove trait `DefIdTree` This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
This commit is contained in:
commit
0d439f8181
90 changed files with 118 additions and 154 deletions
|
@ -25,9 +25,8 @@ use rustc_expand::expand::AstFragment;
|
|||
use rustc_hir::def::{self, *};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_metadata::creader::LoadedMacro;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::ty::{self, DefIdTree};
|
||||
use rustc_middle::{bug, ty};
|
||||
use rustc_session::cstore::CrateStore;
|
||||
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
|
||||
use rustc_span::source_map::respan;
|
||||
|
@ -99,7 +98,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
loop {
|
||||
match self.get_module(def_id) {
|
||||
Some(module) => return module,
|
||||
None => def_id = self.parent(def_id),
|
||||
None => def_id = self.tcx.parent(def_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -775,7 +774,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
let field_vis = self
|
||||
.try_resolve_visibility(&field.vis, false)
|
||||
.unwrap_or(ty::Visibility::Public);
|
||||
if ctor_vis.is_at_least(field_vis, &*self.r) {
|
||||
if ctor_vis.is_at_least(field_vis, self.r.tcx) {
|
||||
ctor_vis = field_vis;
|
||||
}
|
||||
ret_fields.push(field_vis.to_def_id());
|
||||
|
@ -1414,10 +1413,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
|
||||
if !(ctxt == AssocCtxt::Impl
|
||||
&& matches!(item.vis.kind, ast::VisibilityKind::Inherited)
|
||||
&& self
|
||||
.r
|
||||
.trait_impl_items
|
||||
.contains(&ty::DefIdTree::local_parent(&*self.r, local_def_id)))
|
||||
&& self.r.trait_impl_items.contains(&self.r.tcx.local_parent(local_def_id)))
|
||||
{
|
||||
// Trait impl item visibility is inherited from its trait when not specified
|
||||
// explicitly. In that case we cannot determine it here in early resolve,
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
|
|||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::PrimTy;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::{DefIdTree, TyCtxt};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::lint::builtin::ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE;
|
||||
use rustc_session::lint::builtin::MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS;
|
||||
use rustc_session::lint::BuiltinLintDiagnostics;
|
||||
|
@ -1197,7 +1197,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
segms.push(ast::PathSegment::from_ident(ident));
|
||||
let path = Path { span: name_binding.span, segments: segms, tokens: None };
|
||||
let did = match res {
|
||||
Res::Def(DefKind::Ctor(..), did) => this.opt_parent(did),
|
||||
Res::Def(DefKind::Ctor(..), did) => this.tcx.opt_parent(did),
|
||||
_ => res.opt_def_id(),
|
||||
};
|
||||
|
||||
|
@ -1591,7 +1591,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
ctor_def_id,
|
||||
)) = binding.kind
|
||||
{
|
||||
let def_id = self.parent(ctor_def_id);
|
||||
let def_id = self.tcx.parent(ctor_def_id);
|
||||
let fields = self.field_names.get(&def_id)?;
|
||||
return fields.iter().map(|name| name.span).reduce(Span::to); // None for `struct Foo()`
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_hir::def_id::LocalDefId;
|
|||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_middle::middle::privacy::Level;
|
||||
use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility};
|
||||
use rustc_middle::ty::{DefIdTree, Visibility};
|
||||
use rustc_middle::ty::Visibility;
|
||||
use std::mem;
|
||||
|
||||
type ImportId<'a> = Interned<'a, NameBinding<'a>>;
|
||||
|
@ -60,7 +60,7 @@ impl Resolver<'_, '_> {
|
|||
// For mod items `nearest_normal_mod` returns its argument, but we actually need its parent.
|
||||
let normal_mod_id = self.nearest_normal_mod(def_id);
|
||||
if normal_mod_id == def_id {
|
||||
self.opt_local_parent(def_id).map_or(Visibility::Public, Visibility::Restricted)
|
||||
self.tcx.opt_local_parent(def_id).map_or(Visibility::Public, Visibility::Restricted)
|
||||
} else {
|
||||
Visibility::Restricted(normal_mod_id)
|
||||
}
|
||||
|
|
|
@ -245,7 +245,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
import: &'a Import<'a>,
|
||||
) -> &'a NameBinding<'a> {
|
||||
let import_vis = import.expect_vis().to_def_id();
|
||||
let vis = if binding.vis.is_at_least(import_vis, self)
|
||||
let vis = if binding.vis.is_at_least(import_vis, self.tcx)
|
||||
|| pub_use_of_private_extern_crate_hack(import, binding)
|
||||
{
|
||||
import_vis
|
||||
|
@ -255,7 +255,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
if let ImportKind::Glob { ref max_vis, .. } = import.kind {
|
||||
if vis == import_vis
|
||||
|| max_vis.get().map_or(true, |max_vis| vis.is_at_least(max_vis, self))
|
||||
|| max_vis.get().map_or(true, |max_vis| vis.is_at_least(max_vis, self.tcx))
|
||||
{
|
||||
max_vis.set(Some(vis.expect_local()))
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
old_binding,
|
||||
binding,
|
||||
));
|
||||
} else if !old_binding.vis.is_at_least(binding.vis, &*this) {
|
||||
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
|
||||
// We are glob-importing the same item but with greater visibility.
|
||||
resolution.binding = Some(binding);
|
||||
}
|
||||
|
@ -786,7 +786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
if !is_prelude
|
||||
&& let Some(max_vis) = max_vis.get()
|
||||
&& !max_vis.is_at_least(import.expect_vis(), &*self)
|
||||
&& !max_vis.is_at_least(import.expect_vis(), self.tcx)
|
||||
{
|
||||
let msg = "glob import doesn't reexport anything because no candidate is public enough";
|
||||
self.lint_buffer.buffer_lint(UNUSED_IMPORTS, id, import.span, msg);
|
||||
|
@ -977,7 +977,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let mut crate_private_reexport = false;
|
||||
self.per_ns(|this, ns| {
|
||||
if let Ok(binding) = source_bindings[ns].get() {
|
||||
if !binding.vis.is_at_least(import.expect_vis(), &*this) {
|
||||
if !binding.vis.is_at_least(import.expect_vis(), this.tcx) {
|
||||
reexport_error = Some((ns, binding));
|
||||
if let ty::Visibility::Restricted(binding_def_id) = binding.vis {
|
||||
if binding_def_id.is_top_level_module() {
|
||||
|
|
|
@ -22,7 +22,6 @@ use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, PartialRes, PerNS};
|
|||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::{BindingAnnotation, PrimTy, TraitCandidate};
|
||||
use rustc_middle::middle::resolve_bound_vars::Set1;
|
||||
use rustc_middle::ty::DefIdTree;
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::config::{CrateType, ResolveDocLinks};
|
||||
use rustc_session::lint;
|
||||
|
@ -1671,8 +1670,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
// Figure out if this is a type/trait segment,
|
||||
// which may need lifetime elision performed.
|
||||
let type_def_id = match partial_res.base_res() {
|
||||
Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start => self.r.parent(def_id),
|
||||
Res::Def(DefKind::Variant, def_id) if i + 1 == proj_start => self.r.parent(def_id),
|
||||
Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start => {
|
||||
self.r.tcx.parent(def_id)
|
||||
}
|
||||
Res::Def(DefKind::Variant, def_id) if i + 1 == proj_start => {
|
||||
self.r.tcx.parent(def_id)
|
||||
}
|
||||
Res::Def(DefKind::Struct, def_id)
|
||||
| Res::Def(DefKind::Union, def_id)
|
||||
| Res::Def(DefKind::Enum, def_id)
|
||||
|
|
|
@ -21,7 +21,6 @@ use rustc_hir::def::Namespace::{self, *};
|
|||
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::PrimTy;
|
||||
use rustc_middle::ty::DefIdTree;
|
||||
use rustc_session::lint;
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_session::Session;
|
||||
|
@ -1508,7 +1507,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
}
|
||||
}
|
||||
(Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_def_id), _) if ns == ValueNS => {
|
||||
let def_id = self.r.parent(ctor_def_id);
|
||||
let def_id = self.r.tcx.parent(ctor_def_id);
|
||||
if let Some(span) = self.def_span(def_id) {
|
||||
err.span_label(span, &format!("`{}` defined here", path_str));
|
||||
}
|
||||
|
@ -1999,7 +1998,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
}
|
||||
} else {
|
||||
let needs_placeholder = |ctor_def_id: DefId, kind: CtorKind| {
|
||||
let def_id = self.r.parent(ctor_def_id);
|
||||
let def_id = self.r.tcx.parent(ctor_def_id);
|
||||
let has_no_fields = self.r.field_names.get(&def_id).map_or(false, |f| f.is_empty());
|
||||
match kind {
|
||||
CtorKind::Const => false,
|
||||
|
|
|
@ -44,7 +44,7 @@ use rustc_metadata::creader::{CStore, CrateLoader};
|
|||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, TyCtxt};
|
||||
use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt};
|
||||
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::cstore::CrateStore;
|
||||
|
@ -1117,13 +1117,6 @@ impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> DefIdTree for &'a Resolver<'b, 'tcx> {
|
||||
#[inline]
|
||||
fn opt_parent(self, id: DefId) -> Option<DefId> {
|
||||
self.tcx.opt_parent(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Resolver<'_, 'tcx> {
|
||||
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
||||
self.node_id_to_def_id.get(&node).copied()
|
||||
|
@ -1789,7 +1782,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
vis: ty::Visibility<impl Into<DefId>>,
|
||||
module: Module<'a>,
|
||||
) -> bool {
|
||||
vis.is_accessible_from(module.nearest_parent_mod(), self)
|
||||
vis.is_accessible_from(module.nearest_parent_mod(), self.tcx)
|
||||
}
|
||||
|
||||
fn set_binding_parent_module(&mut self, binding: &'a NameBinding<'a>, module: Module<'a>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue