diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 77bb78e4ee0783c59846cb44ac4ab92564950699..41c824a5e0e7f8cb119d52b9d6a65dbcec807839 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -19,7 +19,7 @@ use ty::fold::TypeFoldable; use ty::subst::Subst; -use infer::{InferCtxt, InferOk}; +use infer::{InferOk}; /// Whether we do the orphan check relative to this crate or /// to some remote crate. @@ -43,8 +43,8 @@ pub struct OverlapResult<'tcx> { /// If there are types that satisfy both impls, invokes `on_overlap` /// with a suitably-freshened `ImplHeader` with those types /// substituted. Otherwise, invokes `no_overlap`. -pub fn overlapping_impls( - infcx: &InferCtxt<'_, '_, '_>, +pub fn overlapping_impls<'gcx, F1, F2, R>( + tcx: TyCtxt<'_, 'gcx, 'gcx>, impl1_def_id: DefId, impl2_def_id: DefId, intercrate_mode: IntercrateMode, @@ -63,12 +63,14 @@ pub fn overlapping_impls( impl2_def_id, intercrate_mode); - let selcx = &mut SelectionContext::intercrate(infcx, intercrate_mode); - if let Some(r) = overlap(selcx, impl1_def_id, impl2_def_id) { - on_overlap(r) - } else { - no_overlap() - } + tcx.infer_ctxt().enter(|infcx| { + let selcx = &mut SelectionContext::intercrate(&infcx, intercrate_mode); + if let Some(r) = overlap(selcx, impl1_def_id, impl2_def_id) { + on_overlap(r) + } else { + no_overlap() + } + }) } fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>, diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index 4ad2a4955e9ede1262a64371f3b1cb88eb30a4b4..a10169e13e60a705e4bc9e0bc3d6cf75cf5a4a75 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -133,29 +133,27 @@ fn insert(&mut self, }; let tcx = tcx.global_tcx(); - let (le, ge) = tcx.infer_ctxt().enter(|infcx| { - traits::overlapping_impls( - &infcx, - possible_sibling, - impl_def_id, - traits::IntercrateMode::Issue43355, - |overlap| { - if tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) { - return Ok((false, false)); - } - - let le = tcx.specializes((impl_def_id, possible_sibling)); - let ge = tcx.specializes((possible_sibling, impl_def_id)); - - if le == ge { - Err(overlap_error(overlap)) - } else { - Ok((le, ge)) - } - }, - || Ok((false, false)), - ) - })?; + let (le, ge) = traits::overlapping_impls( + tcx, + possible_sibling, + impl_def_id, + traits::IntercrateMode::Issue43355, + |overlap| { + if tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) { + return Ok((false, false)); + } + + let le = tcx.specializes((impl_def_id, possible_sibling)); + let ge = tcx.specializes((possible_sibling, impl_def_id)); + + if le == ge { + Err(overlap_error(overlap)) + } else { + Ok((le, ge)) + } + }, + || Ok((false, false)), + )?; if le && !ge { debug!("descending as child of TraitRef {:?}", @@ -172,16 +170,14 @@ fn insert(&mut self, return Ok(Inserted::Replaced(possible_sibling)); } else { if !tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) { - tcx.infer_ctxt().enter(|infcx| { - traits::overlapping_impls( - &infcx, - possible_sibling, - impl_def_id, - traits::IntercrateMode::Fixed, - |overlap| last_lint = Some(overlap_error(overlap)), - || (), - ) - }); + traits::overlapping_impls( + tcx, + possible_sibling, + impl_def_id, + traits::IntercrateMode::Fixed, + |overlap| last_lint = Some(overlap_error(overlap)), + || (), + ); } // no overlap (error bailed already via ?) diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index c8a37c01094ac8b4493cb705660e1769d382ef28..88a2dc817ae63f139f1ad1a38bee016c777fa732 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -82,41 +82,37 @@ fn check_for_overlapping_inherent_impls(&self, ty_def_id: DefId) { for (i, &impl1_def_id) in impls.iter().enumerate() { for &impl2_def_id in &impls[(i + 1)..] { - let used_to_be_allowed = self.tcx.infer_ctxt().enter(|infcx| { + let used_to_be_allowed = traits::overlapping_impls( + self.tcx, + impl1_def_id, + impl2_def_id, + IntercrateMode::Issue43355, + |overlap| { + self.check_for_common_items_in_impls( + impl1_def_id, + impl2_def_id, + overlap, + false, + ); + false + }, + || true, + ); + + if used_to_be_allowed { traits::overlapping_impls( - &infcx, + self.tcx, impl1_def_id, impl2_def_id, - IntercrateMode::Issue43355, - |overlap| { - self.check_for_common_items_in_impls( - impl1_def_id, - impl2_def_id, - overlap, - false, - ); - false - }, - || true, - ) - }); - - if used_to_be_allowed { - self.tcx.infer_ctxt().enter(|infcx| { - traits::overlapping_impls( - &infcx, + IntercrateMode::Fixed, + |overlap| self.check_for_common_items_in_impls( impl1_def_id, impl2_def_id, - IntercrateMode::Fixed, - |overlap| self.check_for_common_items_in_impls( - impl1_def_id, - impl2_def_id, - overlap, - true, - ), - || (), - ); - }); + overlap, + true, + ), + || (), + ); } } }