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
|
@ -283,8 +283,19 @@ impl DefId {
|
|||
self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_crate_root(self) -> bool {
|
||||
self.index == CRATE_DEF_INDEX
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_crate_root(self) -> Option<CrateNum> {
|
||||
if self.is_crate_root() { Some(self.krate) } else { None }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_top_level_module(self) -> bool {
|
||||
self.is_local() && self.index == CRATE_DEF_INDEX
|
||||
self.is_local() && self.is_crate_root()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,7 +368,7 @@ impl LocalDefId {
|
|||
|
||||
#[inline]
|
||||
pub fn is_top_level_module(self) -> bool {
|
||||
self.local_def_index == CRATE_DEF_INDEX
|
||||
self == CRATE_DEF_ID
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue