Implement param_env for RPITITs assoc type

This commit is contained in:
Santiago Pastorino 2023-03-03 12:38:36 -03:00
parent 290c638b5f
commit bc9ffbeb50
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
3 changed files with 16 additions and 2 deletions

View file

@ -1324,6 +1324,7 @@ rustc_queries! {
/// might want to use `reveal_all()` method to change modes.
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
feedable
}
/// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.

View file

@ -342,6 +342,10 @@ fn impl_associated_item_for_impl_trait_in_trait(
fn_has_self_parameter: false,
});
// Copy param_env of the containing function. The synthesized associated type doesn't have
// extra predicates to assume.
impl_assoc_ty.param_env(tcx.param_env(impl_fn_def_id));
// Copy impl_defaultness of the containing function.
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));

View file

@ -3,8 +3,8 @@ use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_index::bit_set::BitSet;
use rustc_middle::ty::{
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
TypeSuperVisitable, TypeVisitable, TypeVisitor,
self, Binder, EarlyBinder, ImplTraitInTraitData, Predicate, PredicateKind, ToPredicate, Ty,
TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::{DefId, CRATE_DEF_ID};
@ -117,6 +117,15 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
/// See `ParamEnv` struct definition for details.
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
};
// Compute the bounds on Self and the type parameters.
let ty::InstantiatedPredicates { mut predicates, .. } =
tcx.predicates_of(def_id).instantiate_identity(tcx);