@@ -19,6 +19,7 @@ use hir::map::Map;
1919use hir:: def:: Def ;
2020use hir:: def_id:: { CrateNum , DefId , LocalDefId , LOCAL_CRATE } ;
2121use hir:: ItemLocalId ;
22+ use hir:: LifetimeName ;
2223use ty:: { self , TyCtxt } ;
2324
2425use std:: cell:: Cell ;
@@ -569,10 +570,26 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
569570 for bound in bounds {
570571 self . visit_poly_trait_ref ( bound, hir:: TraitBoundModifier :: None ) ;
571572 }
572- if lifetime. is_elided ( ) {
573- self . resolve_object_lifetime_default ( lifetime)
574- } else {
575- self . visit_lifetime ( lifetime) ;
573+ match lifetime. name {
574+ LifetimeName :: Implicit => {
575+ // If the user does not write *anything*, we
576+ // use the object lifetime defaulting
577+ // rules. So e.g. `Box<dyn Debug>` becomes
578+ // `Box<dyn Debug + 'static>`.
579+ self . resolve_object_lifetime_default ( lifetime)
580+ }
581+ LifetimeName :: Underscore => {
582+ // If the user writes `'_`, we use the *ordinary* elision
583+ // rules. So the `'_` in e.g. `Box<dyn Debug + '_>` will be
584+ // resolved the same as the `'_` in `&'_ Foo`.
585+ //
586+ // cc #48468
587+ self . resolve_elided_lifetimes ( slice:: from_ref ( lifetime) , false )
588+ }
589+ LifetimeName :: Static | LifetimeName :: Name ( _) => {
590+ // If the user wrote an explicit name, use that.
591+ self . visit_lifetime ( lifetime) ;
592+ }
576593 }
577594 }
578595 hir:: TyRptr ( ref lifetime_ref, ref mt) => {
0 commit comments