@@ -14,7 +14,6 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
14
14
use crate :: traits:: select:: IntercrateAmbiguityCause ;
15
15
use crate :: traits:: structural_normalize:: StructurallyNormalizeExt ;
16
16
use crate :: traits:: NormalizeExt ;
17
- use crate :: traits:: SkipLeakCheck ;
18
17
use crate :: traits:: {
19
18
Obligation , ObligationCause , ObligationCtxt , PredicateObligation , PredicateObligations ,
20
19
SelectionContext ,
@@ -85,12 +84,11 @@ impl TrackAmbiguityCauses {
85
84
/// If there are types that satisfy both impls, returns `Some`
86
85
/// with a suitably-freshened `ImplHeader` with those types
87
86
/// substituted. Otherwise, returns `None`.
88
- #[ instrument( skip( tcx, skip_leak_check ) , level = "debug" ) ]
87
+ #[ instrument( skip( tcx) , level = "debug" ) ]
89
88
pub fn overlapping_impls (
90
89
tcx : TyCtxt < ' _ > ,
91
90
impl1_def_id : DefId ,
92
91
impl2_def_id : DefId ,
93
- skip_leak_check : SkipLeakCheck ,
94
92
overlap_mode : OverlapMode ,
95
93
) -> Option < OverlapResult < ' _ > > {
96
94
// Before doing expensive operations like entering an inference context, do
@@ -115,27 +113,14 @@ pub fn overlapping_impls(
115
113
return None ;
116
114
}
117
115
118
- let _overlap_with_bad_diagnostics = overlap (
119
- tcx,
120
- TrackAmbiguityCauses :: No ,
121
- skip_leak_check,
122
- impl1_def_id,
123
- impl2_def_id,
124
- overlap_mode,
125
- ) ?;
116
+ let _overlap_with_bad_diagnostics =
117
+ overlap ( tcx, TrackAmbiguityCauses :: No , impl1_def_id, impl2_def_id, overlap_mode) ?;
126
118
127
119
// In the case where we detect an error, run the check again, but
128
120
// this time tracking intercrate ambiguity causes for better
129
121
// diagnostics. (These take time and can lead to false errors.)
130
- let overlap = overlap (
131
- tcx,
132
- TrackAmbiguityCauses :: Yes ,
133
- skip_leak_check,
134
- impl1_def_id,
135
- impl2_def_id,
136
- overlap_mode,
137
- )
138
- . unwrap ( ) ;
122
+ let overlap =
123
+ overlap ( tcx, TrackAmbiguityCauses :: Yes , impl1_def_id, impl2_def_id, overlap_mode) . unwrap ( ) ;
139
124
Some ( overlap)
140
125
}
141
126
@@ -177,7 +162,6 @@ fn fresh_impl_header_normalized<'tcx>(
177
162
fn overlap < ' tcx > (
178
163
tcx : TyCtxt < ' tcx > ,
179
164
track_ambiguity_causes : TrackAmbiguityCauses ,
180
- skip_leak_check : SkipLeakCheck ,
181
165
impl1_def_id : DefId ,
182
166
impl2_def_id : DefId ,
183
167
overlap_mode : OverlapMode ,
@@ -193,7 +177,6 @@ fn overlap<'tcx>(
193
177
let infcx = tcx
194
178
. infer_ctxt ( )
195
179
. with_opaque_type_inference ( DefiningAnchor :: Bubble )
196
- . skip_leak_check ( skip_leak_check. is_yes ( ) )
197
180
. intercrate ( true )
198
181
. with_next_trait_solver ( tcx. next_trait_solver_in_coherence ( ) )
199
182
. build ( ) ;
@@ -231,8 +214,15 @@ fn overlap<'tcx>(
231
214
}
232
215
}
233
216
234
- // We toggle the `leak_check` by using `skip_leak_check` when constructing the
235
- // inference context, so this may be a noop.
217
+ // Detect any region errors caused by equating these two impls.
218
+ //
219
+ // Only higher ranked region errors are possible here, given that we
220
+ // replaced all parameter regions with existentials.
221
+ //
222
+ // Unlike a full region check, which sometimes incompletely handles
223
+ // `TypeOutlives` constraints, the leak check is a complete. While the
224
+ // leak check does not detect all region errors, it never
225
+ // fails in cases which would later pass full region checking.
236
226
if infcx. leak_check ( ty:: UniverseIndex :: ROOT , None ) . is_err ( ) {
237
227
debug ! ( "overlap: leak check failed" ) ;
238
228
return None ;
0 commit comments