about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorjfager <jfager@gmail.com>2014-11-29 16:41:21 -0500
committerjfager <jfager@gmail.com>2014-11-29 16:41:21 -0500
commit232ffa039ddb349c9e9c08d0872aaf95970a1369 (patch)
treee502451f6717605305e19c8fbcc8902f617c0a36 /src/libsyntax
parent6163581451a089a8d07bed4dba058677ee4a21f3 (diff)
downloadrust-232ffa039ddb349c9e9c08d0872aaf95970a1369.tar.gz
rust-232ffa039ddb349c9e9c08d0872aaf95970a1369.zip
Replace some verbose match statements with their `if let` equivalent.
No semantic changes, no enabling `if let` where it wasn't already enabled.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_map/mod.rs7
-rw-r--r--src/libsyntax/ast_util.rs19
-rw-r--r--src/libsyntax/feature_gate.rs23
-rw-r--r--src/libsyntax/parse/parser.rs63
-rw-r--r--src/libsyntax/print/pprust.rs43
-rw-r--r--src/libsyntax/visit.rs7
6 files changed, 54 insertions, 108 deletions
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs
index 6b97b931ef7..2913666a315 100644
--- a/src/libsyntax/ast_map/mod.rs
+++ b/src/libsyntax/ast_map/mod.rs
@@ -776,11 +776,8 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
             }
             ItemTrait(_, _, ref bounds, ref trait_items) => {
                 for b in bounds.iter() {
-                    match *b {
-                        TraitTyParamBound(ref t) => {
-                            self.insert(t.trait_ref.ref_id, NodeItem(i));
-                        }
-                        _ => {}
+                    if let TraitTyParamBound(ref t) = *b {
+                        self.insert(t.trait_ref.ref_id, NodeItem(i));
                     }
                 }
 
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index aa693976fe4..68bb7ecfb85 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -412,13 +412,10 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
         }
 
         self.operation.visit_id(item.id);
-        match item.node {
-            ItemEnum(ref enum_definition, _) => {
-                for variant in enum_definition.variants.iter() {
-                    self.operation.visit_id(variant.node.id)
-                }
+        if let ItemEnum(ref enum_definition, _) = item.node {
+            for variant in enum_definition.variants.iter() {
+                self.operation.visit_id(variant.node.id)
             }
-            _ => {}
         }
 
         visit::walk_item(self, item);
@@ -453,9 +450,8 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
 
     fn visit_ty(&mut self, typ: &Ty) {
         self.operation.visit_id(typ.id);
-        match typ.node {
-            TyPath(_, id) => self.operation.visit_id(id),
-            _ => {}
+        if let TyPath(_, id) = typ.node {
+            self.operation.visit_id(id);
         }
         visit::walk_ty(self, typ)
     }
@@ -500,9 +496,8 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
                        span);
 
         if !self.pass_through_items {
-            match function_kind {
-                visit::FkMethod(..) => self.visited_outermost = false,
-                _ => {}
+            if let visit::FkMethod(..) = function_kind {
+                self.visited_outermost = false;
             }
         }
     }
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 9635f0175f0..7453da6374e 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -151,13 +151,10 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
     fn visit_view_item(&mut self, i: &ast::ViewItem) {
         match i.node {
             ast::ViewItemUse(ref path) => {
-                match path.node {
-                    ast::ViewPathGlob(..) => {
-                        self.gate_feature("globs", path.span,
-                                          "glob import statements are \
-                                           experimental and possibly buggy");
-                    }
-                    _ => {}
+                if let ast::ViewPathGlob(..) = path.node {
+                    self.gate_feature("globs", path.span,
+                                      "glob import statements are \
+                                       experimental and possibly buggy");
                 }
             }
             ast::ViewItemExternCrate(..) => {
@@ -295,13 +292,10 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
     }
 
     fn visit_ty(&mut self, t: &ast::Ty) {
-        match t.node {
-            ast::TyClosure(ref closure) => {
-                // this used to be blocked by a feature gate, but it should just
-                // be plain impossible right now
-                assert!(closure.onceness != ast::Once);
-            },
-            _ => {}
+        if let ast::TyClosure(ref closure) =  t.node {
+            // this used to be blocked by a feature gate, but it should just
+            // be plain impossible right now
+            assert!(closure.onceness != ast::Once);
         }
 
         visit::walk_ty(self, t);
@@ -465,4 +459,3 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features,
     },
     unknown_features)
 }
-
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 447f2a376e1..01dc3564a84 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -178,11 +178,8 @@ macro_rules! maybe_whole (
                 }
                 _ => None
             };
-            match found {
-                Some(token::Interpolated(token::$constructor(x))) => {
-                    return x.clone()
-                }
-                _ => {}
+            if let Some(token::Interpolated(token::$constructor(x))) = found {
+                return x.clone();
             }
         }
     );
@@ -194,11 +191,8 @@ macro_rules! maybe_whole (
                 }
                 _ => None
             };
-            match found {
-                Some(token::Interpolated(token::$constructor(x))) => {
-                    return x
-                }
-                _ => {}
+            if let Some(token::Interpolated(token::$constructor(x))) = found {
+                return x;
             }
         }
     );
@@ -210,11 +204,8 @@ macro_rules! maybe_whole (
                 }
                 _ => None
             };
-            match found {
-                Some(token::Interpolated(token::$constructor(x))) => {
-                    return (*x).clone()
-                }
-                _ => {}
+            if let Some(token::Interpolated(token::$constructor(x))) = found {
+                return (*x).clone();
             }
         }
     );
@@ -226,11 +217,8 @@ macro_rules! maybe_whole (
                 }
                 _ => None
             };
-            match found {
-                Some(token::Interpolated(token::$constructor(x))) => {
-                    return Some(x.clone()),
-                }
-                _ => {}
+            if let Some(token::Interpolated(token::$constructor(x))) = found {
+                return Some(x.clone());
             }
         }
     );
@@ -242,11 +230,8 @@ macro_rules! maybe_whole (
                 }
                 _ => None
             };
-            match found {
-                Some(token::Interpolated(token::$constructor(x))) => {
-                    return IoviItem(x.clone())
-                }
-                _ => {}
+            if let Some(token::Interpolated(token::$constructor(x))) = found {
+                return IoviItem(x.clone());
             }
         }
     );
@@ -258,11 +243,8 @@ macro_rules! maybe_whole (
                 }
                 _ => None
             };
-            match found {
-                Some(token::Interpolated(token::$constructor(x))) => {
-                    return (Vec::new(), x)
-                }
-                _ => {}
+            if let Some(token::Interpolated(token::$constructor(x))) = found {
+                return (Vec::new(), x);
             }
         }
     )
@@ -469,15 +451,11 @@ impl<'a> Parser<'a> {
     /// from anticipated input errors, discarding erroneous characters.
     pub fn commit_expr(&mut self, e: &Expr, edible: &[token::Token], inedible: &[token::Token]) {
         debug!("commit_expr {}", e);
-        match e.node {
-            ExprPath(..) => {
-                // might be unit-struct construction; check for recoverableinput error.
-                let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
-                expected.push_all(inedible);
-                self.check_for_erroneous_unit_struct_expecting(
-                    expected.as_slice());
-            }
-            _ => {}
+        if let ExprPath(..) = e.node {
+            // might be unit-struct construction; check for recoverableinput error.
+            let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
+            expected.push_all(inedible);
+            self.check_for_erroneous_unit_struct_expecting(expected.as_slice());
         }
         self.expect_one_of(edible, inedible)
     }
@@ -1764,11 +1742,8 @@ impl<'a> Parser<'a> {
             token::Interpolated(token::NtPath(_)) => Some(self.bump_and_get()),
             _ => None,
         };
-        match found {
-            Some(token::Interpolated(token::NtPath(box path))) => {
-                return path;
-            }
-            _ => {}
+        if let Some(token::Interpolated(token::NtPath(box path))) = found {
+            return path;
         }
 
         let lo = self.span.lo;
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index c12c3098279..93376c5ef0d 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -969,14 +969,11 @@ impl<'a> State<'a> {
                                                     "trait").as_slice()));
                 try!(self.print_ident(item.ident));
                 try!(self.print_generics(generics));
-                match unbound {
-                    &Some(ref tref) => {
-                        try!(space(&mut self.s));
-                        try!(self.word_space("for"));
-                        try!(self.print_trait_ref(tref));
-                        try!(word(&mut self.s, "?"));
-                    }
-                    _ => {}
+                if let &Some(ref tref) = unbound {
+                    try!(space(&mut self.s));
+                    try!(self.word_space("for"));
+                    try!(self.print_trait_ref(tref));
+                    try!(word(&mut self.s, "?"));
                 }
                 try!(self.print_bounds(":", bounds.as_slice()));
                 try!(self.print_where_clause(generics));
@@ -1761,16 +1758,14 @@ impl<'a> State<'a> {
                         try!(space(&mut self.s));
                     }
                 }
-                match start {
-                    &Some(ref e) => try!(self.print_expr(&**e)),
-                    _ => {}
+                if let &Some(ref e) = start {
+                    try!(self.print_expr(&**e));
                 }
                 if start.is_some() || end.is_some() {
                     try!(word(&mut self.s, ".."));
                 }
-                match end {
-                    &Some(ref e) => try!(self.print_expr(&**e)),
-                    _ => {}
+                if let &Some(ref e) = end {
+                    try!(self.print_expr(&**e));
                 }
                 try!(word(&mut self.s, "]"));
             }
@@ -1875,13 +1870,10 @@ impl<'a> State<'a> {
                 try!(self.ibox(indent_unit));
                 try!(self.print_local_decl(&**loc));
                 try!(self.end());
-                match loc.init {
-                    Some(ref init) => {
-                        try!(self.nbsp());
-                        try!(self.word_space("="));
-                        try!(self.print_expr(&**init));
-                    }
-                    _ => {}
+                if let Some(ref init) = loc.init {
+                    try!(self.nbsp());
+                    try!(self.word_space("="));
+                    try!(self.print_expr(&**init));
                 }
                 self.end()
             }
@@ -2404,12 +2396,9 @@ impl<'a> State<'a> {
     }
 
     pub fn print_ty_param(&mut self, param: &ast::TyParam) -> IoResult<()> {
-        match param.unbound {
-            Some(ref tref) => {
-                try!(self.print_trait_ref(tref));
-                try!(self.word_space("?"));
-            }
-            _ => {}
+        if let Some(ref tref) = param.unbound {
+            try!(self.print_trait_ref(tref));
+            try!(self.word_space("?"));
         }
         try!(self.print_ident(param.ident));
         try!(self.print_bounds(":", param.bounds.as_slice()));
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 1385fb982e5..18623ca2a81 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -671,11 +671,8 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
 
 pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
                                              struct_field: &'v StructField) {
-    match struct_field.node.kind {
-        NamedField(name, _) => {
-            visitor.visit_ident(struct_field.span, name)
-        }
-        _ => {}
+    if let NamedField(name, _) = struct_field.node.kind {
+        visitor.visit_ident(struct_field.span, name);
     }
 
     visitor.visit_ty(&*struct_field.node.ty);