Stop using CRATE_DEF_INDEX.
`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.
This commit is contained in:
parent
878c7833f6
commit
07ee031763
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