Convert region parameterization to change defaults and handle

methods correctly
This commit is contained in:
Niko Matsakis 2013-02-26 14:41:23 -05:00
parent 824b9e7dbf
commit d26f6eddfd
3 changed files with 9 additions and 37 deletions

View File

@ -57,7 +57,7 @@ use core::prelude::*;
use middle::ty::{arg, field, substs};
use middle::ty::{ty_param_substs_and_ty};
use middle::ty;
use middle::typeck::rscope::{in_anon_rscope, in_binding_rscope};
use middle::typeck::rscope::{in_binding_rscope};
use middle::typeck::rscope::{region_scope, type_rscope};
use middle::typeck::{CrateCtxt, write_substs_to_tcx, write_ty_to_tcx};
@ -315,8 +315,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
}
ast::ty_rptr(region, mt) => {
let r = ast_region_to_region(self, rscope, ast_ty.span, region);
let anon_rscope = in_anon_rscope(rscope, r);
mk_pointer(self, &anon_rscope, mt, ty::vstore_slice(r),
mk_pointer(self, rscope, mt, ty::vstore_slice(r),
|tmt| ty::mk_rptr(tcx, r, tmt))
}
ast::ty_tup(fields) => {

View File

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
n// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -95,7 +95,7 @@ use middle::typeck::check::vtable::{LocationInfo, VtableContext};
use middle::typeck::CrateCtxt;
use middle::typeck::infer::{resolve_type, force_tvar};
use middle::typeck::infer;
use middle::typeck::rscope::{anon_rscope, binding_rscope, bound_self_region};
use middle::typeck::rscope::{binding_rscope, bound_self_region};
use middle::typeck::rscope::{in_binding_rscope, region_scope, type_rscope};
use middle::typeck::rscope;
use middle::typeck::{isr_alist, lookup_def_ccx, method_map_entry};

View File

@ -27,7 +27,7 @@ pub trait region_scope {
pub enum empty_rscope { empty_rscope }
impl region_scope for empty_rscope {
fn anon_region(&self, _span: span) -> Result<ty::Region, ~str> {
Ok(ty::re_static)
result::Err(~"only the static region is allowed here")
}
fn self_region(&self, _span: span) -> Result<ty::Region, ~str> {
result::Err(~"only the static region is allowed here")
@ -62,14 +62,14 @@ impl region_scope for MethodRscope {
pub enum type_rscope = Option<ty::region_variance>;
impl region_scope for type_rscope {
fn anon_region(&self, _span: span) -> Result<ty::Region, ~str> {
// if the anon or self region is used, region parameterization should
result::Err(~"anonymous region types are not permitted here")
}
fn self_region(&self, _span: span) -> Result<ty::Region, ~str> {
// if the self region is used, region parameterization should
// have inferred that this type is RP
assert self.is_some();
result::Ok(ty::re_bound(ty::br_self))
}
fn self_region(&self, span: span) -> Result<ty::Region, ~str> {
self.anon_region(span)
}
fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, ~str> {
do empty_rscope.named_region(span, id).chain_err |_e| {
@ -87,33 +87,6 @@ pub fn bound_self_region(rp: Option<ty::region_variance>)
}
}
pub struct anon_rscope { anon: ty::Region, base: @region_scope }
pub fn in_anon_rscope<RS:region_scope + Copy + Durable>(
self: &RS,
r: ty::Region) -> anon_rscope
{
let base = @(copy *self) as @region_scope;
anon_rscope {anon: r, base: base}
}
impl region_scope for anon_rscope {
fn anon_region(&self,
_span: span) -> Result<ty::Region, ~str>
{
result::Ok(self.anon)
}
fn self_region(&self,
span: span) -> Result<ty::Region, ~str>
{
self.base.self_region(span)
}
fn named_region(&self,
span: span,
id: ast::ident) -> Result<ty::Region, ~str>
{
self.base.named_region(span, id)
}
}
pub struct binding_rscope {
base: @region_scope,
anon_bindings: @mut uint,