diff options
Diffstat (limited to 'src/libsyntax/mut_visit.rs')
| -rw-r--r-- | src/libsyntax/mut_visit.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index fb1a7a680ba..d2a614c4a54 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -576,9 +576,8 @@ pub fn noop_visit_arg<T: MutVisitor>(Arg { id, pat, ty }: &mut Arg, vis: &mut T) pub fn noop_visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) { match tt { - TokenTree::Token(span, tok) => { - vis.visit_span(span); - vis.visit_token(tok); + TokenTree::Token(token) => { + vis.visit_token(token); } TokenTree::Delimited(DelimSpan { open, close }, _delim, tts) => { vis.visit_span(open); @@ -595,17 +594,26 @@ pub fn noop_visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &m }) } -// apply ident visitor if it's an ident, apply other visits to interpolated nodes +// 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) { - match t { - token::Ident(id, _is_raw) => vis.visit_ident(id), - token::Lifetime(id) => vis.visit_ident(id), + 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; + *span = ident.span; + return; // avoid visiting the span for the second time + } 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. |
