Skip to content

Commit

Permalink
De-manage Lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
James Miller committed Jul 7, 2013
1 parent cd1b6c8 commit 62c83bb
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 62 deletions.
18 changes: 9 additions & 9 deletions src/librustc/middle/region.rs
Expand Up @@ -651,18 +651,18 @@ impl DetermineRpCtxt {
// 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
}
}
Expand Down Expand Up @@ -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()));

Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
32 changes: 16 additions & 16 deletions src/librustc/middle/typeck/astconv.rs
Expand Up @@ -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(
Expand All @@ -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))
}
Expand Down Expand Up @@ -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))
}
};

Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
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))
Expand All @@ -398,7 +398,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
f.purity,
f.onceness,
bounds,
f.region,
&f.region,
&f.decl,
None,
&f.lifetimes,
Expand Down Expand Up @@ -647,7 +647,7 @@ fn ty_of_method_or_bare_fn<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,
Expand Down Expand Up @@ -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>,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -1738,7 +1738,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
purity,
expected_onceness,
expected_bounds,
None,
&None,
decl,
expected_sig,
&opt_vec::Empty,
Expand Down Expand Up @@ -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))
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ast.rs
Expand Up @@ -109,7 +109,7 @@ pub struct Path {
span: span,
global: bool,
idents: ~[ident],
rp: Option<@Lifetime>,
rp: Option<Lifetime>,
types: ~[@Ty],
}

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -701,7 +701,7 @@ impl ToStr for Onceness {
#[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct TyClosure {
sigil: Sigil,
region: Option<@Lifetime>,
region: Option<Lifetime>,
lifetimes: OptVec<Lifetime>,
purity: purity,
onceness: Onceness,
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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`
}
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/build.rs
Expand Up @@ -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;

Expand All @@ -51,7 +51,7 @@ pub trait AstBuilder {

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;
Expand Down Expand Up @@ -238,7 +238,7 @@ impl AstBuilder for @ExtCtxt {
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 {
Expand Down Expand Up @@ -281,7 +281,7 @@ impl AstBuilder for @ExtCtxt {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/generic.rs
Expand Up @@ -351,7 +351,7 @@ impl<'self> TraitDef<'self> {
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`.
Expand Down
9 changes: 4 additions & 5 deletions src/libsyntax/ext/deriving/ty.rs
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<'self> Ty<'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,
Expand Down Expand Up @@ -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)
}
});
Expand Down
20 changes: 10 additions & 10 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -646,7 +646,7 @@ impl Parser {
// parse a ty_closure type
pub fn parse_ty_closure(&self,
sigil: ast::Sigil,
region: Option<@ast::Lifetime>)
region: Option<ast::Lifetime>)
-> ty_ {
/*
Expand Down Expand Up @@ -985,7 +985,7 @@ impl Parser {
// @'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));
}
Expand All @@ -994,7 +994,7 @@ impl Parser {
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) {
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl Parser {
token::IDENT(sid, _) => {
let span = copy self.span;
self.bump();
Some(@ast::Lifetime {
Some(ast::Lifetime {
id: self.get_id(),
span: *span,
ident: sid
Expand All @@ -1288,7 +1288,7 @@ impl Parser {
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)"));
Expand Down Expand Up @@ -1322,17 +1322,17 @@ impl Parser {
}

/// 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
}
Expand Down Expand Up @@ -3343,14 +3343,14 @@ impl Parser {
} 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)
Expand Down

0 comments on commit 62c83bb

Please sign in to comment.