diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-02-15 08:31:44 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-02-18 09:38:34 +1100 |
| commit | d26bf742db0754893567401e49ae8b016c878a92 (patch) | |
| tree | 891c27d6805a649ded71e355b64abaa1783f391d /src/libsyntax/parse | |
| parent | f47ec2ad5b6887b3d400aee49e2294bd27733d18 (diff) | |
| download | rust-d26bf742db0754893567401e49ae8b016c878a92.tar.gz rust-d26bf742db0754893567401e49ae8b016c878a92.zip | |
Change `Token::interpolated_to_tokenstream()`.
It is currently a method of `Token`, but it only is valid to call if `self` is a `Token::Interpolated`. This commit eliminates the possibility of misuse by changing it to an associated function that takes a `Nonterminal`, which also simplifies the call sites. This requires splitting out a new function, `nonterminal_to_string`.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index ff7f3e0bfae..976eea2bb54 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -508,14 +508,8 @@ impl Token { } } - pub fn interpolated_to_tokenstream(&self, sess: &ParseSess, span: Span) - -> TokenStream - { - let nt = match *self { - Token::Interpolated(ref nt) => nt, - _ => panic!("only works on interpolated tokens"), - }; - + pub fn interpolated_to_tokenstream(sess: &ParseSess, nt: Lrc<(Nonterminal, LazyTokenStream)>, + span: Span) -> TokenStream { // An `Interpolated` token means that we have a `Nonterminal` // which is often a parsed AST item. At this point we now need // to convert the parsed AST to an actual token stream, e.g. @@ -558,7 +552,7 @@ impl Token { let tokens_for_real = nt.1.force(|| { // FIXME(#43081): Avoid this pretty-print + reparse hack - let source = pprust::token_to_string(self); + let source = pprust::nonterminal_to_string(&nt.0); let filename = FileName::macro_expansion_source_code(&source); let (tokens, errors) = parse_stream_from_source_str( filename, source, sess, Some(span)); |
