Skip to content

Commit ca0ee4c

Browse files
committed
syntax: Remove uses of #[feature(slice_patterns)]
1 parent a4541b0 commit ca0ee4c

File tree

11 files changed

+73
-47
lines changed

11 files changed

+73
-47
lines changed

src/libsyntax/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,15 @@ impl<'a> fold::Folder for CfgAttrFolder<'a> {
284284
return fold::noop_fold_attribute(attr, self);
285285
}
286286

287-
let (cfg, mi) = match attr.meta_item_list() {
288-
Some([ref cfg, ref mi]) => (cfg, mi),
287+
let attr_list = match attr.meta_item_list() {
288+
Some(attr_list) => attr_list,
289+
None => {
290+
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
291+
return None;
292+
}
293+
};
294+
let (cfg, mi) = match (attr_list.len(), attr_list.get(0), attr_list.get(1)) {
295+
(2, Some(cfg), Some(mi)) => (cfg, mi),
289296
_ => {
290297
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
291298
return None;

src/libsyntax/diagnostics/plugin.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
5454
span: Span,
5555
token_tree: &[TokenTree])
5656
-> Box<MacResult+'cx> {
57-
let code = match token_tree {
58-
[ast::TtToken(_, token::Ident(code, _))] => code,
57+
let code = match (token_tree.len(), token_tree.get(0)) {
58+
(1, Some(&ast::TtToken(_, token::Ident(code, _)))) => code,
5959
_ => unreachable!()
6060
};
6161
with_used_diagnostics(|diagnostics| {
@@ -84,13 +84,18 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
8484
span: Span,
8585
token_tree: &[TokenTree])
8686
-> Box<MacResult+'cx> {
87-
let (code, description) = match token_tree {
88-
[ast::TtToken(_, token::Ident(ref code, _))] => {
87+
let (code, description) = match (
88+
token_tree.len(),
89+
token_tree.get(0),
90+
token_tree.get(1),
91+
token_tree.get(2)
92+
) {
93+
(1, Some(&ast::TtToken(_, token::Ident(ref code, _))), None, None) => {
8994
(code, None)
9095
},
91-
[ast::TtToken(_, token::Ident(ref code, _)),
92-
ast::TtToken(_, token::Comma),
93-
ast::TtToken(_, token::Literal(token::StrRaw(description, _), None))] => {
96+
(3, Some(&ast::TtToken(_, token::Ident(ref code, _))),
97+
Some(&ast::TtToken(_, token::Comma)),
98+
Some(&ast::TtToken(_, token::Literal(token::StrRaw(description, _), None)))) => {
9499
(code, Some(description))
95100
}
96101
_ => unreachable!()
@@ -130,8 +135,8 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
130135
span: Span,
131136
token_tree: &[TokenTree])
132137
-> Box<MacResult+'cx> {
133-
let name = match token_tree {
134-
[ast::TtToken(_, token::Ident(ref name, _))] => name,
138+
let name = match (token_tree.len(), token_tree.get(0)) {
139+
(1, Some(&ast::TtToken(_, token::Ident(ref name, _)))) => name,
135140
_ => unreachable!()
136141
};
137142

src/libsyntax/ext/deriving/cmp/ord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
106106
// }
107107

108108
let new = {
109-
let other_f = match other_fs {
110-
[ref o_f] => o_f,
109+
let other_f = match (other_fs.len(), other_fs.get(0)) {
110+
(1, Some(o_f)) => o_f,
111111
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
112112
};
113113

src/libsyntax/ext/deriving/cmp/partial_eq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
2929
cs_fold(
3030
true, // use foldl
3131
|cx, span, subexpr, self_f, other_fs| {
32-
let other_f = match other_fs {
33-
[ref o_f] => o_f,
32+
let other_f = match (other_fs.len(), other_fs.get(0)) {
33+
(1, Some(o_f)) => o_f,
3434
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
3535
};
3636

@@ -46,8 +46,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
4646
cs_fold(
4747
true, // use foldl
4848
|cx, span, subexpr, self_f, other_fs| {
49-
let other_f = match other_fs {
50-
[ref o_f] => o_f,
49+
let other_f = match (other_fs.len(), other_fs.get(0)) {
50+
(1, Some(o_f)) => o_f,
5151
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
5252
};
5353

src/libsyntax/ext/deriving/cmp/partial_ord.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
150150
// }
151151

152152
let new = {
153-
let other_f = match other_fs {
154-
[ref o_f] => o_f,
153+
let other_f = match (other_fs.len(), other_fs.get(0)) {
154+
(1, Some(o_f)) => o_f,
155155
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
156156
};
157157

@@ -208,8 +208,8 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
208208
get use the binops to avoid auto-deref dereferencing too many
209209
layers of pointers, if the type includes pointers.
210210
*/
211-
let other_f = match other_fs {
212-
[ref o_f] => o_f,
211+
let other_f = match (other_fs.len(), other_fs.get(0)) {
212+
(1, Some(o_f)) => o_f,
213213
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
214214
};
215215

src/libsyntax/ext/deriving/hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
5656
}
5757

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

src/libsyntax/ext/deriving/primitive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
7171
}
7272

7373
fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
74-
let n = match substr.nonself_args {
75-
[ref n] => n,
74+
let n = match (substr.nonself_args.len(), substr.nonself_args.get(0)) {
75+
(1, Some(o_f)) => o_f,
7676
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(FromPrimitive)`")
7777
};
7878

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,8 +1962,8 @@ foo_module!();
19621962
"xx" == string
19631963
}).collect();
19641964
let cxbinds: &[&ast::Ident] = &cxbinds[..];
1965-
let cxbind = match cxbinds {
1966-
[b] => b,
1965+
let cxbind = match (cxbinds.len(), cxbinds.get(0)) {
1966+
(1, Some(b)) => *b,
19671967
_ => panic!("expected just one binding for ext_cx")
19681968
};
19691969
let resolved_binding = mtwt::resolve(*cxbind);

src/libsyntax/ext/trace_macros.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
2828
return base::DummyResult::any(sp);
2929
}
3030

31-
32-
match tt {
33-
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => {
31+
match (tt.len(), tt.first()) {
32+
(1, Some(&ast::TtToken(_, ref tok))) if tok.is_keyword(keywords::True) => {
3433
cx.set_trace_macros(true);
3534
}
36-
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::False) => {
35+
(1, Some(&ast::TtToken(_, ref tok))) if tok.is_keyword(keywords::False) => {
3736
cx.set_trace_macros(false);
3837
}
3938
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),

src/libsyntax/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(path_ext)]
3636
#![feature(str_char)]
3737
#![feature(into_cow)]
38-
#![feature(slice_patterns)]
3938

4039
extern crate arena;
4140
extern crate fmt_macros;

src/libsyntax/parse/mod.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -834,28 +834,44 @@ mod test {
834834
fn string_to_tts_macro () {
835835
let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string());
836836
let tts: &[ast::TokenTree] = &tts[..];
837-
match tts {
838-
[ast::TtToken(_, token::Ident(name_macro_rules, token::Plain)),
839-
ast::TtToken(_, token::Not),
840-
ast::TtToken(_, token::Ident(name_zip, token::Plain)),
841-
ast::TtDelimited(_, ref macro_delimed)]
837+
838+
match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) {
839+
(
840+
4,
841+
Some(&ast::TtToken(_, token::Ident(name_macro_rules, token::Plain))),
842+
Some(&ast::TtToken(_, token::Not)),
843+
Some(&ast::TtToken(_, token::Ident(name_zip, token::Plain))),
844+
Some(&ast::TtDelimited(_, ref macro_delimed)),
845+
)
842846
if name_macro_rules.as_str() == "macro_rules"
843847
&& name_zip.as_str() == "zip" => {
844-
match &macro_delimed.tts[..] {
845-
[ast::TtDelimited(_, ref first_delimed),
846-
ast::TtToken(_, token::FatArrow),
847-
ast::TtDelimited(_, ref second_delimed)]
848+
let tts = &macro_delimed.tts[..];
849+
match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) {
850+
(
851+
3,
852+
Some(&ast::TtDelimited(_, ref first_delimed)),
853+
Some(&ast::TtToken(_, token::FatArrow)),
854+
Some(&ast::TtDelimited(_, ref second_delimed)),
855+
)
848856
if macro_delimed.delim == token::Paren => {
849-
match &first_delimed.tts[..] {
850-
[ast::TtToken(_, token::Dollar),
851-
ast::TtToken(_, token::Ident(name, token::Plain))]
857+
let tts = &first_delimed.tts[..];
858+
match (tts.len(), tts.get(0), tts.get(1)) {
859+
(
860+
2,
861+
Some(&ast::TtToken(_, token::Dollar)),
862+
Some(&ast::TtToken(_, token::Ident(name, token::Plain))),
863+
)
852864
if first_delimed.delim == token::Paren
853865
&& name.as_str() == "a" => {},
854866
_ => panic!("value 3: {:?}", **first_delimed),
855867
}
856-
match &second_delimed.tts[..] {
857-
[ast::TtToken(_, token::Dollar),
858-
ast::TtToken(_, token::Ident(name, token::Plain))]
868+
let tts = &second_delimed.tts[..];
869+
match (tts.len(), tts.get(0), tts.get(1)) {
870+
(
871+
2,
872+
Some(&ast::TtToken(_, token::Dollar)),
873+
Some(&ast::TtToken(_, token::Ident(name, token::Plain))),
874+
)
859875
if second_delimed.delim == token::Paren
860876
&& name.as_str() == "a" => {},
861877
_ => panic!("value 4: {:?}", **second_delimed),

0 commit comments

Comments
 (0)