@@ -30,7 +30,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3030 hir_id : hir:: HirId ,
3131 hir_trait_bounds : & [ ( hir:: PolyTraitRef < ' tcx > , hir:: TraitBoundModifier ) ] ,
3232 lifetime : & hir:: Lifetime ,
33- borrowed : bool ,
33+ _borrowed : bool ,
3434 representation : DynKind ,
3535 ) -> Ty < ' tcx > {
3636 let tcx = self . tcx ( ) ;
@@ -325,22 +325,32 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
325325 v. dedup ( ) ;
326326 let existential_predicates = tcx. mk_poly_existential_predicates ( & v) ;
327327
328- // Use explicitly-specified region bound.
328+ // Use explicitly-specified region bound, unless the bound is missing .
329329 let region_bound = if !lifetime. is_elided ( ) {
330- self . lower_lifetime ( lifetime, RegionInferReason :: ObjectLifetimeDefault )
330+ self . lower_lifetime ( lifetime, RegionInferReason :: ExplicitObjectLifetime )
331331 } else {
332332 self . compute_object_lifetime_bound ( span, existential_predicates) . unwrap_or_else ( || {
333+ // Curiously, we prefer object lifetime default for `+ '_`...
333334 if tcx. named_bound_var ( lifetime. hir_id ) . is_some ( ) {
334- self . lower_lifetime ( lifetime, RegionInferReason :: ObjectLifetimeDefault )
335+ self . lower_lifetime ( lifetime, RegionInferReason :: ExplicitObjectLifetime )
335336 } else {
336- self . re_infer (
337- span,
338- if borrowed {
339- RegionInferReason :: ObjectLifetimeDefault
337+ let reason =
338+ if let hir:: LifetimeName :: ImplicitObjectLifetimeDefault = lifetime. res {
339+ if let hir:: Node :: Ty ( hir:: Ty {
340+ kind : hir:: TyKind :: Ref ( parent_lifetime, _) ,
341+ ..
342+ } ) = tcx. parent_hir_node ( hir_id)
343+ && tcx. named_bound_var ( parent_lifetime. hir_id ) . is_none ( )
344+ {
345+ // Parent lifetime must have failed to resolve. Don't emit a redundant error.
346+ RegionInferReason :: ExplicitObjectLifetime
347+ } else {
348+ RegionInferReason :: ObjectLifetimeDefault
349+ }
340350 } else {
341- RegionInferReason :: BorrowedObjectLifetimeDefault
342- } ,
343- )
351+ RegionInferReason :: ExplicitObjectLifetime
352+ } ;
353+ self . re_infer ( span , reason )
344354 }
345355 } )
346356 } ;
0 commit comments