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