@@ -1057,24 +1057,29 @@ impl<'tcx> TyCtxt<'tcx> {
10571057 }
10581058
10591059 /// Returns the `DefId` and the `BoundRegionKind` corresponding to the given region.
1060- pub fn is_suitable_region ( self , region : Region < ' tcx > ) -> Option < FreeRegionInfo > {
1061- let ( suitable_region_binding_scope, bound_region) = match * region {
1062- ty:: ReFree ( ref free_region) => {
1063- ( free_region. scope . expect_local ( ) , free_region. bound_region )
1060+ pub fn is_suitable_region ( self , mut region : Region < ' tcx > ) -> Option < FreeRegionInfo > {
1061+ let ( suitable_region_binding_scope, bound_region) = loop {
1062+ let def_id = match region. kind ( ) {
1063+ ty:: ReFree ( fr) => fr. bound_region . get_id ( ) ?. as_local ( ) ?,
1064+ ty:: ReEarlyBound ( ebr) => ebr. def_id . expect_local ( ) ,
1065+ _ => return None , // not a free region
1066+ } ;
1067+ let scope = self . local_parent ( def_id) ;
1068+ if self . def_kind ( scope) == DefKind :: OpaqueTy {
1069+ // Lifetime params of opaque types are synthetic and thus irrelevant to
1070+ // diagnostics. Map them back to their origin!
1071+ region = self . map_rpit_lifetime_to_fn_lifetime ( def_id) ;
1072+ continue ;
10641073 }
1065- ty:: ReEarlyBound ( ref ebr) => (
1066- self . local_parent ( ebr. def_id . expect_local ( ) ) ,
1067- ty:: BoundRegionKind :: BrNamed ( ebr. def_id , ebr. name ) ,
1068- ) ,
1069- _ => return None , // not a free region
1074+ break ( scope, ty:: BrNamed ( def_id. into ( ) , self . item_name ( def_id. into ( ) ) ) ) ;
10701075 } ;
10711076
10721077 let is_impl_item = match self . hir ( ) . find_by_def_id ( suitable_region_binding_scope) {
10731078 Some ( Node :: Item ( ..) | Node :: TraitItem ( ..) ) => false ,
10741079 Some ( Node :: ImplItem ( ..) ) => {
10751080 self . is_bound_region_in_impl_item ( suitable_region_binding_scope)
10761081 }
1077- _ => return None ,
1082+ _ => false ,
10781083 } ;
10791084
10801085 Some ( FreeRegionInfo {
0 commit comments