提交 62c83bb1 编写于 作者: J James Miller

De-manage Lifetime

上级 cd1b6c89
......@@ -651,18 +651,18 @@ pub fn add_dep(&mut self, from: ast::node_id) {
// with &self type, &self is also bound. We detect those last two
// cases via flags (anon_implies_rp and self_implies_rp) that are
// true when the anon or self region implies RP.
pub fn region_is_relevant(&self, r: Option<@ast::Lifetime>) -> bool {
pub fn region_is_relevant(&self, r: &Option<ast::Lifetime>) -> bool {
match r {
None => {
&None => {
self.anon_implies_rp
}
Some(ref l) if l.ident == special_idents::statik => {
&Some(ref l) if l.ident == special_idents::statik => {
false
}
Some(ref l) if l.ident == special_idents::self_ => {
&Some(ref l) if l.ident == special_idents::self_ => {
true
}
Some(_) => {
&Some(_) => {
false
}
}
......@@ -747,7 +747,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
// locations)
let sess = cx.sess;
match ty.node {
ast::ty_rptr(r, _) => {
ast::ty_rptr(ref r, _) => {
debug!("referenced rptr type %s",
pprust::ty_to_str(ty, sess.intr()));
......@@ -762,7 +762,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
pprust::ty_to_str(ty, sess.intr()));
match f.region {
Some(_) => {
if cx.region_is_relevant(f.region) {
if cx.region_is_relevant(&f.region) {
let rv = cx.add_variance(rv_contravariant);
cx.add_rp(cx.item_id, rv)
}
......@@ -790,7 +790,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
Some(&ast::def_trait(did)) |
Some(&ast::def_struct(did)) => {
if did.crate == ast::local_crate {
if cx.region_is_relevant(path.rp) {
if cx.region_is_relevant(&path.rp) {
cx.add_dep(did.node);
}
} else {
......@@ -800,7 +800,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
Some(variance) => {
debug!("reference to external, rp'd type %s",
pprust::ty_to_str(ty, sess.intr()));
if cx.region_is_relevant(path.rp) {
if cx.region_is_relevant(&path.rp) {
let rv = cx.add_variance(variance);
cx.add_rp(cx.item_id, rv)
}
......
......@@ -85,15 +85,15 @@ pub trait AstConv {
pub fn get_region_reporting_err(
tcx: ty::ctxt,
span: span,
a_r: Option<@ast::Lifetime>,
a_r: &Option<ast::Lifetime>,
res: Result<ty::Region, RegionError>) -> ty::Region
{
match res {
result::Ok(r) => r,
result::Err(ref e) => {
let descr = match a_r {
None => ~"anonymous lifetime",
Some(a) => fmt!("lifetime %s",
&None => ~"anonymous lifetime",
&Some(ref a) => fmt!("lifetime %s",
lifetime_to_str(a, tcx.sess.intr()))
};
tcx.sess.span_err(
......@@ -109,19 +109,19 @@ pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Copy + 'static>(
this: &AC,
rscope: &RS,
default_span: span,
opt_lifetime: Option<@ast::Lifetime>) -> ty::Region
opt_lifetime: &Option<ast::Lifetime>) -> ty::Region
{
let (span, res) = match opt_lifetime {
None => {
&None => {
(default_span, rscope.anon_region(default_span))
}
Some(ref lifetime) if lifetime.ident == special_idents::statik => {
&Some(ref lifetime) if lifetime.ident == special_idents::statik => {
(lifetime.span, Ok(ty::re_static))
}
Some(ref lifetime) if lifetime.ident == special_idents::self_ => {
&Some(ref lifetime) if lifetime.ident == special_idents::self_ => {
(lifetime.span, rscope.self_region(lifetime.span))
}
Some(ref lifetime) => {
&Some(ref lifetime) => {
(lifetime.span, rscope.named_region(lifetime.span,
lifetime.ident))
}
......@@ -164,11 +164,11 @@ fn ast_path_substs<AC:AstConv,RS:region_scope + Copy + 'static>(
}
(&Some(_), &None) => {
let res = rscope.anon_region(path.span);
let r = get_region_reporting_err(this.tcx(), path.span, None, res);
let r = get_region_reporting_err(this.tcx(), path.span, &None, res);
Some(r)
}
(&Some(_), &Some(_)) => {
Some(ast_region_to_region(this, rscope, path.span, path.rp))
Some(ast_region_to_region(this, rscope, path.span, &path.rp))
}
};
......@@ -371,7 +371,7 @@ fn check_path_args(tcx: ty::ctxt,
ast::ty_ptr(ref mt) => {
ty::mk_ptr(tcx, ast_mt_to_mt(this, rscope, mt))
}
ast::ty_rptr(region, ref mt) => {
ast::ty_rptr(ref region, ref mt) => {
let r = ast_region_to_region(this, rscope, ast_ty.span, region);
mk_pointer(this, rscope, mt, ty::vstore_slice(r),
|tmt| ty::mk_rptr(tcx, r, tmt))
......@@ -398,7 +398,7 @@ fn check_path_args(tcx: ty::ctxt,
f.purity,
f.onceness,
bounds,
f.region,
&f.region,
&f.decl,
None,
&f.lifetimes,
......@@ -647,7 +647,7 @@ fn transform_self_ty<AC:AstConv,RS:region_scope + Copy + 'static>(
ast::sty_value => {
Some(self_info.untransformed_self_ty)
}
ast::sty_region(lifetime, mutability) => {
ast::sty_region(ref lifetime, mutability) => {
let region =
ast_region_to_region(this, rscope,
self_info.explicit_self.span,
......@@ -677,7 +677,7 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + 'static>(
purity: ast::purity,
onceness: ast::Onceness,
bounds: ty::BuiltinBounds,
opt_lifetime: Option<@ast::Lifetime>,
opt_lifetime: &Option<ast::Lifetime>,
decl: &ast::fn_decl,
expected_sig: Option<ty::FnSig>,
lifetimes: &OptVec<ast::Lifetime>,
......@@ -695,10 +695,10 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + 'static>(
// resolve the function bound region in the original region
// scope `rscope`, not the scope of the function parameters
let bound_region = match opt_lifetime {
Some(_) => {
&Some(_) => {
ast_region_to_region(this, rscope, span, opt_lifetime)
}
None => {
&None => {
match sigil {
ast::OwnedSigil | ast::ManagedSigil => {
// @fn(), ~fn() default to static as the bound
......
......@@ -1738,7 +1738,7 @@ fn check_expr_fn(fcx: @mut FnCtxt,
purity,
expected_onceness,
expected_bounds,
None,
&None,
decl,
expected_sig,
&opt_vec::Empty,
......@@ -3310,7 +3310,7 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
None
}
Some(_) => { // ...and the type is lifetime parameterized, ok.
Some(ast_region_to_region(fcx, fcx, span, pth.rp))
Some(ast_region_to_region(fcx, fcx, span, &pth.rp))
}
}
}
......
......@@ -109,7 +109,7 @@ pub struct Path {
span: span,
global: bool,
idents: ~[ident],
rp: Option<@Lifetime>,
rp: Option<Lifetime>,
types: ~[@Ty],
}
......@@ -296,7 +296,7 @@ pub enum vstore {
vstore_fixed(Option<uint>), // [1,2,3,4]
vstore_uniq, // ~[1,2,3,4]
vstore_box, // @[1,2,3,4]
vstore_slice(Option<@Lifetime>) // &'foo? [1,2,3,4]
vstore_slice(Option<Lifetime>) // &'foo? [1,2,3,4]
}
#[deriving(Eq, Encodable, Decodable,IterBytes)]
......@@ -701,7 +701,7 @@ fn to_str(&self) -> ~str {
#[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct TyClosure {
sigil: Sigil,
region: Option<@Lifetime>,
region: Option<Lifetime>,
lifetimes: OptVec<Lifetime>,
purity: purity,
onceness: Onceness,
......@@ -730,7 +730,7 @@ pub enum ty_ {
ty_vec(mt),
ty_fixed_length_vec(mt, @expr),
ty_ptr(mt),
ty_rptr(Option<@Lifetime>, mt),
ty_rptr(Option<Lifetime>, mt),
ty_closure(@TyClosure),
ty_bare_fn(@TyBareFn),
ty_tup(~[@Ty]),
......@@ -803,7 +803,7 @@ pub enum ret_style {
pub enum explicit_self_ {
sty_static, // no self
sty_value, // `self`
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
sty_region(Option<Lifetime>, mutability), // `&'lt self`
sty_box(mutability), // `@self`
sty_uniq // `~self`
}
......
......@@ -38,7 +38,7 @@ pub trait AstBuilder {
fn path_all(&self, sp: span,
global: bool,
idents: ~[ast::ident],
rp: Option<@ast::Lifetime>,
rp: Option<ast::Lifetime>,
types: ~[@ast::Ty])
-> ast::Path;
......@@ -51,7 +51,7 @@ fn path_all(&self, sp: span,
fn ty_rptr(&self, span: span,
ty: @ast::Ty,
lifetime: Option<@ast::Lifetime>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::mutability)
-> @ast::Ty;
fn ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty;
......@@ -238,7 +238,7 @@ fn path_global(&self, span: span, strs: ~[ast::ident]) -> ast::Path {
fn path_all(&self, sp: span,
global: bool,
idents: ~[ast::ident],
rp: Option<@ast::Lifetime>,
rp: Option<ast::Lifetime>,
types: ~[@ast::Ty])
-> ast::Path {
ast::Path {
......@@ -281,7 +281,7 @@ fn ty_ident(&self, span: span, ident: ast::ident)
fn ty_rptr(&self,
span: span,
ty: @ast::Ty,
lifetime: Option<@ast::Lifetime>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::mutability)
-> @ast::Ty {
self.ty(span,
......
......@@ -351,7 +351,7 @@ fn create_derived_impl(&self, cx: @ExtCtxt, span: span,
let self_lifetime = if generics.lifetimes.is_empty() {
None
} else {
Some(@*generics.lifetimes.get(0))
Some(*generics.lifetimes.get(0))
};
// Create the type of `self`.
......
......@@ -110,9 +110,9 @@ pub fn nil_ty() -> Ty<'static> {
Tuple(~[])
}
fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> {
fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<ast::Lifetime> {
match *lt {
Some(ref s) => Some(@cx.lifetime(span, cx.ident_of(*s))),
Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s))),
None => None
}
}
......@@ -171,7 +171,7 @@ pub fn to_path(&self,
let lifetime = if self_generics.lifetimes.is_empty() {
None
} else {
Some(@*self_generics.lifetimes.get(0))
Some(*self_generics.lifetimes.get(0))
};
cx.path_all(span, false, ~[self_ty], lifetime,
......@@ -251,8 +251,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
Send => ast::sty_uniq,
Managed(mutbl) => ast::sty_box(mutbl),
Borrowed(ref lt, mutbl) => {
let lt = lt.map(|s| @cx.lifetime(span,
cx.ident_of(*s)));
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(*s)));
ast::sty_region(lt, mutbl)
}
});
......
......@@ -646,7 +646,7 @@ pub fn parse_ty_bare_fn(&self) -> ty_ {
// parse a ty_closure type
pub fn parse_ty_closure(&self,
sigil: ast::Sigil,
region: Option<@ast::Lifetime>)
region: Option<ast::Lifetime>)
-> ty_ {
/*
......@@ -985,7 +985,7 @@ pub fn parse_box_or_uniq_pointee(&self,
// @'foo fn() or @foo/fn() or @fn() are parsed directly as fn types:
match *self.token {
token::LIFETIME(*) => {
let lifetime = @self.parse_lifetime();
let lifetime = self.parse_lifetime();
self.bump();
return self.parse_ty_closure(sigil, Some(lifetime));
}
......@@ -994,7 +994,7 @@ pub fn parse_box_or_uniq_pointee(&self,
if self.look_ahead(1u) == token::BINOP(token::SLASH) &&
self.token_is_closure_keyword(&self.look_ahead(2u))
{
let lifetime = @self.parse_lifetime();
let lifetime = self.parse_lifetime();
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
return self.parse_ty_closure(sigil, Some(lifetime));
} else if self.token_is_closure_keyword(&copy *self.token) {
......@@ -1263,7 +1263,7 @@ pub fn parse_bounded_path_with_tps(&self, colons: bool,
token::IDENT(sid, _) => {
let span = copy self.span;
self.bump();
Some(@ast::Lifetime {
Some(ast::Lifetime {
id: self.get_id(),
span: *span,
ident: sid
......@@ -1288,7 +1288,7 @@ pub fn parse_bounded_path_with_tps(&self, colons: bool,
if v.len() == 0 {
None
} else if v.len() == 1 {
Some(@*v.get(0))
Some(*v.get(0))
} else {
self.fatal(fmt!("Expected at most one \
lifetime name (for now)"));
......@@ -1322,17 +1322,17 @@ pub fn parse_type_path(&self) -> (ast::Path, Option<OptVec<TyParamBound>>) {
}
/// parses 0 or 1 lifetime
pub fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> {
pub fn parse_opt_lifetime(&self) -> Option<ast::Lifetime> {
match *self.token {
token::LIFETIME(*) => {
Some(@self.parse_lifetime())
Some(self.parse_lifetime())
}
// Also accept the (obsolete) syntax `foo/`
token::IDENT(*) => {
if self.look_ahead(1u) == token::BINOP(token::SLASH) {
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
Some(@self.parse_lifetime())
Some(self.parse_lifetime())
} else {
None
}
......@@ -3343,14 +3343,14 @@ fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
} else if (this.token_is_lifetime(&this.look_ahead(1)) &&
token::is_keyword(keywords::Self, &this.look_ahead(2))) {
this.bump();
let lifetime = @this.parse_lifetime();
let lifetime = this.parse_lifetime();
this.expect_self_ident();
sty_region(Some(lifetime), m_imm)
} else if (this.token_is_lifetime(&this.look_ahead(1)) &&
this.token_is_mutability(&this.look_ahead(2)) &&
token::is_keyword(keywords::Self, &this.look_ahead(3))) {
this.bump();
let lifetime = @this.parse_lifetime();
let lifetime = this.parse_lifetime();
let mutability = this.parse_mutability();
this.expect_self_ident();
sty_region(Some(lifetime), mutability)
......
......@@ -366,9 +366,9 @@ pub fn print_foreign_mod(s: @ps, nmod: &ast::foreign_mod,
for nmod.items.iter().advance |item| { print_foreign_item(s, *item); }
}
pub fn print_opt_lifetime(s: @ps, lifetime: Option<@ast::Lifetime>) {
pub fn print_opt_lifetime(s: @ps, lifetime: &Option<ast::Lifetime>) {
for lifetime.iter().advance |l| {
print_lifetime(s, *l);
print_lifetime(s, l);
nbsp(s);
}
}
......@@ -392,7 +392,7 @@ pub fn print_type(s: @ps, ty: @ast::Ty) {
word(s.s, "]");
}
ast::ty_ptr(ref mt) => { word(s.s, "*"); print_mt(s, mt); }
ast::ty_rptr(lifetime, ref mt) => {
ast::ty_rptr(ref lifetime, ref mt) => {
word(s.s, "&");
print_opt_lifetime(s, lifetime);
print_mt(s, mt);
......@@ -408,14 +408,14 @@ pub fn print_type(s: @ps, ty: @ast::Ty) {
ast::ty_bare_fn(f) => {
let generics = ast::Generics {lifetimes: copy f.lifetimes,
ty_params: opt_vec::Empty};
print_ty_fn(s, Some(f.abis), None, None,
print_ty_fn(s, Some(f.abis), None, &None,
f.purity, ast::Many, &f.decl, None, &None,
Some(&generics), None);
}
ast::ty_closure(f) => {
let generics = ast::Generics {lifetimes: copy f.lifetimes,
ty_params: opt_vec::Empty};
print_ty_fn(s, None, Some(f.sigil), f.region,
print_ty_fn(s, None, Some(f.sigil), &f.region,
f.purity, f.onceness, &f.decl, None, &f.bounds,
Some(&generics), None);
}
......@@ -804,7 +804,7 @@ pub fn print_ty_method(s: @ps, m: &ast::ty_method) {
hardbreak_if_not_bol(s);
maybe_print_comment(s, m.span.lo);
print_outer_attributes(s, m.attrs);
print_ty_fn(s, None, None, None, m.purity, ast::Many,
print_ty_fn(s, None, None, &None, m.purity, ast::Many,
&m.decl, Some(m.ident), &None, Some(&m.generics),
Some(/*bad*/ copy m.explicit_self.node));
word(s.s, ";");
......@@ -1021,7 +1021,7 @@ pub fn print_vstore(s: @ps, t: ast::vstore) {
ast::vstore_fixed(None) => word(s.s, "_"),
ast::vstore_uniq => word(s.s, "~"),
ast::vstore_box => word(s.s, "@"),
ast::vstore_slice(r) => {
ast::vstore_slice(ref r) => {
word(s.s, "&");
print_opt_lifetime(s, r);
}
......@@ -1505,7 +1505,7 @@ fn print_path_(s: @ps, path: &ast::Path, colons_before_params: bool,
word(s.s, "<");
for path.rp.iter().advance |r| {
print_lifetime(s, *r);
print_lifetime(s, r);
if !path.types.is_empty() {
word_space(s, ",");
}
......@@ -1653,7 +1653,7 @@ pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
ast::sty_static => { return false; }
ast::sty_value => { word(s.s, "self"); }
ast::sty_uniq => { word(s.s, "~self"); }
ast::sty_region(lt, m) => {
ast::sty_region(ref lt, m) => {
word(s.s, "&");
print_opt_lifetime(s, lt);
print_mutability(s, m);
......@@ -1912,7 +1912,7 @@ pub fn print_arg(s: @ps, input: ast::arg) {
pub fn print_ty_fn(s: @ps,
opt_abis: Option<AbiSet>,
opt_sigil: Option<ast::Sigil>,
opt_region: Option<@ast::Lifetime>,
opt_region: &Option<ast::Lifetime>,
purity: ast::purity,
onceness: ast::Onceness,
decl: &ast::fn_decl,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册