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:
commit
9fad214593
30 changed files with 109 additions and 147 deletions
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue