diff options
| author | bors <bors@rust-lang.org> | 2019-06-07 06:52:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-06-07 06:52:09 +0000 |
| commit | ca1bcfdde3f19afd68ef808cecf2ce56d08d5df4 (patch) | |
| tree | 07a0d2ef9340fa064341cc697a8ae58e3762373a /src/libsyntax/mut_visit.rs | |
| parent | c5295ac64a8f2c7aee9cdd13b8fe00b82aff8435 (diff) | |
| parent | 3a31f0634bb1669eae64e83f595942986f867125 (diff) | |
Auto merge of #61541 - petrochenkov:tsp, r=oli-obk
syntax: Keep token span as a part of `Token` In the world with proc macros and edition hygiene `Token` without a span is not self-contained. In practice this means that tokens and spans are always stored and passed somewhere along with each other. This PR combines them into a single struct by doing the next renaming/replacement: - `Token` -> `TokenKind` - `TokenAndSpan` -> `Token` - `(Token, Span)` -> `Token` Some later commits (https://github.com/rust-lang/rust/commit/fb6e2fe8fd6caed247857758c6c3549fe2b59527 and https://github.com/rust-lang/rust/commit/1cdee86940db892cd17239c26add5364335e895a) remove duplicate spans in `token::Ident` and `token::Lifetime`. Those spans were supposed to be identical to token spans, but could easily go out of sync, as was noticed in https://github.com/rust-lang/rust/pull/60965#discussion_r285398523. The `(Token, Span)` -> `Token` change is a soft pre-requisite for this de-duplication since it allows to avoid some larger churn (passing spans to most of functions classifying identifiers).
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. |
