@@ -67,7 +67,6 @@ use crate::infer::{
6767} ;
6868use crate :: traits:: { ObligationCause , ObligationCauseCode } ;
6969use rustc_data_structures:: undo_log:: UndoLogs ;
70- use rustc_hir:: def_id:: DefId ;
7170use rustc_middle:: mir:: ConstraintCategory ;
7271use rustc_middle:: ty:: subst:: GenericArgKind ;
7372use rustc_middle:: ty:: { self , Region , SubstsRef , Ty , TyCtxt , TypeVisitable } ;
@@ -266,10 +265,8 @@ where
266265 Component :: Param ( param_ty) => {
267266 self . param_ty_must_outlive ( origin, region, * param_ty) ;
268267 }
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) => {
273270 self . components_must_outlive ( origin, & subcomponents, region, category) ;
274271 }
275272 Component :: UnresolvedInferenceVariable ( v) => {
@@ -285,61 +282,26 @@ where
285282 }
286283 }
287284
285+ #[ instrument( level = "debug" , skip( self ) ) ]
288286 fn param_ty_must_outlive (
289287 & mut self ,
290288 origin : infer:: SubregionOrigin < ' tcx > ,
291289 region : ty:: Region < ' tcx > ,
292290 param_ty : ty:: ParamTy ,
293291 ) {
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) ;
300292 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) ;
302294 }
303295
304296 #[ instrument( level = "debug" , skip( self ) ) ]
305- fn alias_must_outlive (
297+ fn alias_ty_must_outlive (
306298 & mut self ,
307- kind : ty:: AliasKind ,
308- data : ty:: AliasTy < ' tcx > ,
309299 origin : infer:: SubregionOrigin < ' tcx > ,
310300 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 > ,
340302 ) {
341303 // An optimization for a common case with opaque types.
342- if substs. is_empty ( ) {
304+ if alias_ty . substs . is_empty ( ) {
343305 return ;
344306 }
345307
@@ -361,14 +323,14 @@ where
361323 // These are guaranteed to apply, no matter the inference
362324 // results.
363325 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 ( ) ;
365327
366328 debug ! ( ?trait_bounds) ;
367329
368330 // Compute the bounds we can derive from the environment. This
369331 // is an "approximate" match -- in some cases, these bounds
370332 // 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 ) ;
372334 debug ! ( ?approx_env_bounds) ;
373335
374336 // Remove outlives bounds that we get from the environment but
@@ -383,8 +345,8 @@ where
383345 // If the declaration is `trait Trait<'b> { type Item: 'b; }`, then `projection_declared_bounds_from_trait`
384346 // will be invoked with `['b => ^1]` and so we will get `^1` returned.
385347 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 )
388350 } ) ;
389351
390352 // If declared bounds list is empty, the only applicable rule is
@@ -401,12 +363,12 @@ where
401363 // the problem is to add `T: 'r`, which isn't true. So, if there are no
402364 // inference variables, we use a verify constraint instead of adding
403365 // 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+ {
406370 debug ! ( "no declared bounds" ) ;
407-
408- self . substs_must_outlive ( substs, origin, region) ;
409-
371+ self . substs_must_outlive ( alias_ty. substs , origin, region) ;
410372 return ;
411373 }
412374
@@ -447,14 +409,9 @@ where
447409 // projection outlive; in some cases, this may add insufficient
448410 // edges into the inference graph, leading to inference failures
449411 // 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) ;
458415 }
459416
460417 fn substs_must_outlive (
0 commit comments