Remove the Option<> since when computing LUB since I believe that the

case where `None` was returned should never happen in practice; it
amounts to comparing regions from two unrelated hierarchies. (I was also
not able to make it happen.)
This commit is contained in:
Niko Matsakis 2015-03-05 21:31:42 -05:00
parent a53a22eab9
commit ea5138eba0
2 changed files with 27 additions and 25 deletions

View File

@ -760,15 +760,17 @@ fn lub_concrete_regions(&self, a: Region, b: Region) -> Region {
// at least as big as the block fr.scope_id". So, we can
// reasonably compare free regions and scopes:
let fr_scope = fr.scope.to_code_extent();
match self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) {
let r_id = self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id);
if r_id == fr_scope {
// if the free region's scope `fr.scope_id` is bigger than
// the scope region `s_id`, then the LUB is the free
// region itself:
Some(r_id) if r_id == fr_scope => f,
f
} else {
// otherwise, we don't know what the free region is,
// so we must conservatively say the LUB is static:
_ => ReStatic
ReStatic
}
}
@ -776,10 +778,7 @@ fn lub_concrete_regions(&self, a: Region, b: Region) -> Region {
// The region corresponding to an outer block is a
// subtype of the region corresponding to an inner
// block.
match self.tcx.region_maps.nearest_common_ancestor(a_id, b_id) {
Some(r_id) => ReScope(r_id),
_ => ReStatic
}
ReScope(self.tcx.region_maps.nearest_common_ancestor(a_id, b_id))
}
(ReFree(ref a_fr), ReFree(ref b_fr)) => {
@ -866,9 +865,10 @@ fn glb_concrete_regions(&self,
// is the scope `s_id`. Otherwise, as we do not know
// big the free region is precisely, the GLB is undefined.
let fr_scope = fr.scope.to_code_extent();
match self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) {
Some(r_id) if r_id == fr_scope => Ok(s),
_ => Err(ty::terr_regions_no_overlap(b, a))
if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope {
Ok(s)
} else {
Err(ty::terr_regions_no_overlap(b, a))
}
}
@ -934,10 +934,13 @@ fn intersect_scopes(&self,
// it. Otherwise fail.
debug!("intersect_scopes(scope_a={:?}, scope_b={:?}, region_a={:?}, region_b={:?})",
scope_a, scope_b, region_a, region_b);
match self.tcx.region_maps.nearest_common_ancestor(scope_a, scope_b) {
Some(r_id) if scope_a == r_id => Ok(ReScope(scope_b)),
Some(r_id) if scope_b == r_id => Ok(ReScope(scope_a)),
_ => Err(ty::terr_regions_no_overlap(region_a, region_b))
let r_id = self.tcx.region_maps.nearest_common_ancestor(scope_a, scope_b);
if r_id == scope_a {
Ok(ReScope(scope_b))
} else if r_id == scope_b {
Ok(ReScope(scope_a))
} else {
Err(ty::terr_regions_no_overlap(region_a, region_b))
}
}
}

View File

@ -607,8 +607,8 @@ pub fn is_subregion_of(&self,
pub fn nearest_common_ancestor(&self,
scope_a: CodeExtent,
scope_b: CodeExtent)
-> Option<CodeExtent> {
if scope_a == scope_b { return Some(scope_a); }
-> CodeExtent {
if scope_a == scope_b { return scope_a; }
let a_ancestors = ancestors_of(self, scope_a);
let b_ancestors = ancestors_of(self, scope_b);
@ -636,13 +636,13 @@ pub fn nearest_common_ancestor(&self,
CodeExtent::DestructionScope(b_root_id)) => {
if self.fn_is_enclosed_by(a_root_id, b_root_id) {
// `a` is enclosed by `b`, hence `b` is the ancestor of everything in `a`
Some(scope_b)
scope_b
} else if self.fn_is_enclosed_by(b_root_id, a_root_id) {
// `b` is enclosed by `a`, hence `a` is the ancestor of everything in `b`
Some(scope_a)
scope_a
} else {
// neither fn encloses the other
None
unreachable!()
}
}
_ => {
@ -655,17 +655,16 @@ pub fn nearest_common_ancestor(&self,
loop {
// Loop invariant: a_ancestors[a_index] == b_ancestors[b_index]
// for all indices between a_index and the end of the array
if a_index == 0 { return Some(scope_a); }
if b_index == 0 { return Some(scope_b); }
if a_index == 0 { return scope_a; }
if b_index == 0 { return scope_b; }
a_index -= 1;
b_index -= 1;
if a_ancestors[a_index] != b_ancestors[b_index] {
return Some(a_ancestors[a_index + 1]);
return a_ancestors[a_index + 1];
}
}
fn ancestors_of(this: &RegionMaps, scope: CodeExtent)
-> Vec<CodeExtent> {
fn ancestors_of(this: &RegionMaps, scope: CodeExtent) -> Vec<CodeExtent> {
// debug!("ancestors_of(scope={:?})", scope);
let mut result = vec!(scope);
let mut scope = scope;