From 0404e264a23af0f0a3485713843c6525d0e949c8 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 13 Mar 2023 17:22:16 +0000 Subject: [PATCH] Encode opt_rpitit_info for associated types --- compiler/rustc_metadata/src/rmeta/decoder.rs | 5 +++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 8 ++++++++ compiler/rustc_metadata/src/rmeta/mod.rs | 1 + compiler/rustc_middle/src/ty/parameterized.rs | 1 + compiler/rustc_ty_utils/src/ty.rs | 9 +++------ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index ca26e1497aaf7..0070e46ffdf02 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1087,6 +1087,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { _ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)), }; let container = self.root.tables.assoc_container.get(self, id).unwrap(); + let opt_rpitit_info = + self.root.tables.opt_rpitit_info.get(self, id).map(|d| d.decode(self)); ty::AssocItem { name, @@ -1095,8 +1097,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { trait_item_def_id: self.get_trait_item_def_id(id), container, fn_has_self_parameter: has_self, - // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): We need to encode this - opt_rpitit_info: None, + opt_rpitit_info, } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index bbab8a62a2bce..37b0bfacb8b87 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1350,6 +1350,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { if trait_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } + if let Some(rpitit_info) = trait_item.opt_rpitit_info { + let rpitit_info = self.lazy(rpitit_info); + self.tables.opt_rpitit_info.set_some(def_id.index, rpitit_info); + } } fn encode_info_for_impl_item(&mut self, def_id: DefId) { @@ -1383,6 +1387,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id)); } + if let Some(rpitit_info) = impl_item.opt_rpitit_info { + let rpitit_info = self.lazy(rpitit_info); + self.tables.opt_rpitit_info.set_some(def_id.index, rpitit_info); + } } fn encode_mir(&mut self) { diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 1d2541a678819..e71a1c9810249 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -355,6 +355,7 @@ define_tables! { inferred_outlives_of: Table, Span)>>, inherent_impls: Table>, associated_items_for_impl_trait_in_trait: Table>, + opt_rpitit_info: Table>>, - optional: attributes: Table>, diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs index 8849e7eab335c..7534d06ae91f1 100644 --- a/compiler/rustc_middle/src/ty/parameterized.rs +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -63,6 +63,7 @@ trivially_parameterized_over_tcx! { ty::DeducedParamAttrs, ty::Generics, ty::ImplPolarity, + ty::ImplTraitInTraitData, ty::ReprOptions, ty::TraitDef, ty::UnusedGenericParams, diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index c8ed1f365f1a8..d41bf603983c0 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -119,12 +119,9 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] { fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { // When computing the param_env of an RPITIT, copy param_env of the containing function. The // synthesized associated type doesn't have extra predicates to assume. - let def_id = - if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) { - fn_def_id - } else { - def_id - }; + if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) { + return tcx.param_env(fn_def_id); + } // Compute the bounds on Self and the type parameters. let ty::InstantiatedPredicates { mut predicates, .. } =