Skip to content

Commit 3f553d8

Browse files
committed
Auto merge of rust-lang#145186 - camsteffen:assoc-impl-kind, r=petrochenkov
Make `AssocItem` aware of its impl kind The general goal is to have fewer query dependencies by making `AssocItem` aware of its parent impl kind (inherent vs. trait) without having to query the parent def_kind. See individual commits.
2 parents 2b82ed4 + 0a4d63a commit 3f553d8

File tree

2 files changed

+18
-14
lines changed
  • compiler/rustc_public/src

2 files changed

+18
-14
lines changed

compiler/rustc_public/src/ty.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,11 +1612,7 @@ crate_def! {
16121612
pub struct AssocItem {
16131613
pub def_id: AssocDef,
16141614
pub kind: AssocKind,
1615-
pub container: AssocItemContainer,
1616-
1617-
/// If this is an item in an impl of a trait then this is the `DefId` of
1618-
/// the associated item on the trait that this implements.
1619-
pub trait_item_def_id: Option<AssocDef>,
1615+
pub container: AssocContainer,
16201616
}
16211617

16221618
#[derive(Clone, PartialEq, Debug, Eq, Serialize)]
@@ -1636,9 +1632,11 @@ pub enum AssocKind {
16361632
}
16371633

16381634
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1639-
pub enum AssocItemContainer {
1635+
pub enum AssocContainer {
1636+
InherentImpl,
1637+
/// The `AssocDef` points to the trait item being implemented.
1638+
TraitImpl(AssocDef),
16401639
Trait,
1641-
Impl,
16421640
}
16431641

16441642
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize)]

compiler/rustc_public/src/unstable/convert/stable/ty.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,14 +1076,21 @@ impl<'tcx> Stable<'tcx> for ty::AssocKind {
10761076
}
10771077
}
10781078

1079-
impl<'tcx> Stable<'tcx> for ty::AssocItemContainer {
1080-
type T = crate::ty::AssocItemContainer;
1079+
impl<'tcx> Stable<'tcx> for ty::AssocContainer {
1080+
type T = crate::ty::AssocContainer;
10811081

1082-
fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1083-
use crate::ty::AssocItemContainer;
1082+
fn stable(
1083+
&self,
1084+
tables: &mut Tables<'_, BridgeTys>,
1085+
_: &CompilerCtxt<'_, BridgeTys>,
1086+
) -> Self::T {
1087+
use crate::ty::AssocContainer;
10841088
match self {
1085-
ty::AssocItemContainer::Trait => AssocItemContainer::Trait,
1086-
ty::AssocItemContainer::Impl => AssocItemContainer::Impl,
1089+
ty::AssocContainer::Trait => AssocContainer::Trait,
1090+
ty::AssocContainer::InherentImpl => AssocContainer::InherentImpl,
1091+
ty::AssocContainer::TraitImpl(trait_item_id) => {
1092+
AssocContainer::TraitImpl(tables.assoc_def(trait_item_id.unwrap()))
1093+
}
10871094
}
10881095
}
10891096
}
@@ -1100,7 +1107,6 @@ impl<'tcx> Stable<'tcx> for ty::AssocItem {
11001107
def_id: tables.assoc_def(self.def_id),
11011108
kind: self.kind.stable(tables, cx),
11021109
container: self.container.stable(tables, cx),
1103-
trait_item_def_id: self.trait_item_def_id.map(|did| tables.assoc_def(did)),
11041110
}
11051111
}
11061112
}

0 commit comments

Comments
 (0)