diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-08-31 20:08:06 +0300 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-09-03 21:15:45 +0300 |
| commit | fa893a322570ea60cc8815b3dddb5311f0cb3b63 (patch) | |
| tree | e693cfd3e9ad5b53aba23bcfe17725afa749aa48 /src/libsyntax/diagnostics | |
| parent | b3146549abf25818fecfc7555f35358a948e27ad (diff) | |
| download | rust-fa893a322570ea60cc8815b3dddb5311f0cb3b63.tar.gz rust-fa893a322570ea60cc8815b3dddb5311f0cb3b63.zip | |
use TokenStream rather than &[TokenTree] for built-in macros
That way, we don't loose the jointness info
Diffstat (limited to 'src/libsyntax/diagnostics')
| -rw-r--r-- | src/libsyntax/diagnostics/plugin.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index e9a55af52e8..5de39c8d14d 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -6,7 +6,7 @@ use crate::ext::base::{ExtCtxt, MacEager, MacResult}; use crate::parse::token::{self, Token}; use crate::ptr::P; use crate::symbol::kw; -use crate::tokenstream::{TokenTree}; +use crate::tokenstream::{TokenTree, TokenStream}; use smallvec::smallvec; use syntax_pos::Span; @@ -27,12 +27,11 @@ pub type ErrorMap = BTreeMap<Name, ErrorInfo>; pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt<'_>, span: Span, - token_tree: &[TokenTree]) + tts: TokenStream) -> Box<dyn MacResult+'cx> { - let code = match token_tree { - [ - TokenTree::Token(Token { kind: token::Ident(code, _), .. }) - ] => code, + assert_eq!(tts.len(), 1); + let code = match tts.into_trees().next() { + Some(TokenTree::Token(Token { kind: token::Ident(code, _), .. })) => code, _ => unreachable!() }; @@ -62,20 +61,21 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt<'_>, pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>, span: Span, - token_tree: &[TokenTree]) + tts: TokenStream) -> Box<dyn MacResult+'cx> { - let (code, description) = match token_tree { - [ - TokenTree::Token(Token { kind: token::Ident(code, _), .. }) - ] => { - (*code, None) - }, - [ - TokenTree::Token(Token { kind: token::Ident(code, _), .. }), - TokenTree::Token(Token { kind: token::Comma, .. }), - TokenTree::Token(Token { kind: token::Literal(token::Lit { symbol, .. }), ..}) - ] => { - (*code, Some(*symbol)) + assert!(tts.len() == 1 || tts.len() == 3); + let mut cursor = tts.into_trees(); + let code = match cursor.next() { + Some(TokenTree::Token(Token { kind: token::Ident(code, _), .. })) => code, + _ => unreachable!() + }; + let description = match (cursor.next(), cursor.next()) { + (None, None) => None, + ( + Some(TokenTree::Token(Token { kind: token::Comma, .. })), + Some(TokenTree::Token(Token { kind: token::Literal(token::Lit { symbol, .. }), ..})) + ) => { + Some(symbol) }, _ => unreachable!() }; @@ -121,12 +121,12 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>, pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt<'_>, span: Span, - token_tree: &[TokenTree]) + tts: TokenStream) -> Box<dyn MacResult+'cx> { - assert_eq!(token_tree.len(), 3); - let ident = match &token_tree[2] { + assert_eq!(tts.len(), 3); + let ident = match tts.into_trees().nth(2) { // DIAGNOSTICS ident. - &TokenTree::Token(Token { kind: token::Ident(name, _), span }) + Some(TokenTree::Token(Token { kind: token::Ident(name, _), span })) => Ident::new(name, span), _ => unreachable!() }; |
