Skip to content

Commit 816a31f

Browse files
authored
Rollup merge of #104674 - spastorino:negative-impl-tcx, r=lcnr
Make negative_impl and negative_impl_exists take the right types r? `@lcnr`
2 parents 96d0b7f + 16c9e39 commit 816a31f

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ fn overlap_within_probe<'cx, 'tcx>(
162162
let infcx = selcx.infcx();
163163

164164
if overlap_mode.use_negative_impl() {
165-
if negative_impl(selcx, impl1_def_id, impl2_def_id)
166-
|| negative_impl(selcx, impl2_def_id, impl1_def_id)
165+
if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id)
166+
|| negative_impl(infcx.tcx, impl2_def_id, impl1_def_id)
167167
{
168168
return None;
169169
}
@@ -279,13 +279,8 @@ fn implicit_negative<'cx, 'tcx>(
279279

280280
/// Given impl1 and impl2 check if both impls are never satisfied by a common type (including
281281
/// where-clauses) If so, return true, they are disjoint and false otherwise.
282-
fn negative_impl<'cx, 'tcx>(
283-
selcx: &mut SelectionContext<'cx, 'tcx>,
284-
impl1_def_id: DefId,
285-
impl2_def_id: DefId,
286-
) -> bool {
282+
fn negative_impl<'tcx>(tcx: TyCtxt<'tcx>, impl1_def_id: DefId, impl2_def_id: DefId) -> bool {
287283
debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id);
288-
let tcx = selcx.infcx().tcx;
289284

290285
// Create an infcx, taking the predicates of impl1 as assumptions:
291286
let infcx = tcx.infer_ctxt().build();
@@ -332,11 +327,10 @@ fn equate<'tcx>(
332327
return true;
333328
};
334329

335-
let selcx = &mut SelectionContext::new(&infcx);
336330
let opt_failing_obligation = obligations
337331
.into_iter()
338332
.chain(more_obligations)
339-
.find(|o| negative_impl_exists(selcx, o, body_def_id));
333+
.find(|o| negative_impl_exists(infcx, o, body_def_id));
340334

341335
if let Some(failing_obligation) = opt_failing_obligation {
342336
debug!("overlap: obligation unsatisfiable {:?}", failing_obligation);
@@ -347,19 +341,19 @@ fn equate<'tcx>(
347341
}
348342

349343
/// Try to prove that a negative impl exist for the given obligation and its super predicates.
350-
#[instrument(level = "debug", skip(selcx))]
351-
fn negative_impl_exists<'cx, 'tcx>(
352-
selcx: &SelectionContext<'cx, 'tcx>,
344+
#[instrument(level = "debug", skip(infcx))]
345+
fn negative_impl_exists<'tcx>(
346+
infcx: &InferCtxt<'tcx>,
353347
o: &PredicateObligation<'tcx>,
354348
body_def_id: DefId,
355349
) -> bool {
356-
if resolve_negative_obligation(selcx.infcx().fork(), o, body_def_id) {
350+
if resolve_negative_obligation(infcx.fork(), o, body_def_id) {
357351
return true;
358352
}
359353

360354
// Try to prove a negative obligation exists for super predicates
361-
for o in util::elaborate_predicates(selcx.tcx(), iter::once(o.predicate)) {
362-
if resolve_negative_obligation(selcx.infcx().fork(), &o, body_def_id) {
355+
for o in util::elaborate_predicates(infcx.tcx, iter::once(o.predicate)) {
356+
if resolve_negative_obligation(infcx.fork(), &o, body_def_id) {
363357
return true;
364358
}
365359
}

0 commit comments

Comments
 (0)