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
|
@ -7,7 +7,7 @@
|
|||
use crate::infer::outlives::env::OutlivesEnvironment;
|
||||
use crate::infer::{CombinedSnapshot, InferOk, RegionckMode};
|
||||
use crate::traits::select::IntercrateAmbiguityCause;
|
||||
use crate::traits::util::{impl_trait_ref_and_oblig, inherent_impl_and_oblig};
|
||||
use crate::traits::util::impl_subject_and_oblig;
|
||||
use crate::traits::SkipLeakCheck;
|
||||
use crate::traits::{
|
||||
self, FulfillmentContext, Normalized, Obligation, ObligationCause, PredicateObligation,
|
||||
|
@ -316,38 +316,16 @@ fn negative_impl<'cx, 'tcx>(
|
|||
Err(err) => bug!("failed to fully normalize {:?}: {:?}", impl1_def_id, err),
|
||||
};
|
||||
|
||||
// Attempt to prove that impl2 applies, given all of the above.
|
||||
let selcx = &mut SelectionContext::new(&infcx);
|
||||
let impl2_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl2_def_id);
|
||||
let (subject2, obligations) =
|
||||
impl_subject_and_obligations(&infcx, impl_env, subject1, impl2_def_id);
|
||||
impl_subject_and_oblig(selcx, impl_env, impl2_def_id, impl2_substs);
|
||||
|
||||
!equate(&infcx, impl_env, impl1_def_id, subject1, subject2, obligations)
|
||||
})
|
||||
}
|
||||
|
||||
fn impl_subject_and_obligations<'cx, 'tcx>(
|
||||
infcx: &InferCtxt<'cx, 'tcx>,
|
||||
impl_env: ty::ParamEnv<'tcx>,
|
||||
subject1: ImplSubject<'tcx>,
|
||||
impl2_def_id: DefId,
|
||||
) -> (ImplSubject<'tcx>, Box<dyn Iterator<Item = PredicateObligation<'tcx>> + 'tcx>) {
|
||||
if let ImplSubject::Trait(_) = subject1 {
|
||||
// Attempt to prove that impl2 applies, given all of the above.
|
||||
let selcx = &mut SelectionContext::new(&infcx);
|
||||
let impl2_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl2_def_id);
|
||||
let (impl2_trait_ref, obligations) =
|
||||
impl_trait_ref_and_oblig(selcx, impl_env, impl2_def_id, impl2_substs);
|
||||
|
||||
(ImplSubject::Trait(impl2_trait_ref), Box::new(obligations))
|
||||
} else {
|
||||
// Attempt to prove that impl2 applies, given all of the above.
|
||||
let selcx = &mut SelectionContext::new(&infcx);
|
||||
let impl2_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl2_def_id);
|
||||
let (impl2_ty, obligations) =
|
||||
inherent_impl_and_oblig(selcx, impl_env, impl2_def_id, impl2_substs);
|
||||
|
||||
(ImplSubject::Inherent(impl2_ty), Box::new(obligations))
|
||||
}
|
||||
}
|
||||
|
||||
fn equate<'cx, 'tcx>(
|
||||
infcx: &InferCtxt<'cx, 'tcx>,
|
||||
impl_env: ty::ParamEnv<'tcx>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue