mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
rustc: Add some simple region checking (no region vars yet)
Amazingly, this causes no test cases to fail!
This commit is contained in:
parent
3e385a80d4
commit
7c27ec72d1
@ -294,9 +294,41 @@ impl unify_methods for infer_ctxt {
|
||||
iter2(as, bs) {|a,b| self.tys(a,b) }
|
||||
}
|
||||
|
||||
fn regions(_a: ty::region, _b: ty::region) -> ures {
|
||||
// FIXME: pcwalton!
|
||||
self.uok()
|
||||
fn regions(a: ty::region, b: ty::region) -> ures {
|
||||
alt (a, b) {
|
||||
(ty::re_var(_), _) | (_, ty::re_var(_)) {
|
||||
self.uok() // FIXME: We need region variables!
|
||||
}
|
||||
(ty::re_inferred, _) | (_, ty::re_inferred) {
|
||||
fail "tried to unify inferred regions"
|
||||
}
|
||||
(ty::re_param(_), ty::re_param(_)) |
|
||||
(ty::re_self, ty::re_self) {
|
||||
if a == b {
|
||||
self.uok()
|
||||
} else {
|
||||
self.uerr(ty::terr_regions_differ(false, a, b))
|
||||
}
|
||||
}
|
||||
(ty::re_param(_), ty::re_block(_)) |
|
||||
(ty::re_self, ty::re_block(_)) {
|
||||
self.uok()
|
||||
}
|
||||
(ty::re_block(_), ty::re_param(_)) |
|
||||
(ty::re_block(_), ty::re_self) {
|
||||
self.uerr(ty::terr_regions_differ(false, a, b))
|
||||
}
|
||||
(ty::re_block(superblock), ty::re_block(subblock)) {
|
||||
// The region corresponding to an outer block is a subtype of the
|
||||
// region corresponding to an inner block.
|
||||
let rm = self.tcx.region_map;
|
||||
if region::scope_contains(rm, subblock, superblock) {
|
||||
self.uok()
|
||||
} else {
|
||||
self.uerr(ty::terr_regions_differ(false, a, b))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn mts(a: ty::mt, b: ty::mt) -> ures {
|
||||
@ -650,4 +682,4 @@ impl resolve_methods for infer_ctxt {
|
||||
some(var_id) { ret self.rerr(var_id); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1682,59 +1682,9 @@ mod unify {
|
||||
}
|
||||
|
||||
fn unify_regions<T:copy>(
|
||||
cx: @uctxt, e_region: region, a_region: region,
|
||||
nxt: fn(region) -> ures<T>) -> ures<T> {
|
||||
let sub = a_region, super = e_region;
|
||||
|
||||
// FIXME: Should have a way of unifying regions that relies on bounds,
|
||||
// not on unification.
|
||||
alt (super, sub) {
|
||||
(ty::re_var(superkey), ty::re_var(subkey)) {
|
||||
ret union_region_sets(cx, subkey, superkey,
|
||||
{|| nxt(sub) });
|
||||
}
|
||||
(ty::re_var(superkey), _) {
|
||||
ret record_region_binding(cx, superkey, sub, nxt);
|
||||
}
|
||||
(_, ty::re_var(subkey)) {
|
||||
ret record_region_binding(cx, subkey, super, nxt);
|
||||
}
|
||||
_ { /* fall through */ }
|
||||
}
|
||||
|
||||
alt (super, sub) {
|
||||
(ty::re_var(_), _) | (_, ty::re_var(_)) {
|
||||
fail "should have been handled above";
|
||||
}
|
||||
(ty::re_inferred, _) | (_, ty::re_inferred) {
|
||||
fail "tried to unify inferred regions";
|
||||
}
|
||||
(ty::re_param(_), ty::re_param(_)) |
|
||||
(ty::re_self, ty::re_self) {
|
||||
ret if super == sub {
|
||||
nxt(ty::re_self)
|
||||
} else {
|
||||
err(terr_regions_differ(false, super, sub))
|
||||
};
|
||||
}
|
||||
(ty::re_param(_), ty::re_block(_)) |
|
||||
(ty::re_self, ty::re_block(_)) {
|
||||
ret nxt(super);
|
||||
}
|
||||
(ty::re_block(_), ty::re_param(_)) |
|
||||
(ty::re_block(_), ty::re_self) {
|
||||
ret err(terr_regions_differ(false, super, sub));
|
||||
}
|
||||
(ty::re_block(superblock), ty::re_block(subblock)) {
|
||||
// Outer regions are subtypes of inner regions. (This is
|
||||
// somewhat surprising!)
|
||||
let rm = cx.tcx.region_map;
|
||||
if region::scope_contains(rm, subblock, superblock) {
|
||||
ret nxt(super);
|
||||
}
|
||||
ret err(terr_regions_differ(false, sub, super));
|
||||
}
|
||||
}
|
||||
_cx: @uctxt, _e_region: region, _a_region: region,
|
||||
_nxt: fn(region) -> ures<T>) -> ures<T> {
|
||||
fail; // unused
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user