about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/deriving/clone.rs43
-rw-r--r--src/libsyntax/ext/deriving/generic.rs37
-rw-r--r--src/libsyntax/ext/deriving/mod.rs5
-rw-r--r--src/libsyntax/ext/deriving/show.rs3
-rw-r--r--src/libsyntax/ext/env.rs2
-rw-r--r--src/libsyntax/ext/expand.rs19
6 files changed, 56 insertions, 53 deletions
diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs
index bd961002f53..5595bdee688 100644
--- a/src/libsyntax/ext/deriving/clone.rs
+++ b/src/libsyntax/ext/deriving/clone.rs
@@ -97,30 +97,27 @@ fn cs_clone(
                                                                  name))
     }
 
-    match *all_fields {
-        [FieldInfo { name: None, .. }, ..] => {
-            // enum-like
-            let subcalls = all_fields.map(subcall);
-            cx.expr_call_ident(trait_span, ctor_ident, subcalls)
-        },
-        _ => {
-            // struct-like
-            let fields = all_fields.map(|field| {
-                let ident = match field.name {
-                    Some(i) => i,
-                    None => cx.span_bug(trait_span,
-                                        format!("unnamed field in normal struct in `deriving({})`",
-                                                name))
-                };
-                cx.field_imm(field.span, ident, subcall(field))
-            });
+    if all_fields.len() >= 1 && all_fields[0].name.is_none() {
+        // enum-like
+        let subcalls = all_fields.map(subcall);
+        cx.expr_call_ident(trait_span, ctor_ident, subcalls)
+    } else {
+        // struct-like
+        let fields = all_fields.map(|field| {
+            let ident = match field.name {
+                Some(i) => i,
+                None => cx.span_bug(trait_span,
+                                    format!("unnamed field in normal struct in `deriving({})`",
+                                            name))
+            };
+            cx.field_imm(field.span, ident, subcall(field))
+        });
 
-            if fields.is_empty() {
-                // no fields, so construct like `None`
-                cx.expr_ident(trait_span, ctor_ident)
-            } else {
-                cx.expr_struct_ident(trait_span, ctor_ident, fields)
-            }
+        if fields.is_empty() {
+            // no fields, so construct like `None`
+            cx.expr_ident(trait_span, ctor_ident)
+        } else {
+            cx.expr_struct_ident(trait_span, ctor_ident, fields)
         }
     }
 }
diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs
index 029e87afbe2..fb7f9b74364 100644
--- a/src/libsyntax/ext/deriving/generic.rs
+++ b/src/libsyntax/ext/deriving/generic.rs
@@ -663,25 +663,26 @@ impl<'a> MethodDef<'a> {
         }
 
         // transpose raw_fields
-        let fields = match raw_fields {
-            [ref self_arg, .. rest] => {
-                self_arg.iter().enumerate().map(|(i, &(span, opt_id, field))| {
-                    let other_fields = rest.map(|l| {
-                        match &l[i] {
-                            &(_, _, ex) => ex
-                        }
-                    });
-                    FieldInfo {
-                        span: span,
-                        name: opt_id,
-                        self_: field,
-                        other: other_fields
+        let fields = if raw_fields.len() > 0 {
+            raw_fields[0].iter()
+                         .enumerate()
+                         .map(|(i, &(span, opt_id, field))| {
+                let other_fields = raw_fields.tail().map(|l| {
+                    match &l[i] {
+                        &(_, _, ex) => ex
                     }
-                }).collect()
-            }
-            [] => { cx.span_bug(trait_.span,
-                                "no self arguments to non-static method \
-                                in generic `deriving`") }
+                });
+                FieldInfo {
+                    span: span,
+                    name: opt_id,
+                    self_: field,
+                    other: other_fields
+                }
+            }).collect()
+        } else {
+            cx.span_bug(trait_.span,
+                        "no self arguments to non-static method in generic \
+                         `deriving`")
         };
 
         // body of the inner most destructuring match
diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs
index 62408d79ee3..7c686e5cd67 100644
--- a/src/libsyntax/ext/deriving/mod.rs
+++ b/src/libsyntax/ext/deriving/mod.rs
@@ -54,7 +54,10 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
         MetaNameValue(_, ref l) => {
             cx.span_err(l.span, "unexpected value in `deriving`");
         }
-        MetaWord(_) | MetaList(_, []) => {
+        MetaWord(_) => {
+            cx.span_warn(mitem.span, "empty trait list in `deriving`");
+        }
+        MetaList(_, ref titems) if titems.len() == 0 => {
             cx.span_warn(mitem.span, "empty trait list in `deriving`");
         }
         MetaList(_, ref titems) => {
diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs
index 83d327daf17..d5b08503fd0 100644
--- a/src/libsyntax/ext/deriving/show.rs
+++ b/src/libsyntax/ext/deriving/show.rs
@@ -74,7 +74,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
     // Getting harder... making the format string:
     match *substr.fields {
         // unit struct/nullary variant: no work necessary!
-        Struct([]) | EnumMatching(_, _, []) => {}
+        Struct(ref fields) if fields.len() == 0 => {}
+        EnumMatching(_, _, ref fields) if fields.len() == 0 => {}
 
         Struct(ref fields) | EnumMatching(_, _, ref fields) => {
             if fields[0].name.is_none() {
diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs
index fec1e70af07..aacb2a74087 100644
--- a/src/libsyntax/ext/env.rs
+++ b/src/libsyntax/ext/env.rs
@@ -40,7 +40,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
 pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
     -> base::MacResult {
     let exprs = match get_exprs_from_tts(cx, sp, tts) {
-        Some([]) => {
+        Some(ref exprs) if exprs.len() == 0 => {
             cx.span_err(sp, "env! takes 1 or 2 arguments");
             return MacResult::dummy_expr(sp);
         }
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 4b81713f7d0..1e0bfb0d3e9 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -647,14 +647,10 @@ impl Visitor<()> for NewNameFinderContext {
                     &ast::Path {
                         global: false,
                         span: _,
-                        segments: [
-                            ast::PathSegment {
-                                identifier: id,
-                                lifetimes: _,
-                                types: _
-                            }
-                        ]
-                    } => self.ident_accumulator.push(id),
+                        segments: ref segments
+                    } if segments.len() == 1 => {
+                        self.ident_accumulator.push(segments[0].identifier)
+                    }
                     // I believe these must be enums...
                     _ => ()
                 }
@@ -1187,7 +1183,12 @@ foo_module!()
         let bindings = name_finder.ident_accumulator;
 
         let cxbinds: ~[&ast::Ident] =
-            bindings.iter().filter(|b| "xx" == token::get_ident(**b).get()).collect();
+            bindings.iter().filter(|b| {
+                let ident = token::get_ident(**b);
+                let string = ident.get();
+                "xx" == string
+            }).collect();
+        let cxbinds: &[&ast::Ident] = cxbinds;
         let cxbind = match cxbinds {
             [b] => b,
             _ => fail!("expected just one binding for ext_cx")