diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 489a7721d7b..366806bc19b 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -284,8 +284,15 @@ impl<'a> fold::Folder for CfgAttrFolder<'a> { return fold::noop_fold_attribute(attr, self); } - let (cfg, mi) = match attr.meta_item_list() { - Some([ref cfg, ref mi]) => (cfg, mi), + let attr_list = match attr.meta_item_list() { + Some(attr_list) => attr_list, + None => { + self.diag.span_err(attr.span, "expected `#[cfg_attr(, )]`"); + return None; + } + }; + let (cfg, mi) = match (attr_list.len(), attr_list.get(0), attr_list.get(1)) { + (2, Some(cfg), Some(mi)) => (cfg, mi), _ => { self.diag.span_err(attr.span, "expected `#[cfg_attr(, )]`"); return None; diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 6fcf39f0b17..ac25a303182 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -54,8 +54,8 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt, span: Span, token_tree: &[TokenTree]) -> Box { - let code = match token_tree { - [ast::TtToken(_, token::Ident(code, _))] => code, + let code = match (token_tree.len(), token_tree.get(0)) { + (1, Some(&ast::TtToken(_, token::Ident(code, _)))) => code, _ => unreachable!() }; with_used_diagnostics(|diagnostics| { @@ -84,13 +84,18 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, span: Span, token_tree: &[TokenTree]) -> Box { - let (code, description) = match token_tree { - [ast::TtToken(_, token::Ident(ref code, _))] => { + let (code, description) = match ( + token_tree.len(), + token_tree.get(0), + token_tree.get(1), + token_tree.get(2) + ) { + (1, Some(&ast::TtToken(_, token::Ident(ref code, _))), None, None) => { (code, None) }, - [ast::TtToken(_, token::Ident(ref code, _)), - ast::TtToken(_, token::Comma), - ast::TtToken(_, token::Literal(token::StrRaw(description, _), None))] => { + (3, Some(&ast::TtToken(_, token::Ident(ref code, _))), + Some(&ast::TtToken(_, token::Comma)), + Some(&ast::TtToken(_, token::Literal(token::StrRaw(description, _), None)))) => { (code, Some(description)) } _ => unreachable!() @@ -130,8 +135,8 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, span: Span, token_tree: &[TokenTree]) -> Box { - let name = match token_tree { - [ast::TtToken(_, token::Ident(ref name, _))] => name, + let name = match (token_tree.len(), token_tree.get(0)) { + (1, Some(&ast::TtToken(_, token::Ident(ref name, _)))) => name, _ => unreachable!() }; diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index b2a4ef1dafb..94cc0d9c493 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -106,8 +106,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, // } let new = { - let other_f = match other_fs { - [ref o_f] => o_f, + let other_f = match (other_fs.len(), other_fs.get(0)) { + (1, Some(o_f)) => o_f, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), }; diff --git a/src/libsyntax/ext/deriving/cmp/partial_eq.rs b/src/libsyntax/ext/deriving/cmp/partial_eq.rs index f02e5ee1412..61eb81c6755 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax/ext/deriving/cmp/partial_eq.rs @@ -29,8 +29,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, cs_fold( true, // use foldl |cx, span, subexpr, self_f, other_fs| { - let other_f = match other_fs { - [ref o_f] => o_f, + let other_f = match (other_fs.len(), other_fs.get(0)) { + (1, Some(o_f)) => o_f, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`") }; @@ -46,8 +46,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, cs_fold( true, // use foldl |cx, span, subexpr, self_f, other_fs| { - let other_f = match other_fs { - [ref o_f] => o_f, + let other_f = match (other_fs.len(), other_fs.get(0)) { + (1, Some(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 fe6a8fea78c..dbb779decac 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax/ext/deriving/cmp/partial_ord.rs @@ -150,8 +150,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, // } let new = { - let other_f = match other_fs { - [ref o_f] => o_f, + let other_f = match (other_fs.len(), other_fs.get(0)) { + (1, Some(o_f)) => o_f, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), }; @@ -208,8 +208,8 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, get use the binops to avoid auto-deref dereferencing too many layers of pointers, if the type includes pointers. */ - let other_f = match other_fs { - [ref o_f] => o_f, + let other_f = match (other_fs.len(), other_fs.get(0)) { + (1, Some(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 915d9979615..b9835eda791 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -56,8 +56,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, } fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { - let state_expr = match substr.nonself_args { - [ref state_expr] => state_expr, + let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) { + (1, Some(o_f)) => o_f, _ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`") }; let call_hash = |span, thing_expr| { diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index 3d0645fd6e3..a972cfe1355 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -71,8 +71,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, } fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { - let n = match substr.nonself_args { - [ref n] => n, + let n = match (substr.nonself_args.len(), substr.nonself_args.get(0)) { + (1, Some(o_f)) => o_f, _ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(FromPrimitive)`") }; diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 0945f8dd021..d1db956adb3 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1962,8 +1962,8 @@ foo_module!(); "xx" == string }).collect(); let cxbinds: &[&ast::Ident] = &cxbinds[..]; - let cxbind = match cxbinds { - [b] => b, + let cxbind = match (cxbinds.len(), cxbinds.get(0)) { + (1, Some(b)) => *b, _ => panic!("expected just one binding for ext_cx") }; let resolved_binding = mtwt::resolve(*cxbind); diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index 3fcc6a8d692..646e6fec405 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -28,12 +28,11 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, return base::DummyResult::any(sp); } - - match tt { - [ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => { + match (tt.len(), tt.first()) { + (1, Some(&ast::TtToken(_, ref tok))) if tok.is_keyword(keywords::True) => { cx.set_trace_macros(true); } - [ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::False) => { + (1, Some(&ast::TtToken(_, ref tok))) if tok.is_keyword(keywords::False) => { cx.set_trace_macros(false); } _ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 99fb2798e7a..a70707b3ea1 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -35,7 +35,6 @@ #![feature(path_ext)] #![feature(str_char)] #![feature(into_cow)] -#![feature(slice_patterns)] extern crate arena; extern crate fmt_macros; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c078787120f..51fb09a7526 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -834,28 +834,44 @@ mod test { fn string_to_tts_macro () { let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string()); let tts: &[ast::TokenTree] = &tts[..]; - match tts { - [ast::TtToken(_, token::Ident(name_macro_rules, token::Plain)), - ast::TtToken(_, token::Not), - ast::TtToken(_, token::Ident(name_zip, token::Plain)), - ast::TtDelimited(_, ref macro_delimed)] + + match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) { + ( + 4, + Some(&ast::TtToken(_, token::Ident(name_macro_rules, token::Plain))), + Some(&ast::TtToken(_, token::Not)), + Some(&ast::TtToken(_, token::Ident(name_zip, token::Plain))), + Some(&ast::TtDelimited(_, ref macro_delimed)), + ) if name_macro_rules.as_str() == "macro_rules" && name_zip.as_str() == "zip" => { - match ¯o_delimed.tts[..] { - [ast::TtDelimited(_, ref first_delimed), - ast::TtToken(_, token::FatArrow), - ast::TtDelimited(_, ref second_delimed)] + let tts = ¯o_delimed.tts[..]; + match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) { + ( + 3, + Some(&ast::TtDelimited(_, ref first_delimed)), + Some(&ast::TtToken(_, token::FatArrow)), + Some(&ast::TtDelimited(_, ref second_delimed)), + ) if macro_delimed.delim == token::Paren => { - match &first_delimed.tts[..] { - [ast::TtToken(_, token::Dollar), - ast::TtToken(_, token::Ident(name, token::Plain))] + let tts = &first_delimed.tts[..]; + match (tts.len(), tts.get(0), tts.get(1)) { + ( + 2, + Some(&ast::TtToken(_, token::Dollar)), + Some(&ast::TtToken(_, token::Ident(name, token::Plain))), + ) if first_delimed.delim == token::Paren && name.as_str() == "a" => {}, _ => panic!("value 3: {:?}", **first_delimed), } - match &second_delimed.tts[..] { - [ast::TtToken(_, token::Dollar), - ast::TtToken(_, token::Ident(name, token::Plain))] + let tts = &second_delimed.tts[..]; + match (tts.len(), tts.get(0), tts.get(1)) { + ( + 2, + Some(&ast::TtToken(_, token::Dollar)), + Some(&ast::TtToken(_, token::Ident(name, token::Plain))), + ) if second_delimed.delim == token::Paren && name.as_str() == "a" => {}, _ => panic!("value 4: {:?}", **second_delimed),