From 62c83bb17be9a47799d702a9470aa7a84012c782 Mon Sep 17 00:00:00 2001 From: James Miller Date: Sat, 6 Jul 2013 00:33:52 +1200 Subject: [PATCH] De-manage Lifetime --- src/librustc/middle/region.rs | 18 +++++++------- src/librustc/middle/typeck/astconv.rs | 32 ++++++++++++------------- src/librustc/middle/typeck/check/mod.rs | 4 ++-- src/libsyntax/ast.rs | 10 ++++---- src/libsyntax/ext/build.rs | 8 +++---- src/libsyntax/ext/deriving/generic.rs | 2 +- src/libsyntax/ext/deriving/ty.rs | 9 ++++--- src/libsyntax/parse/parser.rs | 20 ++++++++-------- src/libsyntax/print/pprust.rs | 20 ++++++++-------- 9 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 69cdbbb897714..a5b64ea426841 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -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) -> 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) } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 1cab6607077d5..b391180bbcdbd 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -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, res: Result) -> 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( this: &AC, rscope: &RS, default_span: span, - opt_lifetime: Option<@ast::Lifetime>) -> ty::Region + opt_lifetime: &Option) -> 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( } (&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 @@ pub fn ast_ty_to_ty( 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 @@ pub fn ast_ty_to_ty( f.purity, f.onceness, bounds, - f.region, + &f.region, &f.decl, None, &f.lifetimes, @@ -647,7 +647,7 @@ fn ty_of_method_or_bare_fn( 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( purity: ast::purity, onceness: ast::Onceness, bounds: ty::BuiltinBounds, - opt_lifetime: Option<@ast::Lifetime>, + opt_lifetime: &Option, decl: &ast::fn_decl, expected_sig: Option, lifetimes: &OptVec, @@ -695,10 +695,10 @@ pub fn ty_of_closure( // 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 diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f595b2dfc6a07..cd66c765a2d6c 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -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, @@ -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)) } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d053c203b91a5..9c3111a691836 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -109,7 +109,7 @@ pub struct Path { span: span, global: bool, idents: ~[ident], - rp: Option<@Lifetime>, + rp: Option, types: ~[@Ty], } @@ -296,7 +296,7 @@ pub enum vstore { vstore_fixed(Option), // [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) // &'foo? [1,2,3,4] } #[deriving(Eq, Encodable, Decodable,IterBytes)] @@ -701,7 +701,7 @@ impl ToStr for Onceness { #[deriving(Eq, Encodable, Decodable,IterBytes)] pub struct TyClosure { sigil: Sigil, - region: Option<@Lifetime>, + region: Option, lifetimes: OptVec, 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, 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, mutability), // `&'lt self` sty_box(mutability), // `@self` sty_uniq // `~self` } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c933caa16c4cc..14ecc26a1c2b1 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -38,7 +38,7 @@ pub trait AstBuilder { fn path_all(&self, sp: span, global: bool, idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, + rp: Option, types: ~[@ast::Ty]) -> ast::Path; @@ -51,7 +51,7 @@ pub trait AstBuilder { fn ty_rptr(&self, span: span, ty: @ast::Ty, - lifetime: Option<@ast::Lifetime>, + lifetime: Option, mutbl: ast::mutability) -> @ast::Ty; fn ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty; @@ -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, types: ~[@ast::Ty]) -> ast::Path { ast::Path { @@ -281,7 +281,7 @@ impl AstBuilder for @ExtCtxt { fn ty_rptr(&self, span: span, ty: @ast::Ty, - lifetime: Option<@ast::Lifetime>, + lifetime: Option, mutbl: ast::mutability) -> @ast::Ty { self.ty(span, diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index e397a41630455..8bd74b96afc1f 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -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`. diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 4dee2e2cdb898..2a60a20b87226 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -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 { 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 @@ 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, @@ -251,8 +251,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) 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) } }); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 00386f611b148..1959649a86544 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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) -> ty_ { /* @@ -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)); } @@ -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(© *self.token) { @@ -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 @@ -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)")); @@ -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 { 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 @@ 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) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 36e9ba4b08a28..d50eb8453d2f0 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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) { 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, opt_sigil: Option, - opt_region: Option<@ast::Lifetime>, + opt_region: &Option, purity: ast::purity, onceness: ast::Onceness, decl: &ast::fn_decl,