@@ -320,6 +320,21 @@ impl<'tcx> Region<'tcx> {
320320 _ => bug ! ( "expected region {:?} to be of kind ReVar" , self ) ,
321321 }
322322 }
323+
324+ /// Given some item `binding_item`, check if this region is a generic parameter introduced by it
325+ /// or one of the parent generics. Returns the `DefId` of the parameter definition if so.
326+ pub fn opt_param_def_id ( self , tcx : TyCtxt < ' tcx > , binding_item : DefId ) -> Option < DefId > {
327+ match self . kind ( ) {
328+ ty:: ReEarlyParam ( ebr) => {
329+ Some ( tcx. generics_of ( binding_item) . region_param ( ebr, tcx) . def_id )
330+ }
331+ ty:: ReLateParam ( ty:: LateParamRegion {
332+ bound_region : ty:: BoundRegionKind :: BrNamed ( def_id, _) ,
333+ ..
334+ } ) => Some ( def_id) ,
335+ _ => None ,
336+ }
337+ }
323338}
324339
325340impl < ' tcx > Deref for Region < ' tcx > {
@@ -334,16 +349,13 @@ impl<'tcx> Deref for Region<'tcx> {
334349#[ derive( Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
335350#[ derive( HashStable ) ]
336351pub struct EarlyParamRegion {
337- pub def_id : DefId ,
338352 pub index : u32 ,
339353 pub name : Symbol ,
340354}
341355
342356impl std:: fmt:: Debug for EarlyParamRegion {
343357 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
344- // FIXME(BoxyUwU): self.def_id goes first because of `erased-regions-in-hidden-ty.rs` being impossible to write
345- // error annotations for otherwise. :). Ideally this would be `self.name, self.index, self.def_id`.
346- write ! ( f, "{:?}_{}/#{}" , self . def_id, self . name, self . index)
358+ write ! ( f, "{}/#{}" , self . name, self . index)
347359 }
348360}
349361
0 commit comments