Skip to content

Commit

Permalink
Hygienize lifetimes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed May 25, 2017
1 parent 8497061 commit 7fdc1fb
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Expand Up @@ -985,7 +985,7 @@ impl<'a> LoweringContext<'a> {
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
hir::Lifetime {
id: self.lower_node_id(l.id),
name: l.name,
name: self.lower_ident(l.ident),
span: l.span,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/def_collector.rs
Expand Up @@ -283,7 +283,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {

fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
self.create_def(def.lifetime.id,
DefPathData::LifetimeDef(def.lifetime.name.as_str()),
DefPathData::LifetimeDef(def.lifetime.ident.name.as_str()),
REGULAR_SPACE);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -162,7 +162,7 @@ impl Lifetime {
}

pub fn is_static(&self) -> bool {
self.name == keywords::StaticLifetime.name()
self.name == "'static"
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -26,7 +26,6 @@ use std::mem::replace;
use syntax::ast;
use syntax::attr;
use syntax::ptr::P;
use syntax::symbol::keywords;
use syntax_pos::Span;
use errors::DiagnosticBuilder;
use util::nodemap::{NodeMap, NodeSet, FxHashSet, FxHashMap, DefIdMap};
Expand Down Expand Up @@ -746,7 +745,7 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics)
match set {
Set1::Empty => Set1::Empty,
Set1::One(name) => {
if name == keywords::StaticLifetime.name() {
if name == "'static" {
Set1::One(Region::Static)
} else {
generics.lifetimes.iter().enumerate().find(|&(_, def)| {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/ast_validation.rs
Expand Up @@ -103,11 +103,11 @@ impl<'a> AstValidator<'a> {

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

visit::walk_lifetime(self, lt)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Expand Up @@ -828,7 +828,7 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String {
if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() {
sig.push('<');
sig.push_str(&generics.lifetimes.iter()
.map(|l| l.lifetime.name.to_string())
.map(|l| l.lifetime.ident.name.to_string())
.collect::<Vec<_>>()
.join(", "));
if !generics.lifetimes.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -37,7 +37,7 @@ use std::u32;
pub struct Lifetime {
pub id: NodeId,
pub span: Span,
pub name: Name
pub ident: Ident,
}

impl fmt::Debug for Lifetime {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostics/plugin.rs
Expand Up @@ -206,7 +206,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
(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(
span,
ecx.ty_ident(span, ecx.ident_of("str")),
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ext/build.rs
Expand Up @@ -76,10 +76,10 @@ pub trait AstBuilder {
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef;
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,
span: Span,
name: ast::Name,
ident: ast::Ident,
attrs: Vec<ast::Attribute>,
bounds: Vec<ast::Lifetime>)
-> ast::LifetimeDef;
Expand Down Expand Up @@ -478,19 +478,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
ast::TraitTyParamBound(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None)
}

fn lifetime(&self, span: Span, name: ast::Name) -> ast::Lifetime {
ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, name: name }
fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime {
ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, ident: ident }
}

fn lifetime_def(&self,
span: Span,
name: ast::Name,
ident: ast::Ident,
attrs: Vec<ast::Attribute>,
bounds: Vec<ast::Lifetime>)
-> ast::LifetimeDef {
ast::LifetimeDef {
attrs: attrs.into(),
lifetime: self.lifetime(span, name),
lifetime: self.lifetime(span, ident),
bounds: bounds
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/fold.rs
Expand Up @@ -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 {
Lifetime {
id: fld.new_id(l.id),
name: l.name,
ident: fld.fold_ident(l.ident),
span: fld.new_span(l.span)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -1958,7 +1958,7 @@ impl<'a> Parser<'a> {
token::Lifetime(ident) => {
let ident_span = self.span;
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")
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Expand Up @@ -2764,7 +2764,7 @@ impl<'a> State<'a> {
lifetime: &ast::Lifetime)
-> io::Result<()>
{
self.print_name(lifetime.name)
self.print_name(lifetime.ident.name)
}

pub fn print_lifetime_bounds(&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/test.rs
Expand Up @@ -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"),
ecx.ident_of("test"),
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]
let static_type = ecx.ty_rptr(sp,
ecx.ty(sp, ast::TyKind::Slice(struct_type)),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/visit.rs
Expand Up @@ -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) {
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) {
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax_ext/deriving/generic/ty.rs
Expand Up @@ -118,14 +118,14 @@ pub fn nil_ty<'r>() -> Ty<'r> {

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).name)),
Some(s) => Some(cx.lifetime(span, Ident::from_str(s))),
None => None,
}
}

fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
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![],
}
}
Expand Down Expand Up @@ -243,11 +243,11 @@ impl<'a> LifetimeBounds<'a> {
-> Generics {
let lifetimes = self.lifetimes
.iter()
.map(|&(ref lt, ref bounds)| {
.map(|&(lt, ref bounds)| {
let bounds = bounds.iter()
.map(|b| cx.lifetime(span, cx.ident_of(*b).name))
.map(|b| cx.lifetime(span, Ident::from_str(b)))
.collect();
cx.lifetime_def(span, cx.ident_of(*lt).name, vec![], bounds)
cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds)
})
.collect();
let ty_params = self.bounds
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn get_explicit_self(cx: &ExtCtxt,
respan(span,
match *ptr {
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)
}
Raw(_) => {
Expand Down
7 changes: 3 additions & 4 deletions src/libsyntax_ext/env.rs
Expand Up @@ -13,7 +13,7 @@
// interface.
//

use syntax::ast;
use syntax::ast::{self, Ident};
use syntax::ext::base::*;
use syntax::ext::base;
use syntax::ext::build::AstBuilder;
Expand All @@ -39,10 +39,9 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
cx.std_path(&["option", "Option", "None"]),
Vec::new(),
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,
cx.ident_of("'static")
.name)),
Ident::from_str("'static"))),
ast::Mutability::Immutable)],
Vec::new()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/format.rs
Expand Up @@ -508,7 +508,7 @@ impl<'a, 'b> Context<'a, 'b> {
let sp = piece_ty.span;
let ty = ecx.ty_rptr(sp,
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);
let slice = ecx.expr_vec_slice(sp, pieces);
// static instead of const to speed up codegen by not requiring this to be inlined
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<'a, 'b> Context<'a, 'b> {

// First, build up the static array which will become our precompiled
// 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,
self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")),
Some(static_lifetime),
Expand Down

0 comments on commit 7fdc1fb

Please sign in to comment.