about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-04-18 19:15:43 +0100
committervarkor <github@varkor.com>2019-04-20 22:03:39 +0100
commit47a558ed7c9b129dea246cdfb35817b1035f8de9 (patch)
treea655ce20ed111efa4e06a285d2860082ff62c13b
parent4bbd29f2066b58d0efef6fe724807daa3d85d237 (diff)
downloadrust-47a558ed7c9b129dea246cdfb35817b1035f8de9.tar.gz
rust-47a558ed7c9b129dea246cdfb35817b1035f8de9.zip
Feature gate async fn methods
-rw-r--r--src/libsyntax/feature_gate.rs32
-rw-r--r--src/libsyntax/visit.rs10
2 files changed, 23 insertions, 19 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 7bae5ba7571..560748dbd6f 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -2035,28 +2035,22 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                 fn_decl: &'a ast::FnDecl,
                 span: Span,
                 _node_id: NodeId) {
-        match fn_kind {
-            FnKind::ItemFn(_, header, _, _) => {
-                // Check for const fn and async fn declarations.
-                if header.asyncness.node.is_async() {
-                    gate_feature_post!(&self, async_await, span, "async fn is unstable");
-                }
+        if let Some(header) = fn_kind.header() {
+            // Check for const fn and async fn declarations.
+            if header.asyncness.node.is_async() {
+                gate_feature_post!(&self, async_await, span, "async fn is unstable");
+            }
 
-                if fn_decl.c_variadic {
-                    gate_feature_post!(&self, c_variadic, span,
-                                       "C-varaidic functions are unstable");
-                }
-                // Stability of const fn methods are covered in
-                // `visit_trait_item` and `visit_impl_item` below; this is
-                // because default methods don't pass through this point.
+            // Stability of const fn methods are covered in
+            // `visit_trait_item` and `visit_impl_item` below; this is
+            // because default methods don't pass through this point.
+            self.check_abi(header.abi, span);
+        }
 
-                self.check_abi(header.abi, span);
-            }
-            FnKind::Method(_, sig, _, _) => {
-                self.check_abi(sig.header.abi, span);
-            }
-            _ => {}
+        if fn_decl.c_variadic {
+            gate_feature_post!(&self, c_variadic, span, "C-varaidic functions are unstable");
         }
+
         visit::walk_fn(self, fn_kind, fn_decl, span);
     }
 
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 8f42d47e69c..fe74cbd6496 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -31,6 +31,16 @@ pub enum FnKind<'a> {
     Closure(&'a Expr),
 }
 
+impl<'a> FnKind<'a> {
+    pub fn header(&self) -> Option<&'a FnHeader> {
+        match *self {
+            FnKind::ItemFn(_, header, _, _) => Some(header),
+            FnKind::Method(_, sig, _, _) => Some(&sig.header),
+            FnKind::Closure(_) => None,
+        }
+    }
+}
+
 /// Each method of the Visitor trait is a hook to be potentially
 /// overridden. Each method's default implementation recursively visits
 /// the substructure of the input via the corresponding `walk` method;