diff options
| author | Cedric <cedric.brancourt@gmail.com> | 2019-06-08 10:49:46 +0200 |
|---|---|---|
| committer | Cedric <cedric.brancourt@gmail.com> | 2019-06-08 10:49:46 +0200 |
| commit | 5fb099dc786c1bee7116fecb4965d34ad5e0a4a5 (patch) | |
| tree | 12064e001712a29691980ab7d52284cd3da5bdc5 /src/libsyntax/diagnostics/plugin.rs | |
| parent | c1c60d292e2dd2deff7084208274f9a02f750d43 (diff) | |
| download | rust-5fb099dc786c1bee7116fecb4965d34ad5e0a4a5.tar.gz rust-5fb099dc786c1bee7116fecb4965d34ad5e0a4a5.zip | |
use pattern matching for slices destructuring
Diffstat (limited to 'src/libsyntax/diagnostics/plugin.rs')
| -rw-r--r-- | src/libsyntax/diagnostics/plugin.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 9f01b9b9f9b..b958a760e82 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -33,8 +33,8 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt<'_>, span: Span, token_tree: &[TokenTree]) -> Box<dyn MacResult+'cx> { - let code = match (token_tree.len(), token_tree.get(0)) { - (1, Some(&TokenTree::Token(Token { kind: token::Ident(code, _), .. }))) => code, + let code = match token_tree { + &[TokenTree::Token(Token { kind: token::Ident(code, _), .. })] => code, _ => unreachable!() }; @@ -66,22 +66,15 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>, span: Span, token_tree: &[TokenTree]) -> Box<dyn MacResult+'cx> { - let (code, description) = match ( - token_tree.len(), - token_tree.get(0), - token_tree.get(1), - token_tree.get(2) - ) { - (1, Some(&TokenTree::Token(Token { kind: token::Ident(code, _), .. })), None, None) => { + let (code, description) = match token_tree { + &[TokenTree::Token(Token { kind: token::Ident(code, _), .. })] => { (code, None) }, - (3, Some(&TokenTree::Token(Token { kind: token::Ident(code, _), .. })), - Some(&TokenTree::Token(Token { kind: token::Comma, .. })), - Some(&TokenTree::Token(Token { - kind: token::Literal(token::Lit { symbol, .. }), .. - }))) => { + &[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)) - } + }, _ => unreachable!() }; |
