@@ -1576,7 +1576,7 @@ impl<'a> Parser<'a> {
1576
1576
let ident = self . parse_ident ( ) ?;
1577
1577
let mut generics = self . parse_generics ( ) ?;
1578
1578
1579
- let d = self . parse_fn_decl_with_self ( |p : & mut Parser < ' a > | {
1579
+ let mut decl = self . parse_fn_decl_with_self ( |p : & mut Parser < ' a > | {
1580
1580
// This is somewhat dubious; We don't want to allow
1581
1581
// argument names to be left off if there is a
1582
1582
// definition...
@@ -1585,7 +1585,7 @@ impl<'a> Parser<'a> {
1585
1585
p. parse_arg_general ( p. span . rust_2018 ( ) , true , false )
1586
1586
} ) ?;
1587
1587
generics. where_clause = self . parse_where_clause ( ) ?;
1588
- self . construct_async_arguments ( & mut asyncness, & d ) ;
1588
+ self . construct_async_arguments ( & mut asyncness, & mut decl ) ;
1589
1589
1590
1590
let sig = ast:: MethodSig {
1591
1591
header : FnHeader {
@@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> {
1594
1594
abi,
1595
1595
asyncness,
1596
1596
} ,
1597
- decl : d ,
1597
+ decl,
1598
1598
} ;
1599
1599
1600
1600
let body = match self . token {
@@ -6479,10 +6479,10 @@ impl<'a> Parser<'a> {
6479
6479
-> PResult < ' a , ItemInfo > {
6480
6480
let ( ident, mut generics) = self . parse_fn_header ( ) ?;
6481
6481
let allow_c_variadic = abi == Abi :: C && unsafety == Unsafety :: Unsafe ;
6482
- let decl = self . parse_fn_decl ( allow_c_variadic) ?;
6482
+ let mut decl = self . parse_fn_decl ( allow_c_variadic) ?;
6483
6483
generics. where_clause = self . parse_where_clause ( ) ?;
6484
6484
let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
6485
- self . construct_async_arguments ( & mut asyncness, & decl) ;
6485
+ self . construct_async_arguments ( & mut asyncness, & mut decl) ;
6486
6486
let header = FnHeader { unsafety, asyncness, constness, abi } ;
6487
6487
Ok ( ( ident, ItemKind :: Fn ( decl, header, generics, body) , Some ( inner_attrs) ) )
6488
6488
}
@@ -6666,9 +6666,9 @@ impl<'a> Parser<'a> {
6666
6666
let ( constness, unsafety, mut asyncness, abi) = self . parse_fn_front_matter ( ) ?;
6667
6667
let ident = self . parse_ident ( ) ?;
6668
6668
let mut generics = self . parse_generics ( ) ?;
6669
- let decl = self . parse_fn_decl_with_self ( |p| p. parse_arg ( ) ) ?;
6669
+ let mut decl = self . parse_fn_decl_with_self ( |p| p. parse_arg ( ) ) ?;
6670
6670
generics. where_clause = self . parse_where_clause ( ) ?;
6671
- self . construct_async_arguments ( & mut asyncness, & decl) ;
6671
+ self . construct_async_arguments ( & mut asyncness, & mut decl) ;
6672
6672
* at_end = true ;
6673
6673
let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
6674
6674
let header = ast:: FnHeader { abi, unsafety, constness, asyncness } ;
@@ -8714,9 +8714,9 @@ impl<'a> Parser<'a> {
8714
8714
///
8715
8715
/// The arguments of the function are replaced in HIR lowering with the arguments created by
8716
8716
/// this function and the statements created here are inserted at the top of the closure body.
8717
- fn construct_async_arguments ( & mut self , asyncness : & mut Spanned < IsAsync > , decl : & FnDecl ) {
8717
+ fn construct_async_arguments ( & mut self , asyncness : & mut Spanned < IsAsync > , decl : & mut FnDecl ) {
8718
8718
if let IsAsync :: Async { ref mut arguments, .. } = asyncness. node {
8719
- for ( index, input) in decl. inputs . iter ( ) . enumerate ( ) {
8719
+ for ( index, input) in decl. inputs . iter_mut ( ) . enumerate ( ) {
8720
8720
let id = ast:: DUMMY_NODE_ID ;
8721
8721
let span = input. pat . span ;
8722
8722
@@ -8728,8 +8728,10 @@ impl<'a> Parser<'a> {
8728
8728
// `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
8729
8729
// statement.
8730
8730
let ( binding_mode, ident, is_simple_pattern) = match input. pat . node {
8731
- PatKind :: Ident ( binding_mode, ident, _) => ( binding_mode, ident, true ) ,
8732
- _ => ( BindingMode :: ByValue ( Mutability :: Immutable ) , ident, false ) ,
8731
+ PatKind :: Ident ( binding_mode @ BindingMode :: ByValue ( _) , ident, _) => {
8732
+ ( binding_mode, ident, true )
8733
+ }
8734
+ _ => ( BindingMode :: ByValue ( Mutability :: Mutable ) , ident, false ) ,
8733
8735
} ;
8734
8736
8735
8737
// Construct an argument representing `__argN: <ty>` to replace the argument of the
@@ -8796,6 +8798,15 @@ impl<'a> Parser<'a> {
8796
8798
} )
8797
8799
} ;
8798
8800
8801
+ // Remove mutability from arguments. If this is not a simple pattern,
8802
+ // those arguments are replaced by `__argN`, so there is no need to do this.
8803
+ if let PatKind :: Ident ( BindingMode :: ByValue ( mutability @ Mutability :: Mutable ) , ..) =
8804
+ & mut input. pat . node
8805
+ {
8806
+ assert ! ( is_simple_pattern) ;
8807
+ * mutability = Mutability :: Immutable ;
8808
+ }
8809
+
8799
8810
let move_stmt = Stmt { id, node : StmtKind :: Local ( P ( move_local) ) , span } ;
8800
8811
arguments. push ( AsyncArgument { ident, arg, pat_stmt, move_stmt } ) ;
8801
8812
}
0 commit comments