about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-05-07 19:39:52 +0000
committerbors <bors@rust-lang.org>2019-05-07 19:39:52 +0000
commitcfdc84a009020c59e53e4039beae22eb59e41685 (patch)
treee2cdaaaefd93cc4c364767b3034e7c05f8ecb977 /src/libsyntax/parse/parser.rs
parent17dba3b6e450c357a881c8cbe6cfce87b7b9d6bd (diff)
parent2d6da83763f934b392dd4c71b083922355ef8c87 (diff)
downloadrust-cfdc84a009020c59e53e4039beae22eb59e41685.tar.gz
rust-cfdc84a009020c59e53e4039beae22eb59e41685.zip
Auto merge of #60612 - Centril:rollup-61drhqt, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #60489 (Remove hamburger button from source code page)
 - #60535 (Correct handling of arguments in async fn)
 - #60579 (Rename `ParamTy::idx` to `ParamTy::index`)
 - #60583 (Fix parsing issue with negative literals as const generic arguments)
 - #60609 (Be a bit more explicit asserting over the vec rather than the len)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 084091f4c2a..921b857bf98 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1576,7 +1576,7 @@ impl<'a> Parser<'a> {
             let ident = self.parse_ident()?;
             let mut generics = self.parse_generics()?;
 
-            let d = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
+            let mut decl = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| {
                 // This is somewhat dubious; We don't want to allow
                 // argument names to be left off if there is a
                 // definition...
@@ -1585,7 +1585,7 @@ impl<'a> Parser<'a> {
                 p.parse_arg_general(p.span.rust_2018(), true, false)
             })?;
             generics.where_clause = self.parse_where_clause()?;
-            self.construct_async_arguments(&mut asyncness, &d);
+            self.construct_async_arguments(&mut asyncness, &mut decl);
 
             let sig = ast::MethodSig {
                 header: FnHeader {
@@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> {
                     abi,
                     asyncness,
                 },
-                decl: d,
+                decl,
             };
 
             let body = match self.token {
@@ -2319,7 +2319,8 @@ impl<'a> Parser<'a> {
         let ident = self.parse_path_segment_ident()?;
 
         let is_args_start = |token: &token::Token| match *token {
-            token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren) => true,
+            token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren)
+            | token::LArrow => true,
             _ => false,
         };
         let check_args_start = |this: &mut Self| {
@@ -6056,8 +6057,6 @@ impl<'a> Parser<'a> {
                         self.fatal("identifiers may currently not be used for const generics")
                     );
                 } else {
-                    // FIXME(const_generics): this currently conflicts with emplacement syntax
-                    // with negative integer literals.
                     self.parse_literal_maybe_minus()?
                 };
                 let value = AnonConst {
@@ -6475,10 +6474,10 @@ impl<'a> Parser<'a> {
                      -> PResult<'a, ItemInfo> {
         let (ident, mut generics) = self.parse_fn_header()?;
         let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
-        let decl = self.parse_fn_decl(allow_c_variadic)?;
+        let mut decl = self.parse_fn_decl(allow_c_variadic)?;
         generics.where_clause = self.parse_where_clause()?;
         let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
-        self.construct_async_arguments(&mut asyncness, &decl);
+        self.construct_async_arguments(&mut asyncness, &mut decl);
         let header = FnHeader { unsafety, asyncness, constness, abi };
         Ok((ident, ItemKind::Fn(decl, header, generics, body), Some(inner_attrs)))
     }
@@ -6662,9 +6661,9 @@ impl<'a> Parser<'a> {
             let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
             let ident = self.parse_ident()?;
             let mut generics = self.parse_generics()?;
-            let decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
+            let mut decl = self.parse_fn_decl_with_self(|p| p.parse_arg())?;
             generics.where_clause = self.parse_where_clause()?;
-            self.construct_async_arguments(&mut asyncness, &decl);
+            self.construct_async_arguments(&mut asyncness, &mut decl);
             *at_end = true;
             let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
             let header = ast::FnHeader { abi, unsafety, constness, asyncness };
@@ -8710,9 +8709,9 @@ impl<'a> Parser<'a> {
     ///
     /// The arguments of the function are replaced in HIR lowering with the arguments created by
     /// this function and the statements created here are inserted at the top of the closure body.
-    fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &FnDecl) {
+    fn construct_async_arguments(&mut self, asyncness: &mut Spanned<IsAsync>, decl: &mut FnDecl) {
         if let IsAsync::Async { ref mut arguments, .. } = asyncness.node {
-            for (index, input) in decl.inputs.iter().enumerate() {
+            for (index, input) in decl.inputs.iter_mut().enumerate() {
                 let id = ast::DUMMY_NODE_ID;
                 let span = input.pat.span;
 
@@ -8724,8 +8723,10 @@ impl<'a> Parser<'a> {
                 // `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
                 // statement.
                 let (binding_mode, ident, is_simple_pattern) = match input.pat.node {
-                    PatKind::Ident(binding_mode, ident, _) => (binding_mode, ident, true),
-                    _ => (BindingMode::ByValue(Mutability::Immutable), ident, false),
+                    PatKind::Ident(binding_mode @ BindingMode::ByValue(_), ident, _) => {
+                        (binding_mode, ident, true)
+                    }
+                    _ => (BindingMode::ByValue(Mutability::Mutable), ident, false),
                 };
 
                 // Construct an argument representing `__argN: <ty>` to replace the argument of the
@@ -8792,6 +8793,15 @@ impl<'a> Parser<'a> {
                     })
                 };
 
+                // Remove mutability from arguments. If this is not a simple pattern,
+                // those arguments are replaced by `__argN`, so there is no need to do this.
+                if let PatKind::Ident(BindingMode::ByValue(mutability @ Mutability::Mutable), ..) =
+                    &mut input.pat.node
+                {
+                    assert!(is_simple_pattern);
+                    *mutability = Mutability::Immutable;
+                }
+
                 let move_stmt = Stmt { id, node: StmtKind::Local(P(move_local)), span };
                 arguments.push(AsyncArgument { ident, arg, pat_stmt, move_stmt });
             }