]> git.lizzy.rs Git - rust.git/commitdiff
parser: move parse_fn_block_decl into expr.rs
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 11 Aug 2019 18:04:09 +0000 (20:04 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sun, 11 Aug 2019 18:04:09 +0000 (20:04 +0200)
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser/expr.rs

index 7ba3e7c4236084ad85b9f5ec47d4106897e41c1d..e2a41a808686ed4304c74c6e4b8c7cc9b0462186 100644 (file)
@@ -19,7 +19,7 @@
 use crate::ast::StrStyle;
 use crate::ast::SelfKind;
 use crate::ast::{GenericParam, GenericParamKind, WhereClause};
-use crate::ast::{Ty, TyKind,  GenericBounds};
+use crate::ast::{TyKind,  GenericBounds};
 use crate::ast::{Visibility, VisibilityKind, Unsafety, CrateSugar};
 use crate::ext::base::DummyResult;
 use crate::ext::hygiene::SyntaxContext;
@@ -1055,30 +1055,6 @@ fn parse_arg_general<F>(
         Ok(Arg { attrs: attrs.into(), id: ast::DUMMY_NODE_ID, pat, span, ty })
     }
 
-    /// Parses an argument in a lambda header (e.g., `|arg, arg|`).
-    fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
-        let lo = self.token.span;
-        let attrs = self.parse_arg_attributes()?;
-        let pat = self.parse_pat(Some("argument name"))?;
-        let t = if self.eat(&token::Colon) {
-            self.parse_ty()?
-        } else {
-            P(Ty {
-                id: ast::DUMMY_NODE_ID,
-                node: TyKind::Infer,
-                span: self.prev_span,
-            })
-        };
-        let span = lo.to(self.token.span);
-        Ok(Arg {
-            attrs: attrs.into(),
-            ty: t,
-            pat,
-            span,
-            id: ast::DUMMY_NODE_ID
-        })
-    }
-
     crate fn check_lifetime(&mut self) -> bool {
         self.expected_tokens.push(TokenType::Lifetime);
         self.token.is_lifetime()
@@ -2148,32 +2124,6 @@ fn parse_fn_decl_with_self<F>(&mut self, parse_arg_fn: F) -> PResult<'a, P<FnDec
         }))
     }
 
-    /// Parses the `|arg, arg|` header of a closure.
-    fn parse_fn_block_decl(&mut self) -> PResult<'a, P<FnDecl>> {
-        let inputs_captures = {
-            if self.eat(&token::OrOr) {
-                Vec::new()
-            } else {
-                self.expect(&token::BinOp(token::Or))?;
-                let args = self.parse_seq_to_before_tokens(
-                    &[&token::BinOp(token::Or), &token::OrOr],
-                    SeqSep::trailing_allowed(token::Comma),
-                    TokenExpectType::NoExpect,
-                    |p| p.parse_fn_block_arg()
-                )?.0;
-                self.expect_or()?;
-                args
-            }
-        };
-        let output = self.parse_ret_ty(true)?;
-
-        Ok(P(FnDecl {
-            inputs: inputs_captures,
-            output,
-            c_variadic: false
-        }))
-    }
-
     fn choose_generics_over_qpath(&self) -> bool {
         // There's an ambiguity between generic parameters and qualified paths in impls.
         // If we see `<` it may start both, so we have to inspect some following tokens.
index 88e534394fe1653c70ee6608a57f2b31026a57e1..19d5bcd3ee9e27784f4ff9db4e9e1a04ca592cf2 100644 (file)
@@ -1,15 +1,13 @@
 use super::{Parser, PResult, Restrictions, PrevTokenKind, TokenType, PathStyle};
 use super::{BlockCheckMode, BlockMode, SemiColonMode};
-use super::SeqSep;
-
-use crate::{maybe_recover_from_interpolated_ty_qpath};
+use super::{SeqSep, TokenExpectType};
 
+use crate::maybe_recover_from_interpolated_ty_qpath;
 use crate::ptr::P;
-use crate::ast;
-use crate::ast::{Attribute, AttrStyle};
+use crate::ast::{self, Attribute, AttrStyle};
 use crate::ast::{Ident, CaptureBy};
 use crate::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm};
-use crate::ast::{Ty, TyKind, FunctionRetTy};
+use crate::ast::{Ty, TyKind, FunctionRetTy, Arg, FnDecl};
 use crate::ast::{BinOpKind, BinOp, UnOp};
 use crate::ast::{Mac_, AnonConst, Field};
 
@@ -22,9 +20,7 @@
 use crate::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par};
 
 use std::mem;
-
-use errors::{Applicability};
-
+use errors::Applicability;
 use rustc_data_structures::thin_vec::ThinVec;
 
 /// Possibly accepts an `token::Interpolated` expression (a pre-parsed expression
@@ -1142,6 +1138,56 @@ fn parse_capture_clause(&mut self) -> CaptureBy {
         }
     }
 
+    /// Parses the `|arg, arg|` header of a closure.
+    fn parse_fn_block_decl(&mut self) -> PResult<'a, P<FnDecl>> {
+        let inputs_captures = {
+            if self.eat(&token::OrOr) {
+                Vec::new()
+            } else {
+                self.expect(&token::BinOp(token::Or))?;
+                let args = self.parse_seq_to_before_tokens(
+                    &[&token::BinOp(token::Or), &token::OrOr],
+                    SeqSep::trailing_allowed(token::Comma),
+                    TokenExpectType::NoExpect,
+                    |p| p.parse_fn_block_arg()
+                )?.0;
+                self.expect_or()?;
+                args
+            }
+        };
+        let output = self.parse_ret_ty(true)?;
+
+        Ok(P(FnDecl {
+            inputs: inputs_captures,
+            output,
+            c_variadic: false
+        }))
+    }
+
+    /// Parses an argument in a lambda header (e.g., `|arg, arg|`).
+    fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
+        let lo = self.token.span;
+        let attrs = self.parse_arg_attributes()?;
+        let pat = self.parse_pat(Some("argument name"))?;
+        let t = if self.eat(&token::Colon) {
+            self.parse_ty()?
+        } else {
+            P(Ty {
+                id: ast::DUMMY_NODE_ID,
+                node: TyKind::Infer,
+                span: self.prev_span,
+            })
+        };
+        let span = lo.to(self.token.span);
+        Ok(Arg {
+            attrs: attrs.into(),
+            ty: t,
+            pat,
+            span,
+            id: ast::DUMMY_NODE_ID
+        })
+    }
+
     /// Parses an `if` expression (`if` token already eaten).
     fn parse_if_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
         let lo = self.prev_span;