@@ -3438,15 +3438,11 @@ impl Parser {
3438
3438
3439
3439
// parse the argument list and result type of a function
3440
3440
// that may have a self type.
3441
- fn parse_fn_decl_with_self (
3442
- & self ,
3443
- parse_arg_fn :
3444
- & fn ( & Parser ) -> arg
3445
- ) -> ( explicit_self , fn_decl ) {
3446
- fn maybe_parse_explicit_self (
3447
- cnstr : & fn ( v : Mutability ) -> ast:: explicit_self_ ,
3448
- p : & Parser
3449
- ) -> ast:: explicit_self_ {
3441
+ fn parse_fn_decl_with_self ( & self , parse_arg_fn : & fn ( & Parser ) -> arg )
3442
+ -> ( explicit_self , fn_decl ) {
3443
+
3444
+ fn maybe_parse_explicit_self ( cnstr : & fn ( v : Mutability ) -> ast:: explicit_self_ ,
3445
+ p : & Parser ) -> ast:: explicit_self_ {
3450
3446
// We need to make sure it isn't a type
3451
3447
if p. look_ahead ( 1 , |t| token:: is_keyword ( keywords:: Self , t) ) ||
3452
3448
( ( p. look_ahead ( 1 , |t| token:: is_keyword ( keywords:: Const , t) ) ||
@@ -3524,25 +3520,39 @@ impl Parser {
3524
3520
self . span_err ( * self . last_span ,
3525
3521
"mutability declaration not allowed here" ) ;
3526
3522
}
3527
- sty_uniq
3523
+ sty_uniq ( MutImmutable )
3528
3524
} , self )
3529
3525
}
3530
3526
token:: IDENT ( * ) if self . is_self_ident ( ) => {
3531
3527
self . bump ( ) ;
3532
- sty_value
3528
+ sty_value ( MutImmutable )
3533
3529
}
3534
3530
token:: BINOP ( token:: STAR ) => {
3535
3531
// Possibly "*self" or "*mut self" -- not supported. Try to avoid
3536
3532
// emitting cryptic "unexpected token" errors.
3537
3533
self . bump ( ) ;
3538
- if self . token_is_mutability ( self . token ) {
3539
- self . bump ( ) ;
3540
- }
3534
+ let mutability = if self . token_is_mutability ( self . token ) {
3535
+ self . parse_mutability ( )
3536
+ } else { MutImmutable } ;
3541
3537
if self . is_self_ident ( ) {
3542
3538
self . span_err ( * self . span , "cannot pass self by unsafe pointer" ) ;
3543
3539
self . bump ( ) ;
3544
3540
}
3545
- sty_value
3541
+ sty_value ( mutability)
3542
+ }
3543
+ _ if self . token_is_mutability ( self . token ) &&
3544
+ self . look_ahead ( 1 , |t| token:: is_keyword ( keywords:: Self , t) ) => {
3545
+ let mutability = self . parse_mutability ( ) ;
3546
+ self . expect_self_ident ( ) ;
3547
+ sty_value ( mutability)
3548
+ }
3549
+ _ if self . token_is_mutability ( self . token ) &&
3550
+ self . look_ahead ( 1 , |t| * t == token:: TILDE ) &&
3551
+ self . look_ahead ( 2 , |t| token:: is_keyword ( keywords:: Self , t) ) => {
3552
+ let mutability = self . parse_mutability ( ) ;
3553
+ self . bump ( ) ;
3554
+ self . expect_self_ident ( ) ;
3555
+ sty_uniq ( mutability)
3546
3556
}
3547
3557
_ => {
3548
3558
sty_static
0 commit comments