@@ -67,7 +67,6 @@ use crate::infer::{
67
67
} ;
68
68
use crate :: traits:: { ObligationCause , ObligationCauseCode } ;
69
69
use rustc_data_structures:: undo_log:: UndoLogs ;
70
- use rustc_hir:: def_id:: DefId ;
71
70
use rustc_middle:: mir:: ConstraintCategory ;
72
71
use rustc_middle:: ty:: subst:: GenericArgKind ;
73
72
use rustc_middle:: ty:: { self , Region , SubstsRef , Ty , TyCtxt , TypeVisitable } ;
@@ -266,10 +265,8 @@ where
266
265
Component :: Param ( param_ty) => {
267
266
self . param_ty_must_outlive ( origin, region, * param_ty) ;
268
267
}
269
- Component :: Alias ( kind, data) => {
270
- self . alias_must_outlive ( * kind, * data, origin, region)
271
- }
272
- Component :: EscapingProjection ( subcomponents) => {
268
+ Component :: Alias ( alias_ty) => self . alias_ty_must_outlive ( origin, region, * alias_ty) ,
269
+ Component :: EscapingAlias ( subcomponents) => {
273
270
self . components_must_outlive ( origin, & subcomponents, region, category) ;
274
271
}
275
272
Component :: UnresolvedInferenceVariable ( v) => {
@@ -285,61 +282,26 @@ where
285
282
}
286
283
}
287
284
285
+ #[ instrument( level = "debug" , skip( self ) ) ]
288
286
fn param_ty_must_outlive (
289
287
& mut self ,
290
288
origin : infer:: SubregionOrigin < ' tcx > ,
291
289
region : ty:: Region < ' tcx > ,
292
290
param_ty : ty:: ParamTy ,
293
291
) {
294
- debug ! (
295
- "param_ty_must_outlive(region={:?}, param_ty={:?}, origin={:?})" ,
296
- region, param_ty, origin
297
- ) ;
298
-
299
- let generic = GenericKind :: Param ( param_ty) ;
300
292
let verify_bound = self . verify_bound . param_bound ( param_ty) ;
301
- self . delegate . push_verify ( origin, generic , region, verify_bound) ;
293
+ self . delegate . push_verify ( origin, GenericKind :: Param ( param_ty ) , region, verify_bound) ;
302
294
}
303
295
304
296
#[ instrument( level = "debug" , skip( self ) ) ]
305
- fn alias_must_outlive (
297
+ fn alias_ty_must_outlive (
306
298
& mut self ,
307
- kind : ty:: AliasKind ,
308
- data : ty:: AliasTy < ' tcx > ,
309
299
origin : infer:: SubregionOrigin < ' tcx > ,
310
300
region : ty:: Region < ' tcx > ,
311
- ) {
312
- self . generic_must_outlive (
313
- origin,
314
- region,
315
- GenericKind :: Alias ( kind, data) ,
316
- data. def_id ,
317
- data. substs ,
318
- kind == ty:: Opaque ,
319
- |ty| match * ty. kind ( ) {
320
- ty:: Alias ( filter_kind, ty:: AliasTy { def_id, substs, .. } )
321
- if kind == filter_kind =>
322
- {
323
- ( def_id, substs)
324
- }
325
- _ => bug ! ( "expected only projection types from env, not {:?}" , ty) ,
326
- } ,
327
- ) ;
328
- }
329
-
330
- #[ instrument( level = "debug" , skip( self , filter) ) ]
331
- fn generic_must_outlive (
332
- & mut self ,
333
- origin : infer:: SubregionOrigin < ' tcx > ,
334
- region : ty:: Region < ' tcx > ,
335
- generic : GenericKind < ' tcx > ,
336
- def_id : DefId ,
337
- substs : SubstsRef < ' tcx > ,
338
- is_opaque : bool ,
339
- filter : impl Fn ( Ty < ' tcx > ) -> ( DefId , SubstsRef < ' tcx > ) ,
301
+ alias_ty : ty:: AliasTy < ' tcx > ,
340
302
) {
341
303
// An optimization for a common case with opaque types.
342
- if substs. is_empty ( ) {
304
+ if alias_ty . substs . is_empty ( ) {
343
305
return ;
344
306
}
345
307
@@ -361,14 +323,14 @@ where
361
323
// These are guaranteed to apply, no matter the inference
362
324
// results.
363
325
let trait_bounds: Vec < _ > =
364
- self . verify_bound . declared_region_bounds ( def_id , substs ) . collect ( ) ;
326
+ self . verify_bound . declared_bounds_from_definition ( alias_ty ) . collect ( ) ;
365
327
366
328
debug ! ( ?trait_bounds) ;
367
329
368
330
// Compute the bounds we can derive from the environment. This
369
331
// is an "approximate" match -- in some cases, these bounds
370
332
// may not apply.
371
- let mut approx_env_bounds = self . verify_bound . approx_declared_bounds_from_env ( generic ) ;
333
+ let mut approx_env_bounds = self . verify_bound . approx_declared_bounds_from_env ( alias_ty ) ;
372
334
debug ! ( ?approx_env_bounds) ;
373
335
374
336
// Remove outlives bounds that we get from the environment but
@@ -383,8 +345,8 @@ where
383
345
// If the declaration is `trait Trait<'b> { type Item: 'b; }`, then `projection_declared_bounds_from_trait`
384
346
// will be invoked with `['b => ^1]` and so we will get `^1` returned.
385
347
let bound = bound_outlives. skip_binder ( ) ;
386
- let ( def_id , substs ) = filter ( bound. 0 ) ;
387
- self . verify_bound . declared_region_bounds ( def_id , substs ) . all ( |r| r != bound. 1 )
348
+ let ty :: Alias ( _ , alias_ty ) = bound. 0 . kind ( ) else { bug ! ( "expected AliasTy" ) } ;
349
+ self . verify_bound . declared_bounds_from_definition ( * alias_ty ) . all ( |r| r != bound. 1 )
388
350
} ) ;
389
351
390
352
// If declared bounds list is empty, the only applicable rule is
@@ -401,12 +363,12 @@ where
401
363
// the problem is to add `T: 'r`, which isn't true. So, if there are no
402
364
// inference variables, we use a verify constraint instead of adding
403
365
// edges, which winds up enforcing the same condition.
404
- let needs_infer = substs. needs_infer ( ) ;
405
- if approx_env_bounds. is_empty ( ) && trait_bounds. is_empty ( ) && ( needs_infer || is_opaque) {
366
+ if approx_env_bounds. is_empty ( )
367
+ && trait_bounds. is_empty ( )
368
+ && ( alias_ty. needs_infer ( ) || alias_ty. kind ( self . tcx ) == ty:: Opaque )
369
+ {
406
370
debug ! ( "no declared bounds" ) ;
407
-
408
- self . substs_must_outlive ( substs, origin, region) ;
409
-
371
+ self . substs_must_outlive ( alias_ty. substs , origin, region) ;
410
372
return ;
411
373
}
412
374
@@ -447,14 +409,9 @@ where
447
409
// projection outlive; in some cases, this may add insufficient
448
410
// edges into the inference graph, leading to inference failures
449
411
// even though a satisfactory solution exists.
450
- let verify_bound = self . verify_bound . projection_opaque_bounds (
451
- generic,
452
- def_id,
453
- substs,
454
- & mut Default :: default ( ) ,
455
- ) ;
456
- debug ! ( "projection_must_outlive: pushing {:?}" , verify_bound) ;
457
- self . delegate . push_verify ( origin, generic, region, verify_bound) ;
412
+ let verify_bound = self . verify_bound . alias_bound ( alias_ty, & mut Default :: default ( ) ) ;
413
+ debug ! ( "alias_must_outlive: pushing {:?}" , verify_bound) ;
414
+ self . delegate . push_verify ( origin, GenericKind :: Alias ( alias_ty) , region, verify_bound) ;
458
415
}
459
416
460
417
fn substs_must_outlive (
0 commit comments