Skip to content

Commit ea5138e

Browse files
committed
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.)
1 parent a53a22e commit ea5138e

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

src/librustc/middle/infer/region_inference/mod.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -760,26 +760,25 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
760760
// at least as big as the block fr.scope_id". So, we can
761761
// reasonably compare free regions and scopes:
762762
let fr_scope = fr.scope.to_code_extent();
763-
match self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) {
763+
let r_id = self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id);
764+
765+
if r_id == fr_scope {
764766
// if the free region's scope `fr.scope_id` is bigger than
765767
// the scope region `s_id`, then the LUB is the free
766768
// region itself:
767-
Some(r_id) if r_id == fr_scope => f,
768-
769+
f
770+
} else {
769771
// otherwise, we don't know what the free region is,
770772
// so we must conservatively say the LUB is static:
771-
_ => ReStatic
773+
ReStatic
772774
}
773775
}
774776

775777
(ReScope(a_id), ReScope(b_id)) => {
776778
// The region corresponding to an outer block is a
777779
// subtype of the region corresponding to an inner
778780
// block.
779-
match self.tcx.region_maps.nearest_common_ancestor(a_id, b_id) {
780-
Some(r_id) => ReScope(r_id),
781-
_ => ReStatic
782-
}
781+
ReScope(self.tcx.region_maps.nearest_common_ancestor(a_id, b_id))
783782
}
784783

785784
(ReFree(ref a_fr), ReFree(ref b_fr)) => {
@@ -866,9 +865,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
866865
// is the scope `s_id`. Otherwise, as we do not know
867866
// big the free region is precisely, the GLB is undefined.
868867
let fr_scope = fr.scope.to_code_extent();
869-
match self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) {
870-
Some(r_id) if r_id == fr_scope => Ok(s),
871-
_ => Err(ty::terr_regions_no_overlap(b, a))
868+
if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope {
869+
Ok(s)
870+
} else {
871+
Err(ty::terr_regions_no_overlap(b, a))
872872
}
873873
}
874874

@@ -934,10 +934,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
934934
// it. Otherwise fail.
935935
debug!("intersect_scopes(scope_a={:?}, scope_b={:?}, region_a={:?}, region_b={:?})",
936936
scope_a, scope_b, region_a, region_b);
937-
match self.tcx.region_maps.nearest_common_ancestor(scope_a, scope_b) {
938-
Some(r_id) if scope_a == r_id => Ok(ReScope(scope_b)),
939-
Some(r_id) if scope_b == r_id => Ok(ReScope(scope_a)),
940-
_ => Err(ty::terr_regions_no_overlap(region_a, region_b))
937+
let r_id = self.tcx.region_maps.nearest_common_ancestor(scope_a, scope_b);
938+
if r_id == scope_a {
939+
Ok(ReScope(scope_b))
940+
} else if r_id == scope_b {
941+
Ok(ReScope(scope_a))
942+
} else {
943+
Err(ty::terr_regions_no_overlap(region_a, region_b))
941944
}
942945
}
943946
}

src/librustc/middle/region.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ impl RegionMaps {
607607
pub fn nearest_common_ancestor(&self,
608608
scope_a: CodeExtent,
609609
scope_b: CodeExtent)
610-
-> Option<CodeExtent> {
611-
if scope_a == scope_b { return Some(scope_a); }
610+
-> CodeExtent {
611+
if scope_a == scope_b { return scope_a; }
612612

613613
let a_ancestors = ancestors_of(self, scope_a);
614614
let b_ancestors = ancestors_of(self, scope_b);
@@ -636,13 +636,13 @@ impl RegionMaps {
636636
CodeExtent::DestructionScope(b_root_id)) => {
637637
if self.fn_is_enclosed_by(a_root_id, b_root_id) {
638638
// `a` is enclosed by `b`, hence `b` is the ancestor of everything in `a`
639-
Some(scope_b)
639+
scope_b
640640
} else if self.fn_is_enclosed_by(b_root_id, a_root_id) {
641641
// `b` is enclosed by `a`, hence `a` is the ancestor of everything in `b`
642-
Some(scope_a)
642+
scope_a
643643
} else {
644644
// neither fn encloses the other
645-
None
645+
unreachable!()
646646
}
647647
}
648648
_ => {
@@ -655,17 +655,16 @@ impl RegionMaps {
655655
loop {
656656
// Loop invariant: a_ancestors[a_index] == b_ancestors[b_index]
657657
// for all indices between a_index and the end of the array
658-
if a_index == 0 { return Some(scope_a); }
659-
if b_index == 0 { return Some(scope_b); }
658+
if a_index == 0 { return scope_a; }
659+
if b_index == 0 { return scope_b; }
660660
a_index -= 1;
661661
b_index -= 1;
662662
if a_ancestors[a_index] != b_ancestors[b_index] {
663-
return Some(a_ancestors[a_index + 1]);
663+
return a_ancestors[a_index + 1];
664664
}
665665
}
666666

667-
fn ancestors_of(this: &RegionMaps, scope: CodeExtent)
668-
-> Vec<CodeExtent> {
667+
fn ancestors_of(this: &RegionMaps, scope: CodeExtent) -> Vec<CodeExtent> {
669668
// debug!("ancestors_of(scope={:?})", scope);
670669
let mut result = vec!(scope);
671670
let mut scope = scope;

0 commit comments

Comments
 (0)