diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-12 04:22:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-12 04:22:50 +0200 |
| commit | 9f22708ceda552784a42253523335533423f2b95 (patch) | |
| tree | 06da68ad78df47d86d27bbbd21dc45383fb57971 /src | |
| parent | 6933034a40aadc0e04a594789e7ad4b2034e9b17 (diff) | |
| parent | 0a4504d400805b2d102a433af98cc33f185fdcf2 (diff) | |
| download | rust-9f22708ceda552784a42253523335533423f2b95.tar.gz rust-9f22708ceda552784a42253523335533423f2b95.zip | |
Rollup merge of #61654 - Electron-libre:use_slice_patterns_in_rustc, r=oli-obk,Centril
use pattern matching for slices destructuring refs #61542 Use slices pattern where it seems to make sense .
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/diagnostics/plugin.rs | 33 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 64 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/ord.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/partial_eq.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/partial_ord.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/hash.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/trace_macros.rs | 6 |
7 files changed, 56 insertions, 67 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 9f01b9b9f9b..98351048c35 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -33,8 +33,10 @@ 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 +68,19 @@ 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) => { - (code, None) + 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)) }, - (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, .. }), .. - }))) => { - (code, Some(symbol)) - } _ => unreachable!() }; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index cde35681988..dd96c63ab0e 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -424,48 +424,38 @@ mod tests { string_to_stream("macro_rules! zip (($a)=>($a))".to_string()).trees().collect(); let tts: &[TokenTree] = &tts[..]; - match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) { - ( - 4, - Some(&TokenTree::Token(Token { - kind: token::Ident(name_macro_rules, false), .. - })), - Some(&TokenTree::Token(Token { kind: token::Not, .. })), - Some(&TokenTree::Token(Token { kind: token::Ident(name_zip, false), .. })), - Some(&TokenTree::Delimited(_, macro_delim, ref macro_tts)), - ) - if name_macro_rules == sym::macro_rules && name_zip.as_str() == "zip" => { + match tts { + [ + TokenTree::Token(Token { kind: token::Ident(name_macro_rules, false), .. }), + TokenTree::Token(Token { kind: token::Not, .. }), + TokenTree::Token(Token { kind: token::Ident(name_zip, false), .. }), + TokenTree::Delimited(_, macro_delim, macro_tts) + ] + if name_macro_rules == &sym::macro_rules && name_zip.as_str() == "zip" => { let tts = ¯o_tts.trees().collect::<Vec<_>>(); - match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) { - ( - 3, - Some(&TokenTree::Delimited(_, first_delim, ref first_tts)), - Some(&TokenTree::Token(Token { kind: token::FatArrow, .. })), - Some(&TokenTree::Delimited(_, second_delim, ref second_tts)), - ) - if macro_delim == token::Paren => { + match &tts[..] { + [ + TokenTree::Delimited(_, first_delim, first_tts), + TokenTree::Token(Token { kind: token::FatArrow, .. }), + TokenTree::Delimited(_, second_delim, second_tts), + ] + if macro_delim == &token::Paren => { let tts = &first_tts.trees().collect::<Vec<_>>(); - match (tts.len(), tts.get(0), tts.get(1)) { - ( - 2, - Some(&TokenTree::Token(Token { kind: token::Dollar, .. })), - Some(&TokenTree::Token(Token { - kind: token::Ident(name, false), .. - })), - ) - if first_delim == token::Paren && name.as_str() == "a" => {}, + match &tts[..] { + [ + TokenTree::Token(Token { kind: token::Dollar, .. }), + TokenTree::Token(Token { kind: token::Ident(name, false), .. }), + ] + if first_delim == &token::Paren && name.as_str() == "a" => {}, _ => panic!("value 3: {:?} {:?}", first_delim, first_tts), } let tts = &second_tts.trees().collect::<Vec<_>>(); - match (tts.len(), tts.get(0), tts.get(1)) { - ( - 2, - Some(&TokenTree::Token(Token { kind: token::Dollar, .. })), - Some(&TokenTree::Token(Token { - kind: token::Ident(name, false), .. - })), - ) - if second_delim == token::Paren && name.as_str() == "a" => {}, + match &tts[..] { + [ + TokenTree::Token(Token { kind: token::Dollar, .. }), + TokenTree::Token(Token { kind: token::Ident(name, false), .. }), + ] + if second_delim == &token::Paren && name.as_str() == "a" => {}, _ => panic!("value 4: {:?} {:?}", second_delim, second_tts), } }, diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index b25a9e4c50f..844865d57c7 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -82,8 +82,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P< // } let new = { - let other_f = match (other_fs.len(), other_fs.get(0)) { - (1, Some(o_f)) => o_f, + let other_f = match other_fs { + [o_f] => o_f, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`"), }; diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 6172f27261e..732bb234389 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -25,8 +25,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, -> P<Expr> { let op = |cx: &mut ExtCtxt<'_>, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| { - let other_f = match (other_fs.len(), other_fs.get(0)) { - (1, Some(o_f)) => o_f, + let other_f = match other_fs { + [o_f] => o_f, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`"), }; diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 3980741f252..a30a7d78222 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -143,8 +143,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_ // } let new = { - let other_f = match (other_fs.len(), other_fs.get(0)) { - (1, Some(o_f)) => o_f, + let other_f = match other_fs { + [o_f] => o_f, _ => { cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`") @@ -193,8 +193,8 @@ fn cs_op(less: bool, }; let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| { - let other_f = match (other_fs.len(), other_fs.get(0)) { - (1, Some(o_f)) => o_f, + let other_f = match other_fs { + [o_f] => o_f, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), }; diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs index e7f99d45782..7ad04aebf6e 100644 --- a/src/libsyntax_ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -52,8 +52,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>, } fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P<Expr> { - let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) { - (1, Some(o_f)) => o_f, + let state_expr = match &substr.nonself_args { + &[o_f] => o_f, _ => { cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`") diff --git a/src/libsyntax_ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs index 6c74f77ff1f..512513e9b41 100644 --- a/src/libsyntax_ext/trace_macros.rs +++ b/src/libsyntax_ext/trace_macros.rs @@ -16,11 +16,11 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>, feature_gate::EXPLAIN_TRACE_MACROS); } - match (tt.len(), tt.first()) { - (1, Some(TokenTree::Token(token))) if token.is_keyword(kw::True) => { + match tt { + [TokenTree::Token(token)] if token.is_keyword(kw::True) => { cx.set_trace_macros(true); } - (1, Some(TokenTree::Token(token))) if token.is_keyword(kw::False) => { + [TokenTree::Token(token)] if token.is_keyword(kw::False) => { cx.set_trace_macros(false); } _ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"), |
