use syntax::ext::hygiene::Mark;
use syntax::visit;
use syntax::symbol::{kw, sym};
-use syntax::parse::token::{self, TokenKind};
+use syntax::parse::token::{self, Token};
use syntax_pos::Span;
/// Creates `DefId`s for nodes in the AST.
}
}
- fn visit_token(&mut self, t: TokenKind) {
- if let token::Interpolated(nt) = t {
+ fn visit_token(&mut self, t: Token) {
+ if let token::Interpolated(nt) = t.kind {
if let token::NtExpr(ref expr) = *nt {
if let ExprKind::Mac(..) = expr.node {
self.visit_macro_invoc(expr.id);
use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
use syntax::feature_gate::is_builtin_attr;
-use syntax::parse::token::{self, TokenKind};
+use syntax::parse::token::{self, Token};
use syntax::span_err;
use syntax::std_inject::injected_crate_name;
use syntax::symbol::{kw, sym};
self.resolver.current_module = parent;
}
- fn visit_token(&mut self, t: TokenKind) {
- if let token::Interpolated(nt) = t {
+ fn visit_token(&mut self, t: Token) {
+ if let token::Interpolated(nt) = t.kind {
if let token::NtExpr(ref expr) = *nt {
if let ast::ExprKind::Mac(..) = expr.node {
self.visit_invoc(expr.id);
use crate::ast::*;
use crate::source_map::{Spanned, respan};
-use crate::parse::token::{self, Token, TokenKind};
+use crate::parse::token::{self, Token};
use crate::ptr::P;
use crate::ThinVec;
use crate::tokenstream::*;
noop_visit_tts(tts, self);
}
- fn visit_token(&mut self, t: &mut TokenKind) {
+ fn visit_token(&mut self, t: &mut Token) {
noop_visit_token(t, self);
}
pub fn noop_visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {
match tt {
- TokenTree::Token(Token { kind, span }) => {
- vis.visit_token(kind);
- vis.visit_span(span);
+ TokenTree::Token(token) => {
+ vis.visit_token(token);
}
TokenTree::Delimited(DelimSpan { open, close }, _delim, tts) => {
vis.visit_span(open);
})
}
-// apply ident visitor if it's an ident, apply other visits to interpolated nodes
-pub fn noop_visit_token<T: MutVisitor>(t: &mut TokenKind, vis: &mut T) {
- match t {
+// Apply ident visitor if it's an ident, apply other visits to interpolated nodes.
+// In practice the ident part is not actually used by specific visitors right now,
+// but there's a test below checking that it works.
+pub fn noop_visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
+ let Token { kind, span } = t;
+ match kind {
+ token::Ident(name, _) | token::Lifetime(name) => {
+ let mut ident = Ident::new(*name, *span);
+ vis.visit_ident(&mut ident);
+ *name = ident.name;
+ }
token::Interpolated(nt) => {
let mut nt = Lrc::make_mut(nt);
vis.visit_interpolated(&mut nt);
}
_ => {}
}
+ vis.visit_span(span);
}
/// Apply visitor to elements of interpolated nodes.
//! those that are created by the expansion of a macro.
use crate::ast::*;
-use crate::parse::token::TokenKind;
+use crate::parse::token::Token;
use crate::tokenstream::{TokenTree, TokenStream};
use syntax_pos::Span;
fn visit_tts(&mut self, tts: TokenStream) {
walk_tts(self, tts)
}
- fn visit_token(&mut self, _t: TokenKind) {}
+ fn visit_token(&mut self, _t: Token) {}
// FIXME: add `visit_interpolated` and `walk_interpolated`
fn visit_vis(&mut self, vis: &'ast Visibility) {
walk_vis(self, vis)
pub fn walk_tt<'a, V: Visitor<'a>>(visitor: &mut V, tt: TokenTree) {
match tt {
- TokenTree::Token(token) => visitor.visit_token(token.kind),
+ TokenTree::Token(token) => visitor.visit_token(token),
TokenTree::Delimited(_, _, tts) => visitor.visit_tts(tts),
}
}