@@ -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 {
@@ -2319,7 +2319,8 @@ impl<'a> Parser<'a> {
2319
2319
let ident = self . parse_path_segment_ident ( ) ?;
2320
2320
2321
2321
let is_args_start = |token : & token:: Token | match * token {
2322
- token:: Lt | token:: BinOp ( token:: Shl ) | token:: OpenDelim ( token:: Paren ) => true ,
2322
+ token:: Lt | token:: BinOp ( token:: Shl ) | token:: OpenDelim ( token:: Paren )
2323
+ | token:: LArrow => true ,
2323
2324
_ => false ,
2324
2325
} ;
2325
2326
let check_args_start = |this : & mut Self | {
@@ -6056,8 +6057,6 @@ impl<'a> Parser<'a> {
6056
6057
self . fatal ( "identifiers may currently not be used for const generics" )
6057
6058
) ;
6058
6059
} else {
6059
- // FIXME(const_generics): this currently conflicts with emplacement syntax
6060
- // with negative integer literals.
6061
6060
self . parse_literal_maybe_minus ( ) ?
6062
6061
} ;
6063
6062
let value = AnonConst {
@@ -6475,10 +6474,10 @@ impl<'a> Parser<'a> {
6475
6474
-> PResult < ' a , ItemInfo > {
6476
6475
let ( ident, mut generics) = self . parse_fn_header ( ) ?;
6477
6476
let allow_c_variadic = abi == Abi :: C && unsafety == Unsafety :: Unsafe ;
6478
- let decl = self . parse_fn_decl ( allow_c_variadic) ?;
6477
+ let mut decl = self . parse_fn_decl ( allow_c_variadic) ?;
6479
6478
generics. where_clause = self . parse_where_clause ( ) ?;
6480
6479
let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
6481
- self . construct_async_arguments ( & mut asyncness, & decl) ;
6480
+ self . construct_async_arguments ( & mut asyncness, & mut decl) ;
6482
6481
let header = FnHeader { unsafety, asyncness, constness, abi } ;
6483
6482
Ok ( ( ident, ItemKind :: Fn ( decl, header, generics, body) , Some ( inner_attrs) ) )
6484
6483
}
@@ -6662,9 +6661,9 @@ impl<'a> Parser<'a> {
6662
6661
let ( constness, unsafety, mut asyncness, abi) = self . parse_fn_front_matter ( ) ?;
6663
6662
let ident = self . parse_ident ( ) ?;
6664
6663
let mut generics = self . parse_generics ( ) ?;
6665
- let decl = self . parse_fn_decl_with_self ( |p| p. parse_arg ( ) ) ?;
6664
+ let mut decl = self . parse_fn_decl_with_self ( |p| p. parse_arg ( ) ) ?;
6666
6665
generics. where_clause = self . parse_where_clause ( ) ?;
6667
- self . construct_async_arguments ( & mut asyncness, & decl) ;
6666
+ self . construct_async_arguments ( & mut asyncness, & mut decl) ;
6668
6667
* at_end = true ;
6669
6668
let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
6670
6669
let header = ast:: FnHeader { abi, unsafety, constness, asyncness } ;
@@ -8710,9 +8709,9 @@ impl<'a> Parser<'a> {
8710
8709
///
8711
8710
/// The arguments of the function are replaced in HIR lowering with the arguments created by
8712
8711
/// this function and the statements created here are inserted at the top of the closure body.
8713
- fn construct_async_arguments ( & mut self , asyncness : & mut Spanned < IsAsync > , decl : & FnDecl ) {
8712
+ fn construct_async_arguments ( & mut self , asyncness : & mut Spanned < IsAsync > , decl : & mut FnDecl ) {
8714
8713
if let IsAsync :: Async { ref mut arguments, .. } = asyncness. node {
8715
- for ( index, input) in decl. inputs . iter ( ) . enumerate ( ) {
8714
+ for ( index, input) in decl. inputs . iter_mut ( ) . enumerate ( ) {
8716
8715
let id = ast:: DUMMY_NODE_ID ;
8717
8716
let span = input. pat . span ;
8718
8717
@@ -8724,8 +8723,10 @@ impl<'a> Parser<'a> {
8724
8723
// `let <pat> = __argN;` statement, instead just adding a `let <pat> = <pat>;`
8725
8724
// statement.
8726
8725
let ( binding_mode, ident, is_simple_pattern) = match input. pat . node {
8727
- PatKind :: Ident ( binding_mode, ident, _) => ( binding_mode, ident, true ) ,
8728
- _ => ( BindingMode :: ByValue ( Mutability :: Immutable ) , ident, false ) ,
8726
+ PatKind :: Ident ( binding_mode @ BindingMode :: ByValue ( _) , ident, _) => {
8727
+ ( binding_mode, ident, true )
8728
+ }
8729
+ _ => ( BindingMode :: ByValue ( Mutability :: Mutable ) , ident, false ) ,
8729
8730
} ;
8730
8731
8731
8732
// Construct an argument representing `__argN: <ty>` to replace the argument of the
@@ -8792,6 +8793,15 @@ impl<'a> Parser<'a> {
8792
8793
} )
8793
8794
} ;
8794
8795
8796
+ // Remove mutability from arguments. If this is not a simple pattern,
8797
+ // those arguments are replaced by `__argN`, so there is no need to do this.
8798
+ if let PatKind :: Ident ( BindingMode :: ByValue ( mutability @ Mutability :: Mutable ) , ..) =
8799
+ & mut input. pat . node
8800
+ {
8801
+ assert ! ( is_simple_pattern) ;
8802
+ * mutability = Mutability :: Immutable ;
8803
+ }
8804
+
8795
8805
let move_stmt = Stmt { id, node : StmtKind :: Local ( P ( move_local) ) , span } ;
8796
8806
arguments. push ( AsyncArgument { ident, arg, pat_stmt, move_stmt } ) ;
8797
8807
}
0 commit comments