@@ -2,13 +2,9 @@ use rustc_errors::DiagnosticBuilder;
2
2
use rustc_infer:: infer:: canonical:: Canonical ;
3
3
use rustc_infer:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
4
4
use rustc_infer:: infer:: region_constraints:: Constraint ;
5
- use rustc_infer:: infer:: region_constraints:: RegionConstraintData ;
6
- use rustc_infer:: infer:: RegionVariableOrigin ;
7
5
use rustc_infer:: infer:: { InferCtxt , RegionResolutionError , SubregionOrigin , TyCtxtInferExt as _} ;
8
6
use rustc_infer:: traits:: { Normalized , ObligationCause , TraitEngine , TraitEngineExt } ;
9
7
use rustc_middle:: ty:: error:: TypeError ;
10
- use rustc_middle:: ty:: RegionVid ;
11
- use rustc_middle:: ty:: UniverseIndex ;
12
8
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
13
9
use rustc_span:: Span ;
14
10
use rustc_trait_selection:: traits:: query:: type_op;
@@ -82,15 +78,6 @@ crate trait ToUniverseInfo<'tcx> {
82
78
fn to_universe_info ( self , base_universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > ;
83
79
}
84
80
85
- impl < ' tcx > ToUniverseInfo < ' tcx > for crate :: type_check:: InstantiateOpaqueType < ' tcx > {
86
- fn to_universe_info ( self , base_universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > {
87
- UniverseInfo ( UniverseInfoInner :: TypeOp ( Rc :: new ( crate :: type_check:: InstantiateOpaqueType {
88
- base_universe : Some ( base_universe) ,
89
- ..self
90
- } ) ) )
91
- }
92
- }
93
-
94
81
impl < ' tcx > ToUniverseInfo < ' tcx >
95
82
for Canonical < ' tcx , ty:: ParamEnvAnd < ' tcx , type_op:: prove_predicate:: ProvePredicate < ' tcx > > >
96
83
{
@@ -131,12 +118,6 @@ impl<'tcx, F, G> ToUniverseInfo<'tcx> for Canonical<'tcx, type_op::custom::Custo
131
118
}
132
119
}
133
120
134
- impl < ' tcx > ToUniverseInfo < ' tcx > for ! {
135
- fn to_universe_info ( self , _base_universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > {
136
- self
137
- }
138
- }
139
-
140
121
#[ allow( unused_lifetimes) ]
141
122
trait TypeOpInfo < ' tcx > {
142
123
/// Returns an error to be reported if rerunning the type op fails to
@@ -147,7 +128,7 @@ trait TypeOpInfo<'tcx> {
147
128
148
129
fn nice_error (
149
130
& self ,
150
- mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
131
+ tcx : TyCtxt < ' tcx > ,
151
132
cause : ObligationCause < ' tcx > ,
152
133
placeholder_region : ty:: Region < ' tcx > ,
153
134
error_region : Option < ty:: Region < ' tcx > > ,
@@ -194,7 +175,7 @@ trait TypeOpInfo<'tcx> {
194
175
debug ! ( ?placeholder_region) ;
195
176
196
177
let span = cause. span ;
197
- let nice_error = self . nice_error ( mbcx , cause, placeholder_region, error_region) ;
178
+ let nice_error = self . nice_error ( tcx , cause, placeholder_region, error_region) ;
198
179
199
180
if let Some ( nice_error) = nice_error {
200
181
nice_error. buffer ( & mut mbcx. errors_buffer ) ;
@@ -223,16 +204,16 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
223
204
224
205
fn nice_error (
225
206
& self ,
226
- mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
207
+ tcx : TyCtxt < ' tcx > ,
227
208
cause : ObligationCause < ' tcx > ,
228
209
placeholder_region : ty:: Region < ' tcx > ,
229
210
error_region : Option < ty:: Region < ' tcx > > ,
230
211
) -> Option < DiagnosticBuilder < ' tcx > > {
231
- mbcx . infcx . tcx . infer_ctxt ( ) . enter_with_canonical (
212
+ tcx. infer_ctxt ( ) . enter_with_canonical (
232
213
cause. span ,
233
214
& self . canonical_query ,
234
215
|ref infcx, key, _| {
235
- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( infcx . tcx ) ;
216
+ let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
236
217
type_op_prove_predicate_with_cause ( infcx, & mut * fulfill_cx, key, cause) ;
237
218
try_extract_error_from_fulfill_cx (
238
219
fulfill_cx,
@@ -266,16 +247,16 @@ where
266
247
267
248
fn nice_error (
268
249
& self ,
269
- mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
250
+ tcx : TyCtxt < ' tcx > ,
270
251
cause : ObligationCause < ' tcx > ,
271
252
placeholder_region : ty:: Region < ' tcx > ,
272
253
error_region : Option < ty:: Region < ' tcx > > ,
273
254
) -> Option < DiagnosticBuilder < ' tcx > > {
274
- mbcx . infcx . tcx . infer_ctxt ( ) . enter_with_canonical (
255
+ tcx. infer_ctxt ( ) . enter_with_canonical (
275
256
cause. span ,
276
257
& self . canonical_query ,
277
258
|ref infcx, key, _| {
278
- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( infcx . tcx ) ;
259
+ let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
279
260
280
261
let mut selcx = SelectionContext :: new ( infcx) ;
281
262
@@ -323,16 +304,16 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
323
304
324
305
fn nice_error (
325
306
& self ,
326
- mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
307
+ tcx : TyCtxt < ' tcx > ,
327
308
cause : ObligationCause < ' tcx > ,
328
309
placeholder_region : ty:: Region < ' tcx > ,
329
310
error_region : Option < ty:: Region < ' tcx > > ,
330
311
) -> Option < DiagnosticBuilder < ' tcx > > {
331
- mbcx . infcx . tcx . infer_ctxt ( ) . enter_with_canonical (
312
+ tcx. infer_ctxt ( ) . enter_with_canonical (
332
313
cause. span ,
333
314
& self . canonical_query ,
334
315
|ref infcx, key, _| {
335
- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( infcx . tcx ) ;
316
+ let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
336
317
type_op_ascribe_user_type_with_span ( infcx, & mut * fulfill_cx, key, Some ( cause. span ) )
337
318
. ok ( ) ?;
338
319
try_extract_error_from_fulfill_cx (
@@ -346,90 +327,43 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
346
327
}
347
328
}
348
329
349
- impl < ' tcx > TypeOpInfo < ' tcx > for crate :: type_check:: InstantiateOpaqueType < ' tcx > {
350
- fn fallback_error ( & self , tcx : TyCtxt < ' tcx > , span : Span ) -> DiagnosticBuilder < ' tcx > {
351
- // FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
352
- // and is only the fallback when the nice error fails. Consider improving this some more.
353
- tcx. sess . struct_span_err ( span, "higher-ranked lifetime error for opaque type!" )
354
- }
355
-
356
- fn base_universe ( & self ) -> ty:: UniverseIndex {
357
- self . base_universe . unwrap ( )
358
- }
359
-
360
- fn nice_error (
361
- & self ,
362
- mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
363
- _cause : ObligationCause < ' tcx > ,
364
- placeholder_region : ty:: Region < ' tcx > ,
365
- error_region : Option < ty:: Region < ' tcx > > ,
366
- ) -> Option < DiagnosticBuilder < ' tcx > > {
367
- try_extract_error_from_region_constraints (
368
- mbcx. infcx ,
369
- placeholder_region,
370
- error_region,
371
- self . region_constraints . as_ref ( ) . unwrap ( ) ,
372
- // We're using the original `InferCtxt` that we
373
- // started MIR borrowchecking with, so the region
374
- // constraints have already been taken. Use the data from
375
- // our `mbcx` instead.
376
- |vid| mbcx. regioncx . var_infos [ vid] . origin ,
377
- |vid| mbcx. regioncx . var_infos [ vid] . universe ,
378
- )
379
- }
380
- }
381
-
382
330
#[ instrument( skip( fulfill_cx, infcx) , level = "debug" ) ]
383
331
fn try_extract_error_from_fulfill_cx < ' tcx > (
384
332
mut fulfill_cx : Box < dyn TraitEngine < ' tcx > + ' tcx > ,
385
333
infcx : & InferCtxt < ' _ , ' tcx > ,
386
334
placeholder_region : ty:: Region < ' tcx > ,
387
335
error_region : Option < ty:: Region < ' tcx > > ,
388
336
) -> Option < DiagnosticBuilder < ' tcx > > {
337
+ let tcx = infcx. tcx ;
338
+
389
339
// We generally shouldn't have errors here because the query was
390
340
// already run, but there's no point using `delay_span_bug`
391
341
// when we're going to emit an error here anyway.
392
342
let _errors = fulfill_cx. select_all_or_error ( infcx) ;
393
- let region_constraints = infcx. with_region_constraints ( |r| r. clone ( ) ) ;
394
- try_extract_error_from_region_constraints (
395
- infcx,
396
- placeholder_region,
397
- error_region,
398
- & region_constraints,
399
- |vid| infcx. region_var_origin ( vid) ,
400
- |vid| infcx. universe_of_region ( infcx. tcx . mk_region ( ty:: ReVar ( vid) ) ) ,
401
- )
402
- }
403
343
404
- fn try_extract_error_from_region_constraints < ' tcx > (
405
- infcx : & InferCtxt < ' _ , ' tcx > ,
406
- placeholder_region : ty:: Region < ' tcx > ,
407
- error_region : Option < ty:: Region < ' tcx > > ,
408
- region_constraints : & RegionConstraintData < ' tcx > ,
409
- mut region_var_origin : impl FnMut ( RegionVid ) -> RegionVariableOrigin ,
410
- mut universe_of_region : impl FnMut ( RegionVid ) -> UniverseIndex ,
411
- ) -> Option < DiagnosticBuilder < ' tcx > > {
412
- let ( sub_region, cause) =
344
+ let ( sub_region, cause) = infcx. with_region_constraints ( |region_constraints| {
345
+ debug ! ( "{:#?}" , region_constraints) ;
413
346
region_constraints. constraints . iter ( ) . find_map ( |( constraint, cause) | {
414
347
match * constraint {
415
348
Constraint :: RegSubReg ( sub, sup) if sup == placeholder_region && sup != sub => {
416
349
Some ( ( sub, cause. clone ( ) ) )
417
350
}
418
351
// FIXME: Should this check the universe of the var?
419
352
Constraint :: VarSubReg ( vid, sup) if sup == placeholder_region => {
420
- Some ( ( infcx . tcx . mk_region ( ty:: ReVar ( vid) ) , cause. clone ( ) ) )
353
+ Some ( ( tcx. mk_region ( ty:: ReVar ( vid) ) , cause. clone ( ) ) )
421
354
}
422
355
_ => None ,
423
356
}
424
- } ) ?;
357
+ } )
358
+ } ) ?;
425
359
426
360
debug ! ( ?sub_region, "cause = {:#?}" , cause) ;
427
361
let nice_error = match ( error_region, sub_region) {
428
362
( Some ( error_region) , & ty:: ReVar ( vid) ) => NiceRegionError :: new (
429
363
infcx,
430
364
RegionResolutionError :: SubSupConflict (
431
365
vid,
432
- region_var_origin ( vid) ,
366
+ infcx . region_var_origin ( vid) ,
433
367
cause. clone ( ) ,
434
368
error_region,
435
369
cause. clone ( ) ,
@@ -446,8 +380,8 @@ fn try_extract_error_from_region_constraints<'tcx>(
446
380
infcx,
447
381
RegionResolutionError :: UpperBoundUniverseConflict (
448
382
vid,
449
- region_var_origin ( vid) ,
450
- universe_of_region ( vid ) ,
383
+ infcx . region_var_origin ( vid) ,
384
+ infcx . universe_of_region ( sub_region ) ,
451
385
cause. clone ( ) ,
452
386
placeholder_region,
453
387
) ,
0 commit comments