mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
hir: Remove the generic type parameter from MaybeOwned
It's only ever used with a reference to `OwnerInfo` as an argument.
This commit is contained in:
parent
bf3c6c5bed
commit
c5eca333fc
@ -25,7 +25,7 @@ pub(super) struct ItemLowerer<'a, 'hir> {
|
|||||||
pub(super) tcx: TyCtxt<'hir>,
|
pub(super) tcx: TyCtxt<'hir>,
|
||||||
pub(super) resolver: &'a mut ResolverAstLowering,
|
pub(super) resolver: &'a mut ResolverAstLowering,
|
||||||
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
|
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
|
||||||
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
|
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
|
/// 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> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn lower_node(
|
pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> {
|
||||||
&mut self,
|
|
||||||
def_id: LocalDefId,
|
|
||||||
) -> hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>> {
|
|
||||||
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
|
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
|
||||||
if let hir::MaybeOwner::Phantom = owner {
|
if let hir::MaybeOwner::Phantom = owner {
|
||||||
let node = self.ast_index[def_id];
|
let node = self.ast_index[def_id];
|
||||||
|
@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
|
|||||||
/// Attributes inside the owner being lowered.
|
/// Attributes inside the owner being lowered.
|
||||||
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
|
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
|
||||||
/// Collect items that were created by lowering the current owner.
|
/// Collect items that were created by lowering the current owner.
|
||||||
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
|
children: Vec<(LocalDefId, hir::MaybeOwner<'hir>)>,
|
||||||
|
|
||||||
coroutine_kind: Option<hir::CoroutineKind>,
|
coroutine_kind: Option<hir::CoroutineKind>,
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ fn index_crate<'a>(
|
|||||||
/// This hash will then be part of the crate_hash which is stored in the metadata.
|
/// This hash will then be part of the crate_hash which is stored in the metadata.
|
||||||
fn compute_hir_hash(
|
fn compute_hir_hash(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
owners: &IndexSlice<LocalDefId, hir::MaybeOwner<&hir::OwnerInfo<'_>>>,
|
owners: &IndexSlice<LocalDefId, hir::MaybeOwner<'_>>,
|
||||||
) -> Fingerprint {
|
) -> Fingerprint {
|
||||||
let mut hir_body_nodes: Vec<_> = owners
|
let mut hir_body_nodes: Vec<_> = owners
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
|
@ -894,34 +894,23 @@ impl<'tcx> OwnerInfo<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||||
pub enum MaybeOwner<T> {
|
pub enum MaybeOwner<'tcx> {
|
||||||
Owner(T),
|
Owner(&'tcx OwnerInfo<'tcx>),
|
||||||
NonOwner(HirId),
|
NonOwner(HirId),
|
||||||
/// Used as a placeholder for unused LocalDefId.
|
/// Used as a placeholder for unused LocalDefId.
|
||||||
Phantom,
|
Phantom,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> MaybeOwner<T> {
|
impl<'tcx> MaybeOwner<'tcx> {
|
||||||
pub fn as_owner(self) -> Option<T> {
|
pub fn as_owner(self) -> Option<&'tcx OwnerInfo<'tcx>> {
|
||||||
match self {
|
match self {
|
||||||
MaybeOwner::Owner(i) => Some(i),
|
MaybeOwner::Owner(i) => Some(i),
|
||||||
MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None,
|
MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> MaybeOwner<U> {
|
pub fn unwrap(self) -> &'tcx OwnerInfo<'tcx> {
|
||||||
match self {
|
self.as_owner().unwrap_or_else(|| panic!("Not a HIR owner"))
|
||||||
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"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,7 +922,7 @@ impl<T> MaybeOwner<T> {
|
|||||||
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
|
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Crate<'hir> {
|
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.
|
// Only present when incr. comp. is enabled.
|
||||||
pub opt_hir_hash: Option<Fingerprint>,
|
pub opt_hir_hash: Option<Fingerprint>,
|
||||||
}
|
}
|
||||||
|
@ -127,12 +127,11 @@ pub fn provide(providers: &mut Providers) {
|
|||||||
providers.hir_crate_items = map::hir_crate_items;
|
providers.hir_crate_items = map::hir_crate_items;
|
||||||
providers.crate_hash = map::crate_hash;
|
providers.crate_hash = map::crate_hash;
|
||||||
providers.hir_module_items = map::hir_module_items;
|
providers.hir_module_items = map::hir_module_items;
|
||||||
providers.opt_local_def_id_to_hir_id = |tcx, id| {
|
providers.opt_local_def_id_to_hir_id = |tcx, def_id| {
|
||||||
let owner = tcx.hir_crate(()).owners[id].map(|_| ());
|
Some(match tcx.hir_crate(()).owners[def_id] {
|
||||||
Some(match owner {
|
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
|
||||||
MaybeOwner::Owner(_) => HirId::make_owner(id),
|
|
||||||
MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
|
|
||||||
MaybeOwner::NonOwner(hir_id) => hir_id,
|
MaybeOwner::NonOwner(hir_id) => hir_id,
|
||||||
|
MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
providers.opt_hir_owner_nodes =
|
providers.opt_hir_owner_nodes =
|
||||||
|
@ -185,8 +185,8 @@ impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {
|
|||||||
type Result = [u8; size_of::<Option<ty::EarlyBinder<Ty<'static>>>>()];
|
type Result = [u8; size_of::<Option<ty::EarlyBinder<Ty<'static>>>>()];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EraseType for rustc_hir::MaybeOwner<&'_ T> {
|
impl EraseType for rustc_hir::MaybeOwner<'_> {
|
||||||
type Result = [u8; size_of::<rustc_hir::MaybeOwner<&'static ()>>()];
|
type Result = [u8; size_of::<rustc_hir::MaybeOwner<'static>>()];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: EraseType> EraseType for ty::EarlyBinder<T> {
|
impl<T: EraseType> EraseType for ty::EarlyBinder<T> {
|
||||||
|
Loading…
Reference in New Issue
Block a user