+ reg_op: |region| {
+ match region {
+ // ignore static regions
+ ty::ReStatic => region,
+ _ => {
+ trace!("checking {:?}", region);
+ for (subst, p) in anon_defn.substs.iter().zip(&generics.params) {
+ if let UnpackedKind::Lifetime(subst) = subst.unpack() {
+ if subst == region {
+ // found it in the substitution list, replace with the
+ // parameter from the existential type
+ let reg = ty::EarlyBoundRegion {
+ def_id: p.def_id,
+ index: p.index,
+ name: p.name,
+ };
+ trace!("replace {:?} with {:?}", region, reg);
+ return self.tcx().global_tcx()
+ .mk_region(ty::ReEarlyBound(reg));
+ }
+ }
+ }
+ trace!("anon_defn: {:#?}", anon_defn);
+ trace!("generics: {:#?}", generics);
+ self.tcx().sess
+ .struct_span_err(
+ span,
+ "non-defining existential type use in defining scope",
+ )
+ .span_label(
+ span,
+ format!(
+ "lifetime `{}` is part of concrete type but not used \
+ in parameter list of existential type",
+ region,
+ ),
+ )
+ .emit();
+ self.tcx().global_tcx().mk_region(ty::ReStatic)
+ }
+ }
+ }
+ })
+ };