Skip to content

Commit 2a8fc94

Browse files
authoredFeb 3, 2024
Rollup merge of rust-lang#120610 - petrochenkov:maybeownogen, r=cjgillot
hir: Remove the generic type parameter from `MaybeOwned` It's only ever used with a reference to `OwnerInfo` as an argument. Follow up to rust-lang#120346.
2 parents 968cff7 + c5eca33 commit 2a8fc94

File tree

5 files changed

+17
-32
lines changed

5 files changed

+17
-32
lines changed
 

‎compiler/rustc_ast_lowering/src/item.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(super) struct ItemLowerer<'a, 'hir> {
2525
pub(super) tcx: TyCtxt<'hir>,
2626
pub(super) resolver: &'a mut ResolverAstLowering,
2727
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
28-
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
28+
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
2929
}
3030

3131
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
@@ -64,10 +64,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6464
}
6565
}
6666

67-
pub(super) fn lower_node(
68-
&mut self,
69-
def_id: LocalDefId,
70-
) -> hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>> {
67+
pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> {
7168
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
7269
if let hir::MaybeOwner::Phantom = owner {
7370
let node = self.ast_index[def_id];

‎compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
9999
/// Attributes inside the owner being lowered.
100100
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
101101
/// Collect items that were created by lowering the current owner.
102-
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
102+
children: Vec<(LocalDefId, hir::MaybeOwner<'hir>)>,
103103

104104
coroutine_kind: Option<hir::CoroutineKind>,
105105

@@ -415,7 +415,7 @@ fn index_crate<'a>(
415415
/// This hash will then be part of the crate_hash which is stored in the metadata.
416416
fn compute_hir_hash(
417417
tcx: TyCtxt<'_>,
418-
owners: &IndexSlice<LocalDefId, hir::MaybeOwner<&hir::OwnerInfo<'_>>>,
418+
owners: &IndexSlice<LocalDefId, hir::MaybeOwner<'_>>,
419419
) -> Fingerprint {
420420
let mut hir_body_nodes: Vec<_> = owners
421421
.iter_enumerated()

‎compiler/rustc_hir/src/hir.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -894,34 +894,23 @@ impl<'tcx> OwnerInfo<'tcx> {
894894
}
895895

896896
#[derive(Copy, Clone, Debug, HashStable_Generic)]
897-
pub enum MaybeOwner<T> {
898-
Owner(T),
897+
pub enum MaybeOwner<'tcx> {
898+
Owner(&'tcx OwnerInfo<'tcx>),
899899
NonOwner(HirId),
900900
/// Used as a placeholder for unused LocalDefId.
901901
Phantom,
902902
}
903903

904-
impl<T> MaybeOwner<T> {
905-
pub fn as_owner(self) -> Option<T> {
904+
impl<'tcx> MaybeOwner<'tcx> {
905+
pub fn as_owner(self) -> Option<&'tcx OwnerInfo<'tcx>> {
906906
match self {
907907
MaybeOwner::Owner(i) => Some(i),
908908
MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None,
909909
}
910910
}
911911

912-
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> MaybeOwner<U> {
913-
match self {
914-
MaybeOwner::Owner(i) => MaybeOwner::Owner(f(i)),
915-
MaybeOwner::NonOwner(hir_id) => MaybeOwner::NonOwner(hir_id),
916-
MaybeOwner::Phantom => MaybeOwner::Phantom,
917-
}
918-
}
919-
920-
pub fn unwrap(self) -> T {
921-
match self {
922-
MaybeOwner::Owner(i) => i,
923-
MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => panic!("Not a HIR owner"),
924-
}
912+
pub fn unwrap(self) -> &'tcx OwnerInfo<'tcx> {
913+
self.as_owner().unwrap_or_else(|| panic!("Not a HIR owner"))
925914
}
926915
}
927916

@@ -933,7 +922,7 @@ impl<T> MaybeOwner<T> {
933922
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
934923
#[derive(Debug)]
935924
pub struct Crate<'hir> {
936-
pub owners: IndexVec<LocalDefId, MaybeOwner<&'hir OwnerInfo<'hir>>>,
925+
pub owners: IndexVec<LocalDefId, MaybeOwner<'hir>>,
937926
// Only present when incr. comp. is enabled.
938927
pub opt_hir_hash: Option<Fingerprint>,
939928
}

‎compiler/rustc_middle/src/hir/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,11 @@ pub fn provide(providers: &mut Providers) {
127127
providers.hir_crate_items = map::hir_crate_items;
128128
providers.crate_hash = map::crate_hash;
129129
providers.hir_module_items = map::hir_module_items;
130-
providers.opt_local_def_id_to_hir_id = |tcx, id| {
131-
let owner = tcx.hir_crate(()).owners[id].map(|_| ());
132-
Some(match owner {
133-
MaybeOwner::Owner(_) => HirId::make_owner(id),
134-
MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
130+
providers.opt_local_def_id_to_hir_id = |tcx, def_id| {
131+
Some(match tcx.hir_crate(()).owners[def_id] {
132+
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
135133
MaybeOwner::NonOwner(hir_id) => hir_id,
134+
MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
136135
})
137136
};
138137
providers.opt_hir_owner_nodes =

‎compiler/rustc_middle/src/query/erase.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {
185185
type Result = [u8; size_of::<Option<ty::EarlyBinder<Ty<'static>>>>()];
186186
}
187187

188-
impl<T> EraseType for rustc_hir::MaybeOwner<&'_ T> {
189-
type Result = [u8; size_of::<rustc_hir::MaybeOwner<&'static ()>>()];
188+
impl EraseType for rustc_hir::MaybeOwner<'_> {
189+
type Result = [u8; size_of::<rustc_hir::MaybeOwner<'static>>()];
190190
}
191191

192192
impl<T: EraseType> EraseType for ty::EarlyBinder<T> {

0 commit comments

Comments
 (0)