diff options
| author | bors <bors@rust-lang.org> | 2022-04-19 13:10:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-19 13:10:12 +0000 |
| commit | 4ca19e09d302a4cbde14f9cb1bc109179dc824cd (patch) | |
| tree | b779b25871b429dfaafe1c4de5cc5051333c3689 /compiler/rustc_span/src | |
| parent | c102c5cfc60203c82460bdde2eecd19ccd8c125b (diff) | |
| parent | 9fad214593e87f151b8f09ff0cda9cd52372d037 (diff) | |
| download | rust-4ca19e09d302a4cbde14f9cb1bc109179dc824cd.tar.gz rust-4ca19e09d302a4cbde14f9cb1bc109179dc824cd.zip | |
Auto merge of #96214 - Dylan-DPC:rollup-a5b4fow, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #94493 (Improved diagnostic on failure to meet send bound on future in a foreign crate) - #95809 (Fix typo in bootstrap.py) - #96086 (Remove `--extern-location` and all associated code) - #96089 (`alloc`: make `vec!` unavailable under `no_global_oom_handling`) - #96122 (Fix an invalid error for a suggestion to add a slice in pattern-matching) - #96142 (Stop using CRATE_DEF_INDEX outside of metadata encoding.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/def_id.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 6d1b36796d8..d5f806308cf 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -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 } } |
