]> git.lizzy.rs Git - rust.git/commitdiff
Feature gate async fn methods
authorvarkor <github@varkor.com>
Thu, 18 Apr 2019 18:15:43 +0000 (19:15 +0100)
committervarkor <github@varkor.com>
Sat, 20 Apr 2019 21:03:39 +0000 (22:03 +0100)
src/libsyntax/feature_gate.rs
src/libsyntax/visit.rs

index 7bae5ba75719a0544b0faf789fbbd91ec67854bb..560748dbd6ffd6d6a0e0d90eba6b16b27fc3b820 100644 (file)
@@ -2035,28 +2035,22 @@ fn visit_fn(&mut self,
                 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);
     }
 
index 8f42d47e69cd3b57c8637a29e44baa2318f2e323..fe74cbd649612d23675069b0e6ee429a9e60e95a 100644 (file)
@@ -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;