1
Fork 0

Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov

Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.
This commit is contained in:
Dylan DPC 2022-04-19 14:43:21 +02:00 committed by GitHub
commit 9fad214593
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 109 additions and 147 deletions

View file

@ -1,4 +1,4 @@
use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::def_id::DefId;
use crate::hir;
use rustc_ast as ast;
@ -124,9 +124,7 @@ impl DefKind {
pub fn descr(self, def_id: DefId) -> &'static str {
match self {
DefKind::Fn => "function",
DefKind::Mod if def_id.index == CRATE_DEF_INDEX && def_id.krate != LOCAL_CRATE => {
"crate"
}
DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
DefKind::Mod => "module",
DefKind::Static(..) => "static",
DefKind::Enum => "enum",

View file

@ -353,11 +353,6 @@ impl Definitions {
}
}
/// Retrieves the root definition.
pub fn get_root_def(&self) -> LocalDefId {
LocalDefId { local_def_index: CRATE_DEF_INDEX }
}
/// Adds a definition with a parent definition.
pub fn create_def(
&mut self,

View file

@ -1,4 +1,4 @@
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
use crate::def_id::{LocalDefId, CRATE_DEF_ID};
use std::fmt;
/// Uniquely identifies a node in the HIR of the current crate. It is
@ -84,8 +84,5 @@ impl ItemLocalId {
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
}
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
pub const CRATE_HIR_ID: HirId = HirId {
owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
local_id: ItemLocalId::from_u32(0),
};
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
pub const CRATE_HIR_ID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::from_u32(0) };