From 2faad3b699b7b80b08f4af7cfc67fff097256630 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 21 Nov 2022 11:04:55 -0300 Subject: [PATCH 1/2] negative_impl should take a TyCtxt --- .../rustc_trait_selection/src/traits/coherence.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 3cf2959a9ffc5..8dd9693451055 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -162,8 +162,8 @@ fn overlap_within_probe<'cx, 'tcx>( let infcx = selcx.infcx(); if overlap_mode.use_negative_impl() { - if negative_impl(selcx, impl1_def_id, impl2_def_id) - || negative_impl(selcx, impl2_def_id, impl1_def_id) + if negative_impl(infcx.tcx, impl1_def_id, impl2_def_id) + || negative_impl(infcx.tcx, impl2_def_id, impl1_def_id) { 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 /// where-clauses) If so, return true, they are disjoint and false otherwise. -fn negative_impl<'cx, 'tcx>( - selcx: &mut SelectionContext<'cx, 'tcx>, - impl1_def_id: DefId, - impl2_def_id: DefId, -) -> bool { +fn negative_impl<'tcx>(tcx: TyCtxt<'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); - let tcx = selcx.infcx().tcx; // Create an infcx, taking the predicates of impl1 as assumptions: let infcx = tcx.infer_ctxt().build(); From 16c9e39021924216005d823b67aa601950bc2184 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 21 Nov 2022 11:26:23 -0300 Subject: [PATCH 2/2] negative_impl_exists should take an InferCtxt --- .../rustc_trait_selection/src/traits/coherence.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 8dd9693451055..1ef77e06b4874 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -327,11 +327,10 @@ fn equate<'tcx>( return true; }; - let selcx = &mut SelectionContext::new(&infcx); let opt_failing_obligation = obligations .into_iter() .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 { debug!("overlap: obligation unsatisfiable {:?}", failing_obligation); @@ -342,19 +341,19 @@ fn equate<'tcx>( } /// Try to prove that a negative impl exist for the given obligation and its super predicates. -#[instrument(level = "debug", skip(selcx))] -fn negative_impl_exists<'cx, 'tcx>( - selcx: &SelectionContext<'cx, 'tcx>, +#[instrument(level = "debug", skip(infcx))] +fn negative_impl_exists<'tcx>( + infcx: &InferCtxt<'tcx>, o: &PredicateObligation<'tcx>, body_def_id: DefId, ) -> bool { - if resolve_negative_obligation(selcx.infcx().fork(), o, body_def_id) { + if resolve_negative_obligation(infcx.fork(), o, body_def_id) { return true; } // Try to prove a negative obligation exists for super predicates - for o in util::elaborate_predicates(selcx.tcx(), iter::once(o.predicate)) { - if resolve_negative_obligation(selcx.infcx().fork(), &o, body_def_id) { + for o in util::elaborate_predicates(infcx.tcx, iter::once(o.predicate)) { + if resolve_negative_obligation(infcx.fork(), &o, body_def_id) { return true; } }