Skip to content

Remove @ast::Region and replace with @ast::Lifetime. #5296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use std::oldmap::HashMap;
use syntax::ast_map;
use syntax::codemap::span;
use syntax::print::pprust;
use syntax::parse::token::special_idents;
use syntax::{ast, visit};

pub type parent = Option<ast::node_id>;
Expand Down Expand Up @@ -546,29 +547,20 @@ pub 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.
fn region_is_relevant(&self, r: @ast::region) -> bool {
match r.node {
ast::re_static => false,
ast::re_anon => self.anon_implies_rp,
ast::re_self => self.self_implies_rp,
ast::re_named(_) => false
}
}

// For named types like Foo, if there is no explicit region
// parameter, then we will add the anonymous region, so there is
// a dependency if the anonymous region implies rp.
//
// If the region is explicitly specified, then we follows the
// normal rules.
fn opt_region_is_relevant(&self,
opt_r: Option<@ast::region>)
-> bool {
debug!("opt_region_is_relevant: %? (anon_implies_rp=%b)",
opt_r, self.anon_implies_rp);
match opt_r {
None => self.anon_implies_rp,
Some(r) => self.region_is_relevant(r)
fn region_is_relevant(&self, r: Option<@ast::Lifetime>) -> bool {
match r {
None => {
self.anon_implies_rp
}
Some(ref l) if l.ident == special_idents::static => {
false
}
Some(ref l) if l.ident == special_idents::self_ => {
self.self_implies_rp
}
Some(_) => {
false
}
}
}

Expand Down Expand Up @@ -672,8 +664,8 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
debug!("referenced fn type: %s",
pprust::ty_to_str(ty, sess.intr()));
match f.region {
Some(r) => {
if cx.region_is_relevant(r) {
Some(_) => {
if cx.region_is_relevant(f.region) {
cx.add_rp(cx.item_id,
cx.add_variance(rv_contravariant))
}
Expand All @@ -699,7 +691,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
match cx.def_map.find(&id) {
Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => {
if did.crate == ast::local_crate {
if cx.opt_region_is_relevant(path.rp) {
if cx.region_is_relevant(path.rp) {
cx.add_dep(did.node);
}
} else {
Expand All @@ -709,7 +701,7 @@ pub 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.opt_region_is_relevant(path.rp) {
if cx.region_is_relevant(path.rp) {
cx.add_rp(cx.item_id, cx.add_variance(variance))
}
}
Expand Down
62 changes: 33 additions & 29 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ use core::result;
use core::vec;
use syntax::ast;
use syntax::codemap::span;
use syntax::print::pprust::{region_to_str, path_to_str};
use syntax::print::pprust::{lifetime_to_str, path_to_str};
use syntax::parse::token::special_idents;
use util::common::indenter;

pub trait AstConv {
Expand All @@ -79,21 +80,16 @@ pub trait AstConv {
pub fn get_region_reporting_err(
tcx: ty::ctxt,
span: span,
a_r: Option<@ast::region>,
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) if a.node == ast::re_anon => {
~"anonymous lifetime"
}
Some(a) => {
fmt!("lifetime %s",
region_to_str(a, tcx.sess.intr()))
}
Some(a) => fmt!("lifetime %s",
lifetime_to_str(a, tcx.sess.intr()))
};
tcx.sess.span_err(
span,
Expand All @@ -105,19 +101,28 @@ pub fn get_region_reporting_err(
}

pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Copy + Durable>(
self: &AC,
rscope: &RS,
span: span,
a_r: @ast::region)
-> ty::Region {
let res = match a_r.node {
ast::re_static => Ok(ty::re_static),
ast::re_anon => rscope.anon_region(span),
ast::re_self => rscope.self_region(span),
ast::re_named(id) => rscope.named_region(span, id)
self: &AC,
rscope: &RS,
default_span: span,
opt_lifetime: Option<@ast::Lifetime>) -> ty::Region
{
let (span, res) = match opt_lifetime {
None => {
(default_span, rscope.anon_region(default_span))
}
Some(ref lifetime) if lifetime.ident == special_idents::static => {
(lifetime.span, Ok(ty::re_static))
}
Some(ref lifetime) if lifetime.ident == special_idents::self_ => {
(lifetime.span, rscope.self_region(lifetime.span))
}
Some(ref lifetime) => {
(lifetime.span, rscope.named_region(lifetime.span,
lifetime.ident))
}
};

get_region_reporting_err(self.tcx(), span, Some(a_r), res)
get_region_reporting_err(self.tcx(), span, opt_lifetime, res)
}

pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
Expand Down Expand Up @@ -156,8 +161,8 @@ pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
let r = get_region_reporting_err(self.tcx(), path.span, None, res);
Some(r)
}
(Some(_), Some(r)) => {
Some(ast_region_to_region(self, rscope, path.span, r))
(Some(_), Some(_)) => {
Some(ast_region_to_region(self, rscope, path.span, path.rp))
}
};

Expand Down Expand Up @@ -504,7 +509,7 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
sigil: ast::Sigil,
purity: ast::purity,
onceness: ast::Onceness,
opt_region: Option<@ast::region>,
opt_lifetime: Option<@ast::Lifetime>,
decl: &ast::fn_decl,
expected_tys: Option<ty::FnSig>,
span: span)
Expand All @@ -514,9 +519,9 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(

// resolve the function bound region in the original region
// scope `rscope`, not the scope of the function parameters
let bound_region = match opt_region {
Some(region) => {
ast_region_to_region(self, rscope, span, region)
let bound_region = match opt_lifetime {
Some(_) => {
ast_region_to_region(self, rscope, span, opt_lifetime)
}
None => {
match sigil {
Expand All @@ -526,9 +531,8 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
ty::re_static
}
ast::BorrowedSigil => {
// &fn() defaults to an anonymous region:
let r_result = rscope.anon_region(span);
get_region_reporting_err(self.tcx(), span, None, r_result)
// &fn() defaults as normal for an omitted lifetime:
ast_region_to_region(self, rscope, span, opt_lifetime)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2950,19 +2950,19 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
// determine the region bound, using the value given by the user
// (if any) and otherwise using a fresh region variable
let self_r = match pth.rp {
Some(r) => {
Some(_) => { // user supplied a lifetime parameter...
match tpt.region_param {
None => {
None => { // ...but the type is not lifetime parameterized!
fcx.ccx.tcx.sess.span_err
(span, ~"this item is not region-parameterized");
None
}
Some(_) => {
Some(ast_region_to_region(fcx, fcx, span, r))
Some(_) => { // ...and the type is lifetime parameterized, ok.
Some(ast_region_to_region(fcx, fcx, span, pth.rp))
}
}
}
None => {
None => { // no lifetime parameter supplied, insert default
fcx.region_var_if_parameterized(
tpt.region_param, span, region_lb)
}
Expand Down
32 changes: 7 additions & 25 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct path {
span: span,
global: bool,
idents: ~[ident],
rp: Option<@region>,
rp: Option<@Lifetime>,
types: ~[@Ty],
}

Expand Down Expand Up @@ -374,10 +374,10 @@ impl ToStr for Sigil {
#[deriving_eq]
pub enum vstore {
// FIXME (#3469): Change uint to @expr (actually only constant exprs)
vstore_fixed(Option<uint>), // [1,2,3,4]
vstore_uniq, // ~[1,2,3,4]
vstore_box, // @[1,2,3,4]
vstore_slice(@region) // &[1,2,3,4](foo)?
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]
}

#[auto_encode]
Expand Down Expand Up @@ -857,24 +857,6 @@ pub enum prim_ty {
ty_bool,
}

#[auto_encode]
#[auto_decode]
#[deriving_eq]
pub struct region {
id: node_id,
node: region_,
}

#[auto_encode]
#[auto_decode]
#[deriving_eq]
pub enum region_ {
re_anon,
re_static,
re_self,
re_named(ident)
}

#[auto_encode]
#[auto_decode]
#[deriving_eq]
Expand Down Expand Up @@ -903,7 +885,7 @@ impl to_bytes::IterBytes for Onceness {
#[deriving_eq]
pub struct TyClosure {
sigil: Sigil,
region: Option<@region>,
region: Option<@Lifetime>,
purity: purity,
onceness: Onceness,
decl: fn_decl
Expand All @@ -929,7 +911,7 @@ pub enum ty_ {
ty_vec(mt),
ty_fixed_length_vec(mt, uint),
ty_ptr(mt),
ty_rptr(@region, mt),
ty_rptr(Option<@Lifetime>, mt),
ty_closure(@TyClosure),
ty_bare_fn(@TyBareFn),
ty_tup(~[@Ty]),
Expand Down
10 changes: 2 additions & 8 deletions src/libsyntax/ext/auto_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,7 @@ fn mk_ser_method(
let ty_s = @ast::Ty {
id: cx.next_id(),
node: ast::ty_rptr(
@ast::region {
id: cx.next_id(),
node: ast::re_anon,
},
None,
ast::mt {
ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]),
mutbl: ast::m_imm
Expand Down Expand Up @@ -658,10 +655,7 @@ fn mk_deser_method(
let ty_d = @ast::Ty {
id: cx.next_id(),
node: ast::ty_rptr(
@ast::region {
id: cx.next_id(),
node: ast::re_anon,
},
None,
ast::mt {
ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]),
mutbl: ast::m_imm
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/ext/deriving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
use ast::{re_anon, stmt, struct_def, struct_variant_kind};
use ast::{stmt, struct_def, struct_variant_kind};
use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, TyParam};
use ast::{TyParamBound, ty_path, ty_rptr, unnamed_field, variant};
use ext::base::ext_ctxt;
Expand Down Expand Up @@ -147,9 +147,8 @@ fn create_eq_method(cx: ext_ctxt,
span,
type_ident,
generics);
let arg_region = @ast::region { id: cx.next_id(), node: re_anon };
let arg_type = ty_rptr(
arg_region,
None,
ast::mt { ty: arg_path_type, mutbl: m_imm }
);
let arg_type = @ast::Ty {
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax/parse/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum ObsoleteSyntax {
ObsoleteRecordType,
ObsoleteRecordPattern,
ObsoleteAssertion,
ObsoletePostFnTySigil,
}

impl to_bytes::IterBytes for ObsoleteSyntax {
Expand Down Expand Up @@ -160,6 +161,11 @@ pub impl Parser {
"assertion",
"use `fail_unless!()` instead"
),
ObsoletePostFnTySigil => (
"fn sigil in postfix position",
"Rather than `fn@`, `fn~`, or `fn&`, \
write `@fn`, `~fn`, and `&fn` respectively"
),
};

self.report(sp, kind, kind_str, desc);
Expand Down
Loading