1
Fork 0

RPITITs inherit method predicates

This commit is contained in:
Michael Goulet 2023-06-30 19:09:42 +00:00
parent 982f025cad
commit a14285ca7e
4 changed files with 19 additions and 26 deletions

View file

@ -4,8 +4,7 @@ use rustc_hir::def::DefKind;
use rustc_index::bit_set::BitSet;
use rustc_middle::query::Providers;
use rustc_middle::ty::{
self, EarlyBinder, ImplTraitInTraitData, ToPredicate, Ty, TyCtxt, TypeSuperVisitable,
TypeVisitable, TypeVisitor,
self, EarlyBinder, ToPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
@ -120,22 +119,6 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
let ty::InstantiatedPredicates { mut predicates, .. } =
tcx.predicates_of(def_id).instantiate_identity(tcx);
// When computing the param_env of an RPITIT, use predicates of the containing function,
// *except* for the additional assumption that the RPITIT normalizes to the trait method's
// default opaque type. This is needed to properly check the item bounds of the assoc
// type hold (`check_type_bounds`), since that method already installs a similar projection
// bound, so they will conflict.
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): I don't like this, we should
// at least be making sure that the generics in RPITITs and their parent fn don't
// get out of alignment, or else we do actually need to substitute these predicates.
if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. })
| Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id)
{
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): Should not need to add the predicates
// from the parent fn to our assumptions
predicates.extend(tcx.predicates_of(fn_def_id).instantiate_identity(tcx).predicates);
}
// Finally, we have to normalize the bounds in the environment, in
// case they contain any associated type projections. This process
// can yield errors if the put in illegal associated types, like