@@ -30,7 +30,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
30
30
hir_id : hir:: HirId ,
31
31
hir_trait_bounds : & [ ( hir:: PolyTraitRef < ' tcx > , hir:: TraitBoundModifier ) ] ,
32
32
lifetime : & hir:: Lifetime ,
33
- borrowed : bool ,
33
+ _borrowed : bool ,
34
34
representation : DynKind ,
35
35
) -> Ty < ' tcx > {
36
36
let tcx = self . tcx ( ) ;
@@ -325,22 +325,32 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
325
325
v. dedup ( ) ;
326
326
let existential_predicates = tcx. mk_poly_existential_predicates ( & v) ;
327
327
328
- // Use explicitly-specified region bound.
328
+ // Use explicitly-specified region bound, unless the bound is missing .
329
329
let region_bound = if !lifetime. is_elided ( ) {
330
- self . lower_lifetime ( lifetime, RegionInferReason :: ObjectLifetimeDefault )
330
+ self . lower_lifetime ( lifetime, RegionInferReason :: ExplicitObjectLifetime )
331
331
} else {
332
332
self . compute_object_lifetime_bound ( span, existential_predicates) . unwrap_or_else ( || {
333
+ // Curiously, we prefer object lifetime default for `+ '_`...
333
334
if tcx. named_bound_var ( lifetime. hir_id ) . is_some ( ) {
334
- self . lower_lifetime ( lifetime, RegionInferReason :: ObjectLifetimeDefault )
335
+ self . lower_lifetime ( lifetime, RegionInferReason :: ExplicitObjectLifetime )
335
336
} 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
+ }
340
350
} else {
341
- RegionInferReason :: BorrowedObjectLifetimeDefault
342
- } ,
343
- )
351
+ RegionInferReason :: ExplicitObjectLifetime
352
+ } ;
353
+ self . re_infer ( span , reason )
344
354
}
345
355
} )
346
356
} ;
0 commit comments