1
Fork 0

Auto merge of #95880 - cjgillot:def-ident-span, r=petrochenkov

Handle `def_ident_span` like `def_span`.

`def_ident_span` had an ad-hoc status in the compiler.

This PR refactors it to be a first-class citizen like `def_span`:
- it gets encoded in the main metadata loop, instead of the visitor;
- its implementation is updated to mirror the one of `def_span`.

We do not remove the `Option` in the return type, since some items do not have an ident, AnonConsts for instance.
This commit is contained in:
bors 2022-06-11 20:08:48 +00:00
commit 99930ac7f8
14 changed files with 229 additions and 151 deletions

View file

@ -5,7 +5,6 @@ use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
};
use rustc_span::Span;
use rustc_trait_selection::traits;
fn sized_constraint_for_ty<'tcx>(
@ -103,21 +102,6 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtSizedConstrain
ty::AdtSizedConstraint(result)
}
fn def_ident_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Span> {
tcx.hir()
.get_if_local(def_id)
.and_then(|node| match node {
// A `Ctor` doesn't have an identifier itself, but its parent
// struct/variant does. Compare with `hir::Map::opt_span`.
hir::Node::Ctor(ctor) => ctor
.ctor_hir_id()
.and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id)))
.and_then(|parent| parent.ident()),
_ => node.ident(),
})
.map(|ident| ident.span)
}
/// See `ParamEnv` struct definition for details.
#[instrument(level = "debug", skip(tcx))]
fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
@ -480,7 +464,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers {
asyncness,
adt_sized_constraint,
def_ident_span,
param_env,
param_env_reveal_all_normalized,
instance_def_size_estimate,