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(<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>)]`");
return None;
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
- 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| {
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
- 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!()
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
- 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!()
};
// }
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)`"),
};
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)`")
};
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)`")
};
// }
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)`"),
};
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)`")
};
}
fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
- 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| {
}
fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
- 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)`")
};
"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);
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`"),
#![feature(path_ext)]
#![feature(str_char)]
#![feature(into_cow)]
-#![feature(slice_patterns)]
extern crate arena;
extern crate fmt_macros;
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),