Skip to content

Make ast::Lifetime contain ast::Name instead of ast::ident #8016

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

Closed
wants to merge 1 commit into from
Closed
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
56 changes: 55 additions & 1 deletion src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,71 @@ fn path_node_global(ids: ~[ast::ident]) -> ast::Path {
}

fn mk_tests(cx: &TestCtxt) -> @ast::item {

use syntax::parse;
let ext_cx = cx.ext_cx;

// The vector of test_descs for this crate
let test_descs = mk_test_descs(cx);

// NOTE: Cannot use lifetimes in quote_item due to stage0 and #7743, revert after a snapshot
let tt = {
pub use syntax::ext::quote::rt::*;
use syntax::parse::token;
let sp = ext_cx.call_site();
let mut t = ~[ tt_tok(sp,
IDENT(ext_cx.ident_of("pub"),
false)),
tt_tok(sp,
IDENT(ext_cx.ident_of("static"),
false)),
tt_tok(sp,
IDENT(ext_cx.ident_of("TESTS"),
false)),
tt_tok(sp,
COLON),
tt_tok(sp,
BINOP(AND)),
tt_tok(sp,
LIFETIME(token::intern("static"))),
tt_tok(sp,
LBRACKET),
tt_tok(sp,
IDENT(ext_cx.ident_of("self"),
true)),
tt_tok(sp,
MOD_SEP),
tt_tok(sp,
IDENT(ext_cx.ident_of("extra"),
true)),
tt_tok(sp,
MOD_SEP),
tt_tok(sp,
IDENT(ext_cx.ident_of("test"),
true)),
tt_tok(sp,
MOD_SEP),
tt_tok(sp,
IDENT(ext_cx.ident_of("TestDescAndFn"),
false)),
tt_tok(sp,
RBRACKET),
tt_tok(sp,
EQ)];
t.push_all_move(test_descs.to_tokens(ext_cx));
t.push(tt_tok(sp, SEMI));
t
};
parse::new_parser_from_tts(ext_cx.parse_sess(),
ext_cx.cfg(),
tt
).parse_item(~[]).get()
/*
(quote_item!(
pub static TESTS : &'static [self::extra::test::TestDescAndFn] =
$test_descs
;
)).get()
*/
}

fn is_extra(cx: &TestCtxt) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use syntax::ast;
use syntax::ast::*;
use syntax::codemap::dummy_sp;
use syntax::opt_vec;
use syntax::parse::token;

// Compact string representation for ty::t values. API ty_str &
// parse_from_str. Extra parameters are for converting to/from def_ids in the
Expand Down Expand Up @@ -226,7 +227,7 @@ fn parse_bound_region(st: &mut PState) -> ty::bound_region {
assert_eq!(next(st), '|');
ty::br_anon(id)
}
'[' => ty::br_named(st.tcx.sess.ident_of(parse_str(st, ']'))),
'[' => ty::br_named(token::intern(parse_str(st, ']'))),
'c' => {
let id = parse_uint(st) as int;
assert_eq!(next(st), '|');
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use syntax::ast;
use syntax::ast::*;
use syntax::diagnostic::span_handler;
use syntax::print::pprust::*;
use syntax::parse::token;

pub struct ctxt {
diag: @span_handler,
Expand Down Expand Up @@ -184,7 +185,7 @@ fn enc_bound_region(w: @io::Writer, cx: @ctxt, br: ty::bound_region) {
}
ty::br_named(s) => {
w.write_char('[');
w.write_str(cx.tcx.sess.str_of(s));
w.write_str(token::interner_get(s));
w.write_char(']')
}
ty::br_cap_avoid(id, br) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,10 @@ impl DetermineRpCtxt {
&None => {
self.anon_implies_rp
}
&Some(ref l) if l.ident == special_idents::statik => {
&Some(ref l) if l.name == special_idents::statik.name => {
false
}
&Some(ref l) if l.ident == special_idents::self_ => {
&Some(ref l) if l.name == special_idents::self_.name => {
true
}
&Some(_) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ pub struct ClosureTy {
* - `output` is the return type. */
#[deriving(Clone, Eq, IterBytes)]
pub struct FnSig {
bound_lifetime_names: OptVec<ast::ident>,
bound_lifetime_names: OptVec<ast::Name>,
inputs: ~[t],
output: t
}
Expand Down Expand Up @@ -471,7 +471,7 @@ pub enum bound_region {
br_anon(uint),

/// Named region parameters for functions (a in &'a T)
br_named(ast::ident),
br_named(ast::Name),

/// Fresh bound identifiers created during GLB computations.
br_fresh(uint),
Expand Down Expand Up @@ -2714,7 +2714,7 @@ impl cmp::TotalOrd for bound_region {
(&ty::br_anon(ref a1), &ty::br_anon(ref a2)) => a1.cmp(a2),
(&ty::br_anon(*), _) => cmp::Less,

(&ty::br_named(ref a1), &ty::br_named(ref a2)) => a1.name.cmp(&a2.name),
(&ty::br_named(ref a1), &ty::br_named(ref a2)) => a1.cmp(a2),
(&ty::br_named(*), _) => cmp::Less,

(&ty::br_cap_avoid(ref a1, @ref b1),
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Clone + 'static>(
&None => {
(default_span, rscope.anon_region(default_span))
}
&Some(ref lifetime) if lifetime.ident == special_idents::statik => {
&Some(ref lifetime) if lifetime.name == special_idents::statik.name => {
(lifetime.span, Ok(ty::re_static))
}
&Some(ref lifetime) if lifetime.ident == special_idents::self_ => {
&Some(ref lifetime) if lifetime.name == special_idents::self_.name => {
(lifetime.span, rscope.self_region(lifetime.span))
}
&Some(ref lifetime) => {
(lifetime.span, rscope.named_region(lifetime.span,
lifetime.ident))
lifetime.name))
}
};

Expand Down Expand Up @@ -539,7 +539,7 @@ pub fn ty_of_arg<AC:AstConv,

pub fn bound_lifetimes<AC:AstConv>(
this: &AC,
ast_lifetimes: &OptVec<ast::Lifetime>) -> OptVec<ast::ident>
ast_lifetimes: &OptVec<ast::Lifetime>) -> OptVec<ast::Name>
{
/*!
*
Expand All @@ -555,13 +555,13 @@ pub fn bound_lifetimes<AC:AstConv>(
let special_idents = [special_idents::statik, special_idents::self_];
let mut bound_lifetime_names = opt_vec::Empty;
ast_lifetimes.map_to_vec(|ast_lifetime| {
if special_idents.iter().any(|&i| i == ast_lifetime.ident) {
if special_idents.iter().any(|&i| i.name == ast_lifetime.name) {
this.tcx().sess.span_err(
ast_lifetime.span,
fmt!("illegal lifetime parameter name: `%s`",
lifetime_to_str(ast_lifetime, this.tcx().sess.intr())));
} else {
bound_lifetime_names.push(ast_lifetime.ident);
bound_lifetime_names.push(ast_lifetime.name);
}
});
bound_lifetime_names
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ impl FnCtxt {
match in_scope_regions.find(br) {
Some(r) => result::Ok(r),
None => {
let blk_br = ty::br_named(special_idents::blk);
let blk_br = ty::br_named(special_idents::blk.name);
if br == blk_br {
result::Ok(self.block_region())
} else {
Expand Down Expand Up @@ -709,7 +709,7 @@ impl region_scope for FnCtxt {
}
fn named_region(&self,
span: span,
id: ast::ident) -> Result<ty::Region, RegionError> {
id: ast::Name) -> Result<ty::Region, RegionError> {
self.search_in_scope_regions(span, ty::br_named(id))
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/librustc/middle/typeck/rscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct RegionError {
pub trait region_scope {
fn anon_region(&self, span: span) -> Result<ty::Region, RegionError>;
fn self_region(&self, span: span) -> Result<ty::Region, RegionError>;
fn named_region(&self, span: span, id: ast::ident)
fn named_region(&self, span: span, id: ast::Name)
-> Result<ty::Region, RegionError>;
}

Expand All @@ -42,24 +42,24 @@ impl region_scope for empty_rscope {
fn self_region(&self, _span: span) -> Result<ty::Region, RegionError> {
self.anon_region(_span)
}
fn named_region(&self, _span: span, _id: ast::ident)
fn named_region(&self, _span: span, _id: ast::Name)
-> Result<ty::Region, RegionError>
{
self.anon_region(_span)
}
}

#[deriving(Clone)]
pub struct RegionParamNames(OptVec<ast::ident>);
pub struct RegionParamNames(OptVec<ast::Name>);

impl RegionParamNames {
fn has_self(&self) -> bool {
self.has_ident(special_idents::self_)
self.has_name(special_idents::self_.name)
}

fn has_ident(&self, ident: ast::ident) -> bool {
fn has_name(&self, name: ast::Name) -> bool {
for region_param_name in self.iter() {
if *region_param_name == ident {
if *region_param_name == name {
return true;
}
}
Expand All @@ -73,11 +73,11 @@ impl RegionParamNames {
match **self {
opt_vec::Empty => {
*self = RegionParamNames(
opt_vec::Vec(new_lifetimes.map(|lt| lt.ident)));
opt_vec::Vec(new_lifetimes.map(|lt| lt.name)));
}
opt_vec::Vec(ref mut existing_lifetimes) => {
for new_lifetime in new_lifetimes.iter() {
existing_lifetimes.push(new_lifetime.ident);
existing_lifetimes.push(new_lifetime.name);
}
}
}
Expand All @@ -103,7 +103,7 @@ impl RegionParamNames {
match generics.lifetimes {
opt_vec::Empty => RegionParamNames(opt_vec::Empty),
opt_vec::Vec(ref lifetimes) => {
RegionParamNames(opt_vec::Vec(lifetimes.map(|lt| lt.ident)))
RegionParamNames(opt_vec::Vec(lifetimes.map(|lt| lt.name)))
}
}
}
Expand All @@ -113,7 +113,7 @@ impl RegionParamNames {
match *lifetimes {
opt_vec::Empty => RegionParamNames::new(),
opt_vec::Vec(ref v) => {
RegionParamNames(opt_vec::Vec(v.map(|lt| lt.ident)))
RegionParamNames(opt_vec::Vec(v.map(|lt| lt.name)))
}
}
}
Expand Down Expand Up @@ -196,9 +196,9 @@ impl region_scope for MethodRscope {
}
result::Ok(ty::re_bound(ty::br_self))
}
fn named_region(&self, span: span, id: ast::ident)
fn named_region(&self, span: span, id: ast::Name)
-> Result<ty::Region, RegionError> {
if !self.region_param_names.has_ident(id) {
if !self.region_param_names.has_name(id) {
return RegionParamNames::undeclared_name(None);
}
do empty_rscope.named_region(span, id).chain_err |_e| {
Expand Down Expand Up @@ -248,7 +248,7 @@ impl region_scope for type_rscope {
}
result::Ok(ty::re_bound(ty::br_self))
}
fn named_region(&self, span: span, id: ast::ident)
fn named_region(&self, span: span, id: ast::Name)
-> Result<ty::Region, RegionError> {
do empty_rscope.named_region(span, id).chain_err |_e| {
result::Err(RegionError {
Expand Down Expand Up @@ -307,11 +307,11 @@ impl region_scope for binding_rscope {
}
fn named_region(&self,
span: span,
id: ast::ident) -> Result<ty::Region, RegionError>
id: ast::Name) -> Result<ty::Region, RegionError>
{
do self.base.named_region(span, id).chain_err |_e| {
let result = ty::re_bound(ty::br_named(id));
if self.region_param_names.has_ident(id) {
if self.region_param_names.has_name(id) {
result::Ok(result)
} else {
RegionParamNames::undeclared_name(Some(result))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn bound_region_to_str(cx: ctxt,
if cx.sess.verbose() { return fmt!("%s%?%s", prefix, br, space_str); }

match br {
br_named(id) => fmt!("%s'%s%s", prefix, cx.sess.str_of(id), space_str),
br_named(id) => fmt!("%s'%s%s", prefix, token::interner_get(id), space_str),
br_self => fmt!("%s'self%s", prefix, space_str),
br_anon(_) => prefix.to_str(),
br_fresh(_) => prefix.to_str(),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub type fn_ident = Option<ident>;
pub struct Lifetime {
id: NodeId,
span: span,
ident: ident
name: Name
}

// a "Path" is essentially Rust's notion of a name;
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub trait AstBuilder {

fn trait_ref(&self, path: ast::Path) -> ast::trait_ref;
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime;
fn lifetime(&self, span: span, name: ast::Name) -> ast::Lifetime;

// statements
fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt;
Expand Down Expand Up @@ -365,8 +365,8 @@ impl AstBuilder for @ExtCtxt {
ast::TraitTyParamBound(self.trait_ref(path))
}

fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime {
ast::Lifetime { id: self.next_id(), span: span, ident: ident }
fn lifetime(&self, span: span, name: ast::Name) -> ast::Lifetime {
ast::Lifetime { id: self.next_id(), span: span, name: name }
}

fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt {
Expand Down
7 changes: 4 additions & 3 deletions src/libsyntax/ext/deriving/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use codemap::{span,respan};
use opt_vec;
use parse::token;

/// The types of pointers
pub enum PtrTy<'self> {
Expand Down Expand Up @@ -111,7 +112,7 @@ pub fn nil_ty() -> Ty<'static> {

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, token::intern(*s))),
None => None
}
}
Expand Down Expand Up @@ -221,7 +222,7 @@ impl<'self> LifetimeBounds<'self> {
self_generics: &Generics)
-> Generics {
let lifetimes = do self.lifetimes.map |lt| {
cx.lifetime(span, cx.ident_of(*lt))
cx.lifetime(span, token::intern(*lt))
};
let ty_params = do self.bounds.map |t| {
match t {
Expand Down Expand Up @@ -249,7 +250,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, token::intern(*s)));
ast::sty_region(lt, mutbl)
}
});
Expand Down
Loading