Introduce Region::get_name_or_anon.

For a common pattern.
This commit is contained in:
Nicholas Nethercote
2023-04-11 14:18:30 +10:00
parent 88fb1b922b
commit 5716ae6982
2 changed files with 16 additions and 32 deletions

View File

@@ -1621,19 +1621,24 @@ impl<'tcx> Region<'tcx> {
pub fn get_name(self) -> Option<Symbol> {
if self.has_name() {
let name = match *self {
match *self {
ty::ReEarlyBound(ebr) => Some(ebr.name),
ty::ReLateBound(_, br) => br.kind.get_name(),
ty::ReFree(fr) => fr.bound_region.get_name(),
ty::ReStatic => Some(kw::StaticLifetime),
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
_ => None,
};
return name;
}
} else {
None
}
}
None
pub fn get_name_or_anon(self) -> Symbol {
match self.get_name() {
Some(name) => name,
None => Symbol::intern("anon"),
}
}
/// Is this region named by the user?