diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-03-13 00:52:25 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-08-01 21:38:45 +0200 |
| commit | d7ea161b7e71f6a76868b1566bad31c1ca52824c (patch) | |
| tree | f54e79e0433cf00d8ef7b48dbec3491f94f4c073 /compiler/rustc_metadata | |
| parent | 8ee4446ee5e1c23bef61b45f74e37db4bad2f424 (diff) | |
| download | rust-d7ea161b7e71f6a76868b1566bad31c1ca52824c.tar.gz rust-d7ea161b7e71f6a76868b1566bad31c1ca52824c.zip | |
Remove DefId from AssocItemContainer.
Diffstat (limited to 'compiler/rustc_metadata')
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/encoder.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/mod.rs | 31 |
3 files changed, 17 insertions, 47 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 40f8da43c66..d8d2ac32c2f 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1114,7 +1114,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn get_fn_has_self_parameter(self, id: DefIndex) -> bool { match self.kind(id) { - EntryKind::AssocFn(data) => data.decode(self).has_self, + EntryKind::AssocFn { has_self, .. } => has_self, _ => false, } } @@ -1134,18 +1134,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn get_associated_item(self, id: DefIndex) -> ty::AssocItem { - let def_key = self.def_key(id); - let parent = self.local_def_id(def_key.parent.unwrap()); let name = self.item_name(id); let (kind, container, has_self) = match self.kind(id) { EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false), - EntryKind::AssocFn(data) => { - let data = data.decode(self); - (ty::AssocKind::Fn, data.container, data.has_self) - } + EntryKind::AssocFn { container, has_self } => (ty::AssocKind::Fn, container, has_self), EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false), - _ => bug!("cannot get associated-item of `{:?}`", def_key), + _ => bug!("cannot get associated-item of `{:?}`", id), }; ty::AssocItem { @@ -1153,7 +1148,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { kind, def_id: self.local_def_id(id), trait_item_def_id: self.get_trait_item_def_id(id), - container: container.with_def_id(parent), + container, fn_has_self_parameter: has_self, } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1fbd6f3795f..33278367ce3 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1222,7 +1222,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { |s| s.print_trait_item(ast_item), ); - record!(self.tables.kind[def_id] <- EntryKind::AssocConst(AssocContainer::Trait)); + record!(self.tables.kind[def_id] <- EntryKind::AssocConst(ty::AssocItemContainer::TraitContainer)); record!(self.tables.mir_const_qualif[def_id] <- mir::ConstQualifs::default()); record!(self.tables.rendered_const[def_id] <- rendered); } @@ -1238,14 +1238,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { }; self.tables.asyncness.set(def_id.index, m_sig.header.asyncness); self.tables.constness.set(def_id.index, hir::Constness::NotConst); - record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData { - container:AssocContainer::Trait, + record!(self.tables.kind[def_id] <- EntryKind::AssocFn { + container: ty::AssocItemContainer::TraitContainer, has_self: trait_item.fn_has_self_parameter, - }))); + }); } ty::AssocKind::Type => { self.encode_explicit_item_bounds(def_id); - record!(self.tables.kind[def_id] <- EntryKind::AssocType(AssocContainer::Trait)); + record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::TraitContainer)); } } match trait_item.kind { @@ -1277,7 +1277,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id); let const_data = self.encode_rendered_const_for_body(body_id); - record!(self.tables.kind[def_id] <- EntryKind::AssocConst(AssocContainer::Impl)); + record!(self.tables.kind[def_id] <- EntryKind::AssocConst(ty::AssocItemContainer::ImplContainer)); record!(self.tables.mir_const_qualif[def_id] <- qualifs); record!(self.tables.rendered_const[def_id] <- const_data); } else { @@ -1295,13 +1295,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { hir::Constness::NotConst }; self.tables.constness.set(def_id.index, constness); - record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData { - container:AssocContainer::Impl, + record!(self.tables.kind[def_id] <- EntryKind::AssocFn { + container: ty::AssocItemContainer::ImplContainer, has_self: impl_item.fn_has_self_parameter, - }))); + }); } ty::AssocKind::Type => { - record!(self.tables.kind[def_id] <- EntryKind::AssocType(AssocContainer::Impl)); + record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::ImplContainer)); } } self.encode_item_type(def_id); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index d93d6323475..66bdecc30db 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -419,9 +419,9 @@ enum EntryKind { Generator, Trait, Impl, - AssocFn(LazyValue<AssocFnData>), - AssocType(AssocContainer), - AssocConst(AssocContainer), + AssocFn { container: ty::AssocItemContainer, has_self: bool }, + AssocType(ty::AssocItemContainer), + AssocConst(ty::AssocItemContainer), TraitAlias, } @@ -434,30 +434,6 @@ struct VariantData { is_non_exhaustive: bool, } -/// Describes whether the container of an associated item -/// is a trait or an impl and whether, in a trait, it has -/// a default, or an in impl, whether it's marked "default". -#[derive(Copy, Clone, TyEncodable, TyDecodable)] -enum AssocContainer { - Trait, - Impl, -} - -impl AssocContainer { - fn with_def_id(&self, def_id: DefId) -> ty::AssocItemContainer { - match *self { - AssocContainer::Trait => ty::TraitContainer(def_id), - AssocContainer::Impl => ty::ImplContainer(def_id), - } - } -} - -#[derive(MetadataEncodable, MetadataDecodable)] -struct AssocFnData { - container: AssocContainer, - has_self: bool, -} - #[derive(TyEncodable, TyDecodable)] struct GeneratorData<'tcx> { layout: mir::GeneratorLayout<'tcx>, @@ -475,7 +451,6 @@ pub fn provide(providers: &mut Providers) { trivially_parameterized_over_tcx! { VariantData, - AssocFnData, EntryKind, RawDefId, TraitImpls, |
