Implement impl_subject_and_oblig instead of repeating the impls
This commit is contained in:
parent
d96faef913
commit
42e986f77b
3 changed files with 26 additions and 74 deletions
|
@ -6,7 +6,7 @@ use smallvec::SmallVec;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeFoldable};
|
||||
|
||||
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
|
||||
pub use rustc_infer::traits::{self, util::*};
|
||||
|
@ -190,19 +190,19 @@ impl Iterator for SupertraitDefIds<'_> {
|
|||
// Other
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Instantiate all bound parameters of the impl with the given substs,
|
||||
/// returning the resulting trait ref and all obligations that arise.
|
||||
/// Instantiate all bound parameters of the impl subject with the given substs,
|
||||
/// returning the resulting subject and all obligations that arise.
|
||||
/// The obligations are closed under normalization.
|
||||
pub fn impl_trait_ref_and_oblig<'a, 'tcx>(
|
||||
pub fn impl_subject_and_oblig<'a, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_substs: SubstsRef<'tcx>,
|
||||
) -> (ty::TraitRef<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
|
||||
let impl_trait_ref = selcx.tcx().impl_trait_ref(impl_def_id).unwrap();
|
||||
let impl_trait_ref = impl_trait_ref.subst(selcx.tcx(), impl_substs);
|
||||
let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } =
|
||||
super::normalize(selcx, param_env, ObligationCause::dummy(), impl_trait_ref);
|
||||
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
|
||||
let subject = selcx.tcx().impl_subject(impl_def_id);
|
||||
let subject = subject.subst(selcx.tcx(), impl_substs);
|
||||
let Normalized { value: subject, obligations: normalization_obligations1 } =
|
||||
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
|
||||
|
||||
let predicates = selcx.tcx().predicates_of(impl_def_id);
|
||||
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
|
||||
|
@ -215,35 +215,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'tcx>(
|
|||
.chain(normalization_obligations1.into_iter())
|
||||
.chain(normalization_obligations2.into_iter());
|
||||
|
||||
(impl_trait_ref, impl_obligations)
|
||||
}
|
||||
|
||||
/// Instantiate all bound parameters of the impl with the given substs,
|
||||
/// returning the resulting trait ref and all obligations that arise.
|
||||
/// The obligations are closed under normalization.
|
||||
pub fn inherent_impl_and_oblig<'a, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_substs: SubstsRef<'tcx>,
|
||||
) -> (Ty<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
|
||||
let ty = selcx.tcx().type_of(impl_def_id);
|
||||
let ty = ty.subst(selcx.tcx(), impl_substs);
|
||||
let Normalized { value: ty, obligations: normalization_obligations1 } =
|
||||
super::normalize(selcx, param_env, ObligationCause::dummy(), ty);
|
||||
|
||||
let predicates = selcx.tcx().predicates_of(impl_def_id);
|
||||
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
|
||||
let Normalized { value: predicates, obligations: normalization_obligations2 } =
|
||||
super::normalize(selcx, param_env, ObligationCause::dummy(), predicates);
|
||||
let impl_obligations =
|
||||
predicates_for_generics(ObligationCause::dummy(), 0, param_env, predicates);
|
||||
|
||||
let impl_obligations = impl_obligations
|
||||
.chain(normalization_obligations1.into_iter())
|
||||
.chain(normalization_obligations2.into_iter());
|
||||
|
||||
(ty, impl_obligations)
|
||||
(subject, impl_obligations)
|
||||
}
|
||||
|
||||
pub fn predicates_for_generics<'tcx>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue