Introduce Region::get_name_or_anon
.
For a common pattern.
This commit is contained in:
parent
88fb1b922b
commit
5716ae6982
@ -440,11 +440,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||||||
debug!(?r);
|
debug!(?r);
|
||||||
if !indices.indices.contains_key(&r) {
|
if !indices.indices.contains_key(&r) {
|
||||||
let region_vid = {
|
let region_vid = {
|
||||||
let name = match r.get_name() {
|
let name = r.get_name_or_anon();
|
||||||
Some(name) => name,
|
|
||||||
_ => Symbol::intern("anon"),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.infcx.next_nll_region_var(FR, || {
|
self.infcx.next_nll_region_var(FR, || {
|
||||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||||
})
|
})
|
||||||
@ -478,11 +474,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||||||
debug!(?r);
|
debug!(?r);
|
||||||
if !indices.indices.contains_key(&r) {
|
if !indices.indices.contains_key(&r) {
|
||||||
let region_vid = {
|
let region_vid = {
|
||||||
let name = match r.get_name() {
|
let name = r.get_name_or_anon();
|
||||||
Some(name) => name,
|
|
||||||
_ => Symbol::intern("anon"),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.infcx.next_nll_region_var(FR, || {
|
self.infcx.next_nll_region_var(FR, || {
|
||||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||||
})
|
})
|
||||||
@ -768,15 +760,10 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||||
{
|
{
|
||||||
self.infcx.tcx.fold_regions(value, |region, _depth| {
|
self.infcx.tcx.fold_regions(value, |region, _depth| {
|
||||||
let name = match region.get_name() {
|
let name = region.get_name_or_anon();
|
||||||
Some(name) => name,
|
|
||||||
_ => Symbol::intern("anon"),
|
|
||||||
};
|
|
||||||
debug!(?region, ?name);
|
debug!(?region, ?name);
|
||||||
|
|
||||||
let reg_var = self.next_nll_region_var(origin, || RegionCtxt::Free(name));
|
self.next_nll_region_var(origin, || RegionCtxt::Free(name))
|
||||||
|
|
||||||
reg_var
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -829,11 +816,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||||||
debug!(?r);
|
debug!(?r);
|
||||||
if !indices.indices.contains_key(&r) {
|
if !indices.indices.contains_key(&r) {
|
||||||
let region_vid = {
|
let region_vid = {
|
||||||
let name = match r.get_name() {
|
let name = r.get_name_or_anon();
|
||||||
Some(name) => name,
|
|
||||||
_ => Symbol::intern("anon"),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.next_nll_region_var(FR, || {
|
self.next_nll_region_var(FR, || {
|
||||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||||
})
|
})
|
||||||
@ -855,11 +838,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||||||
debug!(?r);
|
debug!(?r);
|
||||||
if !indices.indices.contains_key(&r) {
|
if !indices.indices.contains_key(&r) {
|
||||||
let region_vid = {
|
let region_vid = {
|
||||||
let name = match r.get_name() {
|
let name = r.get_name_or_anon();
|
||||||
Some(name) => name,
|
|
||||||
_ => Symbol::intern("anon"),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.next_nll_region_var(FR, || {
|
self.next_nll_region_var(FR, || {
|
||||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||||
})
|
})
|
||||||
|
@ -1621,19 +1621,24 @@ impl<'tcx> Region<'tcx> {
|
|||||||
|
|
||||||
pub fn get_name(self) -> Option<Symbol> {
|
pub fn get_name(self) -> Option<Symbol> {
|
||||||
if self.has_name() {
|
if self.has_name() {
|
||||||
let name = match *self {
|
match *self {
|
||||||
ty::ReEarlyBound(ebr) => Some(ebr.name),
|
ty::ReEarlyBound(ebr) => Some(ebr.name),
|
||||||
ty::ReLateBound(_, br) => br.kind.get_name(),
|
ty::ReLateBound(_, br) => br.kind.get_name(),
|
||||||
ty::ReFree(fr) => fr.bound_region.get_name(),
|
ty::ReFree(fr) => fr.bound_region.get_name(),
|
||||||
ty::ReStatic => Some(kw::StaticLifetime),
|
ty::ReStatic => Some(kw::StaticLifetime),
|
||||||
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
|
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
}
|
||||||
|
} else {
|
||||||
return name;
|
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?
|
/// Is this region named by the user?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user