Auto merge of #107206 - cjgillot:no-h2l-map, r=WaffleLapkin
Remove HirId -> LocalDefId map from HIR. Having this map in HIR prevents the creating of new definitions after HIR has been built. Thankfully, we do not need it. Based on https://github.com/rust-lang/rust/pull/103902
This commit is contained in:
commit
d6f0642827
91 changed files with 557 additions and 592 deletions
|
@ -56,9 +56,7 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
||||
use rustc_hir::intravisit::FnKind as HirFnKind;
|
||||
use rustc_hir::{
|
||||
Body, FnDecl, ForeignItemKind, GenericParamKind, HirId, Node, PatKind, PredicateOrigin,
|
||||
};
|
||||
use rustc_hir::{Body, FnDecl, ForeignItemKind, GenericParamKind, Node, PatKind, PredicateOrigin};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
||||
|
@ -583,12 +581,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
|
||||
// If the method is an impl for a trait, don't doc.
|
||||
if method_context(cx, impl_item.hir_id()) == MethodLateContext::TraitImpl {
|
||||
let context = method_context(cx, impl_item.owner_id.def_id);
|
||||
if context == MethodLateContext::TraitImpl {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the method is an impl for an item with docs_hidden, don't doc.
|
||||
if method_context(cx, impl_item.hir_id()) == MethodLateContext::PlainImpl {
|
||||
if context == MethodLateContext::PlainImpl {
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
|
||||
let impl_ty = cx.tcx.type_of(parent);
|
||||
let outerdef = match impl_ty.kind() {
|
||||
|
@ -1296,19 +1295,18 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
|
|||
_: &'tcx FnDecl<'_>,
|
||||
_: &'tcx Body<'_>,
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
def_id: LocalDefId,
|
||||
) {
|
||||
if fn_kind.asyncness() == IsAsync::Async
|
||||
&& !cx.tcx.features().closure_track_caller
|
||||
&& let attrs = cx.tcx.hir().attrs(hir_id)
|
||||
// Now, check if the function has the `#[track_caller]` attribute
|
||||
&& let Some(attr) = attrs.iter().find(|attr| attr.has_name(sym::track_caller))
|
||||
{
|
||||
cx.emit_spanned_lint(UNGATED_ASYNC_FN_TRACK_CALLER, attr.span, BuiltinUngatedAsyncFnTrackCaller {
|
||||
label: span,
|
||||
parse_sess: &cx.tcx.sess.parse_sess,
|
||||
});
|
||||
}
|
||||
&& let Some(attr) = cx.tcx.get_attr(def_id.to_def_id(), sym::track_caller)
|
||||
{
|
||||
cx.emit_spanned_lint(UNGATED_ASYNC_FN_TRACK_CALLER, attr.span, BuiltinUngatedAsyncFnTrackCaller {
|
||||
label: span,
|
||||
parse_sess: &cx.tcx.sess.parse_sess,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2684,7 +2682,7 @@ pub struct ClashingExternDeclarations {
|
|||
/// the symbol should be reported as a clashing declaration.
|
||||
// FIXME: Technically, we could just store a &'tcx str here without issue; however, the
|
||||
// `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
|
||||
seen_decls: FxHashMap<Symbol, HirId>,
|
||||
seen_decls: FxHashMap<Symbol, hir::OwnerId>,
|
||||
}
|
||||
|
||||
/// Differentiate between whether the name for an extern decl came from the link_name attribute or
|
||||
|
@ -2710,19 +2708,20 @@ impl ClashingExternDeclarations {
|
|||
pub(crate) fn new() -> Self {
|
||||
ClashingExternDeclarations { seen_decls: FxHashMap::default() }
|
||||
}
|
||||
|
||||
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists
|
||||
/// for the item, return its HirId without updating the set.
|
||||
fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId> {
|
||||
fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<hir::OwnerId> {
|
||||
let did = fi.owner_id.to_def_id();
|
||||
let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
|
||||
let name = Symbol::intern(tcx.symbol_name(instance).name);
|
||||
if let Some(&hir_id) = self.seen_decls.get(&name) {
|
||||
if let Some(&existing_id) = self.seen_decls.get(&name) {
|
||||
// Avoid updating the map with the new entry when we do find a collision. We want to
|
||||
// make sure we're always pointing to the first definition as the previous declaration.
|
||||
// This lets us avoid emitting "knock-on" diagnostics.
|
||||
Some(hir_id)
|
||||
Some(existing_id)
|
||||
} else {
|
||||
self.seen_decls.insert(name, fi.hir_id())
|
||||
self.seen_decls.insert(name, fi.owner_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2949,16 +2948,16 @@ impl ClashingExternDeclarations {
|
|||
impl_lint_pass!(ClashingExternDeclarations => [CLASHING_EXTERN_DECLARATIONS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
|
||||
#[instrument(level = "trace", skip(self, cx))]
|
||||
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
|
||||
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
|
||||
if let ForeignItemKind::Fn(..) = this_fi.kind {
|
||||
let tcx = cx.tcx;
|
||||
if let Some(existing_hid) = self.insert(tcx, this_fi) {
|
||||
let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid));
|
||||
if let Some(existing_did) = self.insert(tcx, this_fi) {
|
||||
let existing_decl_ty = tcx.type_of(existing_did);
|
||||
let this_decl_ty = tcx.type_of(this_fi.owner_id);
|
||||
debug!(
|
||||
"ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}",
|
||||
existing_hid, existing_decl_ty, this_fi.owner_id, this_decl_ty
|
||||
existing_did, existing_decl_ty, this_fi.owner_id, this_decl_ty
|
||||
);
|
||||
// Check that the declarations match.
|
||||
if !Self::structurally_same_type(
|
||||
|
@ -2967,7 +2966,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
|
|||
this_decl_ty,
|
||||
CItemKind::Declaration,
|
||||
) {
|
||||
let orig_fi = tcx.hir().expect_foreign_item(existing_hid.expect_owner());
|
||||
let orig_fi = tcx.hir().expect_foreign_item(existing_did);
|
||||
let orig = Self::name_of_extern_decl(tcx, orig_fi);
|
||||
|
||||
// We want to ensure that we use spans for both decls that include where the
|
||||
|
|
|
@ -66,13 +66,12 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
|||
self.context.last_node_with_lint_attrs = prev;
|
||||
}
|
||||
|
||||
fn with_param_env<F>(&mut self, id: hir::HirId, f: F)
|
||||
fn with_param_env<F>(&mut self, id: hir::OwnerId, f: F)
|
||||
where
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
let old_param_env = self.context.param_env;
|
||||
self.context.param_env =
|
||||
self.context.tcx.param_env(self.context.tcx.hir().local_def_id(id));
|
||||
self.context.param_env = self.context.tcx.param_env(id);
|
||||
f(self);
|
||||
self.context.param_env = old_param_env;
|
||||
}
|
||||
|
@ -132,7 +131,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
let old_cached_typeck_results = self.context.cached_typeck_results.take();
|
||||
let old_enclosing_body = self.context.enclosing_body.take();
|
||||
self.with_lint_attrs(it.hir_id(), |cx| {
|
||||
cx.with_param_env(it.hir_id(), |cx| {
|
||||
cx.with_param_env(it.owner_id, |cx| {
|
||||
lint_callback!(cx, check_item, it);
|
||||
hir_visit::walk_item(cx, it);
|
||||
lint_callback!(cx, check_item_post, it);
|
||||
|
@ -145,7 +144,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
|
||||
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
|
||||
self.with_lint_attrs(it.hir_id(), |cx| {
|
||||
cx.with_param_env(it.hir_id(), |cx| {
|
||||
cx.with_param_env(it.owner_id, |cx| {
|
||||
lint_callback!(cx, check_foreign_item, it);
|
||||
hir_visit::walk_foreign_item(cx, it);
|
||||
});
|
||||
|
@ -180,7 +179,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
body_id: hir::BodyId,
|
||||
span: Span,
|
||||
id: hir::HirId,
|
||||
id: LocalDefId,
|
||||
) {
|
||||
// Wrap in typeck results here, not just in visit_nested_body,
|
||||
// in order for `check_fn` to be able to use them.
|
||||
|
@ -268,7 +267,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&trait_item.generics);
|
||||
self.with_lint_attrs(trait_item.hir_id(), |cx| {
|
||||
cx.with_param_env(trait_item.hir_id(), |cx| {
|
||||
cx.with_param_env(trait_item.owner_id, |cx| {
|
||||
lint_callback!(cx, check_trait_item, trait_item);
|
||||
hir_visit::walk_trait_item(cx, trait_item);
|
||||
});
|
||||
|
@ -280,7 +279,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&impl_item.generics);
|
||||
self.with_lint_attrs(impl_item.hir_id(), |cx| {
|
||||
cx.with_param_env(impl_item.hir_id(), |cx| {
|
||||
cx.with_param_env(impl_item.owner_id, |cx| {
|
||||
lint_callback!(cx, check_impl_item, impl_item);
|
||||
hir_visit::walk_impl_item(cx, impl_item);
|
||||
lint_callback!(cx, check_impl_item_post, impl_item);
|
||||
|
|
|
@ -10,8 +10,9 @@ use rustc_hir::def::{DefKind, Res};
|
|||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{GenericParamKind, PatKind};
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{symbol::Ident, BytePos, Span};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::{BytePos, Span};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
@ -21,9 +22,8 @@ pub enum MethodLateContext {
|
|||
PlainImpl,
|
||||
}
|
||||
|
||||
pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext {
|
||||
let def_id = cx.tcx.hir().local_def_id(id);
|
||||
let item = cx.tcx.associated_item(def_id);
|
||||
pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext {
|
||||
let item = cx.tcx.associated_item(id);
|
||||
match item.container {
|
||||
ty::TraitContainer => MethodLateContext::TraitAutoImpl,
|
||||
ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
|
||||
|
@ -379,13 +379,13 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
|||
_: &hir::FnDecl<'_>,
|
||||
_: &hir::Body<'_>,
|
||||
_: Span,
|
||||
id: hir::HirId,
|
||||
id: LocalDefId,
|
||||
) {
|
||||
let attrs = cx.tcx.hir().attrs(id);
|
||||
match &fk {
|
||||
FnKind::Method(ident, sig, ..) => match method_context(cx, id) {
|
||||
MethodLateContext::PlainImpl => {
|
||||
if sig.header.abi != Abi::Rust && cx.sess().contains_name(attrs, sym::no_mangle)
|
||||
if sig.header.abi != Abi::Rust
|
||||
&& cx.tcx.has_attr(id.to_def_id(), sym::no_mangle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
|||
},
|
||||
FnKind::ItemFn(ident, _, header) => {
|
||||
// Skip foreign-ABI #[no_mangle] functions (Issue #31924)
|
||||
if header.abi != Abi::Rust && cx.sess().contains_name(attrs, sym::no_mangle) {
|
||||
if header.abi != Abi::Rust && cx.tcx.has_attr(id.to_def_id(), sym::no_mangle) {
|
||||
return;
|
||||
}
|
||||
self.check_snake_case(cx, "function", ident);
|
||||
|
|
|
@ -4,6 +4,7 @@ use rustc_ast as ast;
|
|||
use rustc_hir as hir;
|
||||
use rustc_session::lint::builtin::HardwiredLints;
|
||||
use rustc_session::lint::LintPass;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -36,7 +37,7 @@ macro_rules! late_lint_methods {
|
|||
b: &'tcx hir::FnDecl<'tcx>,
|
||||
c: &'tcx hir::Body<'tcx>,
|
||||
d: Span,
|
||||
e: hir::HirId);
|
||||
e: LocalDefId);
|
||||
fn check_trait_item(a: &'tcx hir::TraitItem<'tcx>);
|
||||
fn check_impl_item(a: &'tcx hir::ImplItem<'tcx>);
|
||||
fn check_impl_item_post(a: &'tcx hir::ImplItem<'tcx>);
|
||||
|
|
|
@ -14,6 +14,7 @@ use rustc_hir::{is_range_literal, Expr, ExprKind, Node};
|
|||
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::source_map;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
@ -1224,8 +1225,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl<'_>) {
|
||||
let def_id = self.cx.tcx.hir().local_def_id(id);
|
||||
fn check_foreign_fn(&mut self, def_id: LocalDefId, decl: &hir::FnDecl<'_>) {
|
||||
let sig = self.cx.tcx.fn_sig(def_id).subst_identity();
|
||||
let sig = self.cx.tcx.erase_late_bound_regions(sig);
|
||||
|
||||
|
@ -1239,9 +1239,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_foreign_static(&mut self, id: hir::HirId, span: Span) {
|
||||
let def_id = self.cx.tcx.hir().local_def_id(id);
|
||||
let ty = self.cx.tcx.type_of(def_id);
|
||||
fn check_foreign_static(&mut self, id: hir::OwnerId, span: Span) {
|
||||
let ty = self.cx.tcx.type_of(id);
|
||||
self.check_type_for_ffi_and_report_errors(span, ty, true, false);
|
||||
}
|
||||
|
||||
|
@ -1261,10 +1260,10 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
|
|||
if !vis.is_internal_abi(abi) {
|
||||
match it.kind {
|
||||
hir::ForeignItemKind::Fn(ref decl, _, _) => {
|
||||
vis.check_foreign_fn(it.hir_id(), decl);
|
||||
vis.check_foreign_fn(it.owner_id.def_id, decl);
|
||||
}
|
||||
hir::ForeignItemKind::Static(ref ty, _) => {
|
||||
vis.check_foreign_static(it.hir_id(), ty.span);
|
||||
vis.check_foreign_static(it.owner_id, ty.span);
|
||||
}
|
||||
hir::ForeignItemKind::Type => (),
|
||||
}
|
||||
|
@ -1280,7 +1279,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
|
|||
decl: &'tcx hir::FnDecl<'_>,
|
||||
_: &'tcx hir::Body<'_>,
|
||||
_: Span,
|
||||
hir_id: hir::HirId,
|
||||
id: LocalDefId,
|
||||
) {
|
||||
use hir::intravisit::FnKind;
|
||||
|
||||
|
@ -1292,7 +1291,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
|
|||
|
||||
let mut vis = ImproperCTypesVisitor { cx, mode: CItemKind::Definition };
|
||||
if !vis.is_internal_abi(abi) {
|
||||
vis.check_foreign_fn(hir_id, decl);
|
||||
vis.check_foreign_fn(id, decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue