syntax: Remove uses of #[feature(slice_patterns)]

This commit is contained in:
Erick Tryzelaar 2015-04-15 22:12:12 -07:00
parent a4541b02a3
commit ca0ee4c645
11 changed files with 73 additions and 47 deletions

View file

@ -284,8 +284,15 @@ impl<'a> fold::Folder for CfgAttrFolder<'a> {
return fold::noop_fold_attribute(attr, self); return fold::noop_fold_attribute(attr, self);
} }
let (cfg, mi) = match attr.meta_item_list() { let attr_list = match attr.meta_item_list() {
Some([ref cfg, ref mi]) => (cfg, mi), Some(attr_list) => attr_list,
None => {
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <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(<cfg pattern>, <attr>)]`"); self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
return None; return None;

View file

@ -54,8 +54,8 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
span: Span, span: Span,
token_tree: &[TokenTree]) token_tree: &[TokenTree])
-> Box<MacResult+'cx> { -> Box<MacResult+'cx> {
let code = match token_tree { let code = match (token_tree.len(), token_tree.get(0)) {
[ast::TtToken(_, token::Ident(code, _))] => code, (1, Some(&ast::TtToken(_, token::Ident(code, _)))) => code,
_ => unreachable!() _ => unreachable!()
}; };
with_used_diagnostics(|diagnostics| { with_used_diagnostics(|diagnostics| {
@ -84,13 +84,18 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
span: Span, span: Span,
token_tree: &[TokenTree]) token_tree: &[TokenTree])
-> Box<MacResult+'cx> { -> Box<MacResult+'cx> {
let (code, description) = match token_tree { let (code, description) = match (
[ast::TtToken(_, token::Ident(ref code, _))] => { 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) (code, None)
}, },
[ast::TtToken(_, token::Ident(ref code, _)), (3, Some(&ast::TtToken(_, token::Ident(ref code, _))),
ast::TtToken(_, token::Comma), Some(&ast::TtToken(_, token::Comma)),
ast::TtToken(_, token::Literal(token::StrRaw(description, _), None))] => { Some(&ast::TtToken(_, token::Literal(token::StrRaw(description, _), None)))) => {
(code, Some(description)) (code, Some(description))
} }
_ => unreachable!() _ => unreachable!()
@ -130,8 +135,8 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
span: Span, span: Span,
token_tree: &[TokenTree]) token_tree: &[TokenTree])
-> Box<MacResult+'cx> { -> Box<MacResult+'cx> {
let name = match token_tree { let name = match (token_tree.len(), token_tree.get(0)) {
[ast::TtToken(_, token::Ident(ref name, _))] => name, (1, Some(&ast::TtToken(_, token::Ident(ref name, _)))) => name,
_ => unreachable!() _ => unreachable!()
}; };

View file

@ -106,8 +106,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
// } // }
let new = { let new = {
let other_f = match other_fs { let other_f = match (other_fs.len(), other_fs.get(0)) {
[ref o_f] => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
}; };

View file

@ -29,8 +29,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
cs_fold( cs_fold(
true, // use foldl true, // use foldl
|cx, span, subexpr, self_f, other_fs| { |cx, span, subexpr, self_f, other_fs| {
let other_f = match other_fs { let other_f = match (other_fs.len(), other_fs.get(0)) {
[ref o_f] => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`") _ => 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( cs_fold(
true, // use foldl true, // use foldl
|cx, span, subexpr, self_f, other_fs| { |cx, span, subexpr, self_f, other_fs| {
let other_f = match other_fs { let other_f = match (other_fs.len(), other_fs.get(0)) {
[ref o_f] => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`") _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
}; };

View file

@ -150,8 +150,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
// } // }
let new = { let new = {
let other_f = match other_fs { let other_f = match (other_fs.len(), other_fs.get(0)) {
[ref o_f] => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), _ => 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 get use the binops to avoid auto-deref dereferencing too many
layers of pointers, if the type includes pointers. layers of pointers, if the type includes pointers.
*/ */
let other_f = match other_fs { let other_f = match (other_fs.len(), other_fs.get(0)) {
[ref o_f] => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`") _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
}; };

View file

@ -56,8 +56,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
} }
fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
let state_expr = match substr.nonself_args { let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) {
[ref state_expr] => state_expr, (1, Some(o_f)) => o_f,
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`") _ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`")
}; };
let call_hash = |span, thing_expr| { let call_hash = |span, thing_expr| {

View file

@ -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<Expr> { fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
let n = match substr.nonself_args { let n = match (substr.nonself_args.len(), substr.nonself_args.get(0)) {
[ref n] => n, (1, Some(o_f)) => o_f,
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(FromPrimitive)`") _ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(FromPrimitive)`")
}; };

View file

@ -1962,8 +1962,8 @@ foo_module!();
"xx" == string "xx" == string
}).collect(); }).collect();
let cxbinds: &[&ast::Ident] = &cxbinds[..]; let cxbinds: &[&ast::Ident] = &cxbinds[..];
let cxbind = match cxbinds { let cxbind = match (cxbinds.len(), cxbinds.get(0)) {
[b] => b, (1, Some(b)) => *b,
_ => panic!("expected just one binding for ext_cx") _ => panic!("expected just one binding for ext_cx")
}; };
let resolved_binding = mtwt::resolve(*cxbind); let resolved_binding = mtwt::resolve(*cxbind);

View file

@ -28,12 +28,11 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
return base::DummyResult::any(sp); return base::DummyResult::any(sp);
} }
match (tt.len(), tt.first()) {
match tt { (1, Some(&ast::TtToken(_, ref tok))) if tok.is_keyword(keywords::True) => {
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => {
cx.set_trace_macros(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.set_trace_macros(false);
} }
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"), _ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),

View file

@ -35,7 +35,6 @@
#![feature(path_ext)] #![feature(path_ext)]
#![feature(str_char)] #![feature(str_char)]
#![feature(into_cow)] #![feature(into_cow)]
#![feature(slice_patterns)]
extern crate arena; extern crate arena;
extern crate fmt_macros; extern crate fmt_macros;

View file

@ -834,28 +834,44 @@ mod test {
fn string_to_tts_macro () { fn string_to_tts_macro () {
let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string()); let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string());
let tts: &[ast::TokenTree] = &tts[..]; let tts: &[ast::TokenTree] = &tts[..];
match tts {
[ast::TtToken(_, token::Ident(name_macro_rules, token::Plain)), match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) {
ast::TtToken(_, token::Not), (
ast::TtToken(_, token::Ident(name_zip, token::Plain)), 4,
ast::TtDelimited(_, ref macro_delimed)] 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" if name_macro_rules.as_str() == "macro_rules"
&& name_zip.as_str() == "zip" => { && name_zip.as_str() == "zip" => {
match &macro_delimed.tts[..] { let tts = &macro_delimed.tts[..];
[ast::TtDelimited(_, ref first_delimed), match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) {
ast::TtToken(_, token::FatArrow), (
ast::TtDelimited(_, ref second_delimed)] 3,
Some(&ast::TtDelimited(_, ref first_delimed)),
Some(&ast::TtToken(_, token::FatArrow)),
Some(&ast::TtDelimited(_, ref second_delimed)),
)
if macro_delimed.delim == token::Paren => { if macro_delimed.delim == token::Paren => {
match &first_delimed.tts[..] { let tts = &first_delimed.tts[..];
[ast::TtToken(_, token::Dollar), match (tts.len(), tts.get(0), tts.get(1)) {
ast::TtToken(_, token::Ident(name, token::Plain))] (
2,
Some(&ast::TtToken(_, token::Dollar)),
Some(&ast::TtToken(_, token::Ident(name, token::Plain))),
)
if first_delimed.delim == token::Paren if first_delimed.delim == token::Paren
&& name.as_str() == "a" => {}, && name.as_str() == "a" => {},
_ => panic!("value 3: {:?}", **first_delimed), _ => panic!("value 3: {:?}", **first_delimed),
} }
match &second_delimed.tts[..] { let tts = &second_delimed.tts[..];
[ast::TtToken(_, token::Dollar), match (tts.len(), tts.get(0), tts.get(1)) {
ast::TtToken(_, token::Ident(name, token::Plain))] (
2,
Some(&ast::TtToken(_, token::Dollar)),
Some(&ast::TtToken(_, token::Ident(name, token::Plain))),
)
if second_delimed.delim == token::Paren if second_delimed.delim == token::Paren
&& name.as_str() == "a" => {}, && name.as_str() == "a" => {},
_ => panic!("value 4: {:?}", **second_delimed), _ => panic!("value 4: {:?}", **second_delimed),