1
Fork 0

Rollup merge of #104674 - spastorino:negative-impl-tcx, r=lcnr

Make negative_impl and negative_impl_exists take the right types

r? `@lcnr`
This commit is contained in:
Matthias Krüger 2022-11-22 00:01:12 +01:00 committed by GitHub
commit 816a31fc66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -162,8 +162,8 @@ fn overlap_within_probe<'cx, 'tcx>(
let infcx = selcx.infcx(); let infcx = selcx.infcx();
if overlap_mode.use_negative_impl() { if overlap_mode.use_negative_impl() {
if negative_impl(selcx, impl1_def_id, impl2_def_id) if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id)
|| negative_impl(selcx, impl2_def_id, impl1_def_id) || negative_impl(infcx.tcx, impl2_def_id, impl1_def_id)
{ {
return None; return None;
} }
@ -279,13 +279,8 @@ fn implicit_negative<'cx, 'tcx>(
/// Given impl1 and impl2 check if both impls are never satisfied by a common type (including /// Given impl1 and impl2 check if both impls are never satisfied by a common type (including
/// where-clauses) If so, return true, they are disjoint and false otherwise. /// where-clauses) If so, return true, they are disjoint and false otherwise.
fn negative_impl<'cx, 'tcx>( fn negative_impl<'tcx>(tcx: TyCtxt<'tcx>, impl1_def_id: DefId, impl2_def_id: DefId) -> bool {
selcx: &mut SelectionContext<'cx, 'tcx>,
impl1_def_id: DefId,
impl2_def_id: DefId,
) -> bool {
debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id); debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id);
let tcx = selcx.infcx().tcx;
// Create an infcx, taking the predicates of impl1 as assumptions: // Create an infcx, taking the predicates of impl1 as assumptions:
let infcx = tcx.infer_ctxt().build(); let infcx = tcx.infer_ctxt().build();
@ -332,11 +327,10 @@ fn equate<'tcx>(
return true; return true;
}; };
let selcx = &mut SelectionContext::new(&infcx);
let opt_failing_obligation = obligations let opt_failing_obligation = obligations
.into_iter() .into_iter()
.chain(more_obligations) .chain(more_obligations)
.find(|o| negative_impl_exists(selcx, o, body_def_id)); .find(|o| negative_impl_exists(infcx, o, body_def_id));
if let Some(failing_obligation) = opt_failing_obligation { if let Some(failing_obligation) = opt_failing_obligation {
debug!("overlap: obligation unsatisfiable {:?}", failing_obligation); debug!("overlap: obligation unsatisfiable {:?}", failing_obligation);
@ -347,19 +341,19 @@ fn equate<'tcx>(
} }
/// Try to prove that a negative impl exist for the given obligation and its super predicates. /// Try to prove that a negative impl exist for the given obligation and its super predicates.
#[instrument(level = "debug", skip(selcx))] #[instrument(level = "debug", skip(infcx))]
fn negative_impl_exists<'cx, 'tcx>( fn negative_impl_exists<'tcx>(
selcx: &SelectionContext<'cx, 'tcx>, infcx: &InferCtxt<'tcx>,
o: &PredicateObligation<'tcx>, o: &PredicateObligation<'tcx>,
body_def_id: DefId, body_def_id: DefId,
) -> bool { ) -> bool {
if resolve_negative_obligation(selcx.infcx().fork(), o, body_def_id) { if resolve_negative_obligation(infcx.fork(), o, body_def_id) {
return true; return true;
} }
// Try to prove a negative obligation exists for super predicates // Try to prove a negative obligation exists for super predicates
for o in util::elaborate_predicates(selcx.tcx(), iter::once(o.predicate)) { for o in util::elaborate_predicates(infcx.tcx, iter::once(o.predicate)) {
if resolve_negative_obligation(selcx.infcx().fork(), &o, body_def_id) { if resolve_negative_obligation(infcx.fork(), &o, body_def_id) {
return true; return true;
} }
} }