@@ -13,7 +13,6 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
1313use crate :: traits:: select:: IntercrateAmbiguityCause ;
1414use crate :: traits:: structural_normalize:: StructurallyNormalizeExt ;
1515use crate :: traits:: NormalizeExt ;
16- use crate :: traits:: SkipLeakCheck ;
1716use crate :: traits:: {
1817 Obligation , ObligationCause , ObligationCtxt , PredicateObligation , PredicateObligations ,
1918 SelectionContext ,
@@ -84,12 +83,11 @@ impl TrackAmbiguityCauses {
8483/// If there are types that satisfy both impls, returns `Some`
8584/// with a suitably-freshened `ImplHeader` with those types
8685/// substituted. Otherwise, returns `None`.
87- #[ instrument( skip( tcx, skip_leak_check ) , level = "debug" ) ]
86+ #[ instrument( skip( tcx) , level = "debug" ) ]
8887pub fn overlapping_impls (
8988 tcx : TyCtxt < ' _ > ,
9089 impl1_def_id : DefId ,
9190 impl2_def_id : DefId ,
92- skip_leak_check : SkipLeakCheck ,
9391 overlap_mode : OverlapMode ,
9492) -> Option < OverlapResult < ' _ > > {
9593 // Before doing expensive operations like entering an inference context, do
@@ -114,27 +112,14 @@ pub fn overlapping_impls(
114112 return None ;
115113 }
116114
117- let _overlap_with_bad_diagnostics = overlap (
118- tcx,
119- TrackAmbiguityCauses :: No ,
120- skip_leak_check,
121- impl1_def_id,
122- impl2_def_id,
123- overlap_mode,
124- ) ?;
115+ let _overlap_with_bad_diagnostics =
116+ overlap ( tcx, TrackAmbiguityCauses :: No , impl1_def_id, impl2_def_id, overlap_mode) ?;
125117
126118 // In the case where we detect an error, run the check again, but
127119 // this time tracking intercrate ambiguity causes for better
128120 // diagnostics. (These take time and can lead to false errors.)
129- let overlap = overlap (
130- tcx,
131- TrackAmbiguityCauses :: Yes ,
132- skip_leak_check,
133- impl1_def_id,
134- impl2_def_id,
135- overlap_mode,
136- )
137- . unwrap ( ) ;
121+ let overlap =
122+ overlap ( tcx, TrackAmbiguityCauses :: Yes , impl1_def_id, impl2_def_id, overlap_mode) . unwrap ( ) ;
138123 Some ( overlap)
139124}
140125
@@ -176,7 +161,6 @@ fn fresh_impl_header_normalized<'tcx>(
176161fn overlap < ' tcx > (
177162 tcx : TyCtxt < ' tcx > ,
178163 track_ambiguity_causes : TrackAmbiguityCauses ,
179- skip_leak_check : SkipLeakCheck ,
180164 impl1_def_id : DefId ,
181165 impl2_def_id : DefId ,
182166 overlap_mode : OverlapMode ,
@@ -192,7 +176,6 @@ fn overlap<'tcx>(
192176 let infcx = tcx
193177 . infer_ctxt ( )
194178 . with_opaque_type_inference ( DefiningAnchor :: Bubble )
195- . skip_leak_check ( skip_leak_check. is_yes ( ) )
196179 . intercrate ( true )
197180 . with_next_trait_solver ( tcx. next_trait_solver_in_coherence ( ) )
198181 . build ( ) ;
@@ -230,8 +213,15 @@ fn overlap<'tcx>(
230213 }
231214 }
232215
233- // We toggle the `leak_check` by using `skip_leak_check` when constructing the
234- // inference context, so this may be a noop.
216+ // Detect any region errors caused by equating these two impls.
217+ //
218+ // Only higher ranked region errors are possible here, given that we
219+ // replaced all parameter regions with existentials.
220+ //
221+ // Unlike a full region check, which sometimes incompletely handles
222+ // `TypeOutlives` constraints, the leak check is a complete. While the
223+ // leak check does not detect all region errors, it never
224+ // fails in cases which would later pass full region checking.
235225 if infcx. leak_check ( ty:: UniverseIndex :: ROOT , None ) . is_err ( ) {
236226 debug ! ( "overlap: leak check failed" ) ;
237227 return None ;
0 commit comments