Add helper method for reusing an existing interned region
This commit is contained in:
parent
e9b0ce8afa
commit
aa117047f0
@ -326,13 +326,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
opportunistically resolved to {:?}",
|
||||
vid, r
|
||||
);
|
||||
// micro-optimize -- avoid an interner look-up if the vid
|
||||
// hasn't changed.
|
||||
let r = if vid == resolved_vid {
|
||||
r
|
||||
} else {
|
||||
self.tcx.mk_region(ty::ReVar(resolved_vid))
|
||||
};
|
||||
let r = self.tcx.reuse_or_mk_region(r, ty::ReVar(resolved_vid));
|
||||
self.canonicalize_region_mode.canonicalize_free_region(self, r)
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.opportunistic_resolve_var(rid);
|
||||
if resolved == rid { r } else { self.tcx().mk_region(ty::ReVar(resolved)) }
|
||||
self.tcx().reuse_or_mk_region(r, ty::ReVar(resolved))
|
||||
}
|
||||
_ => r,
|
||||
}
|
||||
|
@ -2081,6 +2081,13 @@ pub fn signature_unclosure(
|
||||
})
|
||||
}
|
||||
|
||||
/// Same a `self.mk_region(kind)`, but avoids accessing the interners if
|
||||
/// `*r == kind`.
|
||||
#[inline]
|
||||
pub fn reuse_or_mk_region(self, r: Region<'tcx>, kind: RegionKind) -> Region<'tcx> {
|
||||
if *r == kind { r } else { self.mk_region(kind) }
|
||||
}
|
||||
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
#[inline]
|
||||
pub fn mk_ty(&self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
||||
|
Loading…
Reference in New Issue
Block a user