diff options
| author | bors <bors@rust-lang.org> | 2024-02-04 18:51:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-04 18:51:28 +0000 |
| commit | 4e3eed48926b8b70eee8beb082e37ffa4985c0ed (patch) | |
| tree | f479799179b27abe3959cf04e202d8f08f96fe90 /compiler/rustc_hir/src | |
| parent | 671eb38a4e5fadb75548841ec7ae31224eea0593 (diff) | |
| parent | 326839bf7f962495b79bdd93dfb886194a5ba13c (diff) | |
| download | rust-4e3eed48926b8b70eee8beb082e37ffa4985c0ed.tar.gz rust-4e3eed48926b8b70eee8beb082e37ffa4985c0ed.zip | |
Auto merge of #120620 - matthiaskrgr:rollup-sscmbsm, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #119543 (add avx512fp16 to x86 target features) - #120004 (Release notes for 1.76) - #120562 (Revert unsound libcore changes) - #120566 (coverage: Use normal `edition:` headers in coverage tests) - #120570 (Suggest changing type to const parameters if we encounter a type in the trait bound position) - #120571 (Miscellaneous diagnostics cleanups) - #120573 (Remove `BorrowckErrors::tainted_by_errors`) - #120592 (Remove unnecessary `.to_string()`/`.as_str()`s) - #120610 (hir: Remove the generic type parameter from `MaybeOwned`) - #120616 (Fix ICE on field access on a tainted type after const-eval failure) Failed merges: - #120569 (coverage: Improve handling of function/closure spans) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_hir/src')
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 681e228a0f2..de1b28acb12 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -894,34 +894,23 @@ impl<'tcx> OwnerInfo<'tcx> { } #[derive(Copy, Clone, Debug, HashStable_Generic)] -pub enum MaybeOwner<T> { - Owner(T), +pub enum MaybeOwner<'tcx> { + Owner(&'tcx OwnerInfo<'tcx>), NonOwner(HirId), /// Used as a placeholder for unused LocalDefId. Phantom, } -impl<T> MaybeOwner<T> { - pub fn as_owner(self) -> Option<T> { +impl<'tcx> MaybeOwner<'tcx> { + pub fn as_owner(self) -> Option<&'tcx OwnerInfo<'tcx>> { match self { MaybeOwner::Owner(i) => Some(i), MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None, } } - pub fn map<U>(self, f: impl FnOnce(T) -> U) -> MaybeOwner<U> { - match self { - MaybeOwner::Owner(i) => MaybeOwner::Owner(f(i)), - MaybeOwner::NonOwner(hir_id) => MaybeOwner::NonOwner(hir_id), - MaybeOwner::Phantom => MaybeOwner::Phantom, - } - } - - pub fn unwrap(self) -> T { - match self { - MaybeOwner::Owner(i) => i, - MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => panic!("Not a HIR owner"), - } + pub fn unwrap(self) -> &'tcx OwnerInfo<'tcx> { + self.as_owner().unwrap_or_else(|| panic!("Not a HIR owner")) } } @@ -933,7 +922,7 @@ impl<T> MaybeOwner<T> { /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html #[derive(Debug)] pub struct Crate<'hir> { - pub owners: IndexVec<LocalDefId, MaybeOwner<&'hir OwnerInfo<'hir>>>, + pub owners: IndexVec<LocalDefId, MaybeOwner<'hir>>, // Only present when incr. comp. is enabled. pub opt_hir_hash: Option<Fingerprint>, } |
