diff --git a/src/librustc/middle/infer/region_inference/mod.rs b/src/librustc/middle/infer/region_inference/mod.rs index c432d114b6ee..b539dded12e8 100644 --- a/src/librustc/middle/infer/region_inference/mod.rs +++ b/src/librustc/middle/infer/region_inference/mod.rs @@ -760,15 +760,17 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { // 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 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { // 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 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { // 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 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { // 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)) } } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 11627c24f540..b68f8fa9b988 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -607,8 +607,8 @@ impl RegionMaps { pub fn nearest_common_ancestor(&self, scope_a: CodeExtent, scope_b: CodeExtent) - -> Option { - 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 @@ impl RegionMaps { 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 @@ impl RegionMaps { 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 { + fn ancestors_of(this: &RegionMaps, scope: CodeExtent) -> Vec { // debug!("ancestors_of(scope={:?})", scope); let mut result = vec!(scope); let mut scope = scope;