Hygienize lifetimes.

This commit is contained in:
Jeffrey Seyfried 2017-03-25 21:14:18 +00:00
parent 8497061a49
commit 7fdc1fb2e4
17 changed files with 31 additions and 33 deletions

View file

@ -985,7 +985,7 @@ impl<'a> LoweringContext<'a> {
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime { fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
hir::Lifetime { hir::Lifetime {
id: self.lower_node_id(l.id), id: self.lower_node_id(l.id),
name: l.name, name: self.lower_ident(l.ident),
span: l.span, span: l.span,
} }
} }

View file

@ -283,7 +283,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) { fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
self.create_def(def.lifetime.id, self.create_def(def.lifetime.id,
DefPathData::LifetimeDef(def.lifetime.name.as_str()), DefPathData::LifetimeDef(def.lifetime.ident.name.as_str()),
REGULAR_SPACE); REGULAR_SPACE);
} }

View file

@ -162,7 +162,7 @@ impl Lifetime {
} }
pub fn is_static(&self) -> bool { pub fn is_static(&self) -> bool {
self.name == keywords::StaticLifetime.name() self.name == "'static"
} }
} }

View file

@ -26,7 +26,6 @@ use std::mem::replace;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::keywords;
use syntax_pos::Span; use syntax_pos::Span;
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;
use util::nodemap::{NodeMap, NodeSet, FxHashSet, FxHashMap, DefIdMap}; use util::nodemap::{NodeMap, NodeSet, FxHashSet, FxHashMap, DefIdMap};
@ -746,7 +745,7 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
match set { match set {
Set1::Empty => Set1::Empty, Set1::Empty => Set1::Empty,
Set1::One(name) => { Set1::One(name) => {
if name == keywords::StaticLifetime.name() { if name == "'static" {
Set1::One(Region::Static) Set1::One(Region::Static)
} else { } else {
generics.lifetimes.iter().enumerate().find(|&(_, def)| { generics.lifetimes.iter().enumerate().find(|&(_, def)| {

View file

@ -103,11 +103,11 @@ impl<'a> AstValidator<'a> {
impl<'a> Visitor<'a> for AstValidator<'a> { impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_lifetime(&mut self, lt: &'a Lifetime) { fn visit_lifetime(&mut self, lt: &'a Lifetime) {
if lt.name == "'_" { if lt.ident.name == "'_" {
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE, self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
lt.id, lt.id,
lt.span, lt.span,
format!("invalid lifetime name `{}`", lt.name)); format!("invalid lifetime name `{}`", lt.ident));
} }
visit::walk_lifetime(self, lt) visit::walk_lifetime(self, lt)

View file

@ -828,7 +828,7 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String {
if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() { if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() {
sig.push('<'); sig.push('<');
sig.push_str(&generics.lifetimes.iter() sig.push_str(&generics.lifetimes.iter()
.map(|l| l.lifetime.name.to_string()) .map(|l| l.lifetime.ident.name.to_string())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ")); .join(", "));
if !generics.lifetimes.is_empty() { if !generics.lifetimes.is_empty() {

View file

@ -37,7 +37,7 @@ use std::u32;
pub struct Lifetime { pub struct Lifetime {
pub id: NodeId, pub id: NodeId,
pub span: Span, pub span: Span,
pub name: Name pub ident: Ident,
} }
impl fmt::Debug for Lifetime { impl fmt::Debug for Lifetime {

View file

@ -206,7 +206,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
(descriptions.len(), ecx.expr_vec(span, descriptions)) (descriptions.len(), ecx.expr_vec(span, descriptions))
}); });
let static_ = ecx.lifetime(span, ecx.name_of("'static")); let static_ = ecx.lifetime(span, Ident::from_str("'static"));
let ty_str = ecx.ty_rptr( let ty_str = ecx.ty_rptr(
span, span,
ecx.ty_ident(span, ecx.ident_of("str")), ecx.ty_ident(span, ecx.ident_of("str")),

View file

@ -76,10 +76,10 @@ pub trait AstBuilder {
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef; fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef;
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound; fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
fn lifetime(&self, span: Span, ident: ast::Name) -> ast::Lifetime; fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime;
fn lifetime_def(&self, fn lifetime_def(&self,
span: Span, span: Span,
name: ast::Name, ident: ast::Ident,
attrs: Vec<ast::Attribute>, attrs: Vec<ast::Attribute>,
bounds: Vec<ast::Lifetime>) bounds: Vec<ast::Lifetime>)
-> ast::LifetimeDef; -> ast::LifetimeDef;
@ -478,19 +478,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
ast::TraitTyParamBound(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None) ast::TraitTyParamBound(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None)
} }
fn lifetime(&self, span: Span, name: ast::Name) -> ast::Lifetime { fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime {
ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, name: name } ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, ident: ident }
} }
fn lifetime_def(&self, fn lifetime_def(&self,
span: Span, span: Span,
name: ast::Name, ident: ast::Ident,
attrs: Vec<ast::Attribute>, attrs: Vec<ast::Attribute>,
bounds: Vec<ast::Lifetime>) bounds: Vec<ast::Lifetime>)
-> ast::LifetimeDef { -> ast::LifetimeDef {
ast::LifetimeDef { ast::LifetimeDef {
attrs: attrs.into(), attrs: attrs.into(),
lifetime: self.lifetime(span, name), lifetime: self.lifetime(span, ident),
bounds: bounds bounds: bounds
} }
} }

View file

@ -694,7 +694,7 @@ pub fn noop_fold_ty_params<T: Folder>(tps: Vec<TyParam>, fld: &mut T) -> Vec<TyP
pub fn noop_fold_lifetime<T: Folder>(l: Lifetime, fld: &mut T) -> Lifetime { pub fn noop_fold_lifetime<T: Folder>(l: Lifetime, fld: &mut T) -> Lifetime {
Lifetime { Lifetime {
id: fld.new_id(l.id), id: fld.new_id(l.id),
name: l.name, ident: fld.fold_ident(l.ident),
span: fld.new_span(l.span) span: fld.new_span(l.span)
} }
} }

View file

@ -1958,7 +1958,7 @@ impl<'a> Parser<'a> {
token::Lifetime(ident) => { token::Lifetime(ident) => {
let ident_span = self.span; let ident_span = self.span;
self.bump(); self.bump();
Lifetime { name: ident.name, span: ident_span, id: ast::DUMMY_NODE_ID } Lifetime { ident: ident, span: ident_span, id: ast::DUMMY_NODE_ID }
} }
_ => self.span_bug(self.span, "not a lifetime") _ => self.span_bug(self.span, "not a lifetime")
} }

View file

@ -2764,7 +2764,7 @@ impl<'a> State<'a> {
lifetime: &ast::Lifetime) lifetime: &ast::Lifetime)
-> io::Result<()> -> io::Result<()>
{ {
self.print_name(lifetime.name) self.print_name(lifetime.ident.name)
} }
pub fn print_lifetime_bounds(&mut self, pub fn print_lifetime_bounds(&mut self,

View file

@ -591,7 +591,7 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
let struct_type = ecx.ty_path(ecx.path(sp, vec![ecx.ident_of("self"), let struct_type = ecx.ty_path(ecx.path(sp, vec![ecx.ident_of("self"),
ecx.ident_of("test"), ecx.ident_of("test"),
ecx.ident_of("TestDescAndFn")])); ecx.ident_of("TestDescAndFn")]));
let static_lt = ecx.lifetime(sp, keywords::StaticLifetime.name()); let static_lt = ecx.lifetime(sp, keywords::StaticLifetime.ident());
// &'static [self::test::TestDescAndFn] // &'static [self::test::TestDescAndFn]
let static_type = ecx.ty_rptr(sp, let static_type = ecx.ty_rptr(sp,
ecx.ty(sp, ast::TyKind::Slice(struct_type)), ecx.ty(sp, ast::TyKind::Slice(struct_type)),

View file

@ -195,7 +195,7 @@ pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) {
} }
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) { pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) {
visitor.visit_name(lifetime.span, lifetime.name); visitor.visit_ident(lifetime.span, lifetime.ident);
} }
pub fn walk_lifetime_def<'a, V: Visitor<'a>>(visitor: &mut V, lifetime_def: &'a LifetimeDef) { pub fn walk_lifetime_def<'a, V: Visitor<'a>>(visitor: &mut V, lifetime_def: &'a LifetimeDef) {

View file

@ -118,14 +118,14 @@ pub fn nil_ty<'r>() -> Ty<'r> {
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 { match *lt {
Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s).name)), Some(s) => Some(cx.lifetime(span, Ident::from_str(s))),
None => None, None => None,
} }
} }
fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> { fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
match *lt { match *lt {
Some(ref s) => vec![cx.lifetime(span, cx.ident_of(*s).name)], Some(s) => vec![cx.lifetime(span, Ident::from_str(s))],
None => vec![], None => vec![],
} }
} }
@ -243,11 +243,11 @@ impl<'a> LifetimeBounds<'a> {
-> Generics { -> Generics {
let lifetimes = self.lifetimes let lifetimes = self.lifetimes
.iter() .iter()
.map(|&(ref lt, ref bounds)| { .map(|&(lt, ref bounds)| {
let bounds = bounds.iter() let bounds = bounds.iter()
.map(|b| cx.lifetime(span, cx.ident_of(*b).name)) .map(|b| cx.lifetime(span, Ident::from_str(b)))
.collect(); .collect();
cx.lifetime_def(span, cx.ident_of(*lt).name, vec![], bounds) cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds)
}) })
.collect(); .collect();
let ty_params = self.bounds let ty_params = self.bounds
@ -277,7 +277,7 @@ pub fn get_explicit_self(cx: &ExtCtxt,
respan(span, respan(span,
match *ptr { match *ptr {
Borrowed(ref lt, mutbl) => { Borrowed(ref lt, mutbl) => {
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name)); let lt = lt.map(|s| cx.lifetime(span, Ident::from_str(s)));
SelfKind::Region(lt, mutbl) SelfKind::Region(lt, mutbl)
} }
Raw(_) => { Raw(_) => {

View file

@ -13,7 +13,7 @@
// interface. // interface.
// //
use syntax::ast; use syntax::ast::{self, Ident};
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::ext::base; use syntax::ext::base;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
@ -39,10 +39,9 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
cx.std_path(&["option", "Option", "None"]), cx.std_path(&["option", "Option", "None"]),
Vec::new(), Vec::new(),
vec![cx.ty_rptr(sp, vec![cx.ty_rptr(sp,
cx.ty_ident(sp, cx.ident_of("str")), cx.ty_ident(sp, Ident::from_str("str")),
Some(cx.lifetime(sp, Some(cx.lifetime(sp,
cx.ident_of("'static") Ident::from_str("'static"))),
.name)),
ast::Mutability::Immutable)], ast::Mutability::Immutable)],
Vec::new())) Vec::new()))
} }

View file

@ -508,7 +508,7 @@ impl<'a, 'b> Context<'a, 'b> {
let sp = piece_ty.span; let sp = piece_ty.span;
let ty = ecx.ty_rptr(sp, let ty = ecx.ty_rptr(sp,
ecx.ty(sp, ast::TyKind::Slice(piece_ty)), ecx.ty(sp, ast::TyKind::Slice(piece_ty)),
Some(ecx.lifetime(sp, keywords::StaticLifetime.name())), Some(ecx.lifetime(sp, keywords::StaticLifetime.ident())),
ast::Mutability::Immutable); ast::Mutability::Immutable);
let slice = ecx.expr_vec_slice(sp, pieces); let slice = ecx.expr_vec_slice(sp, pieces);
// static instead of const to speed up codegen by not requiring this to be inlined // static instead of const to speed up codegen by not requiring this to be inlined
@ -536,7 +536,7 @@ impl<'a, 'b> Context<'a, 'b> {
// First, build up the static array which will become our precompiled // First, build up the static array which will become our precompiled
// format "string" // format "string"
let static_lifetime = self.ecx.lifetime(self.fmtsp, keywords::StaticLifetime.name()); let static_lifetime = self.ecx.lifetime(self.fmtsp, keywords::StaticLifetime.ident());
let piece_ty = self.ecx.ty_rptr(self.fmtsp, let piece_ty = self.ecx.ty_rptr(self.fmtsp,
self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")), self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")),
Some(static_lifetime), Some(static_lifetime),