@@ -501,39 +501,40 @@ impl<'a> Parser<'a> {
501501 token:: Literal ( ..) | token:: Pound => true ,
502502 _ => t. is_whole_expr ( ) ,
503503 } ;
504- let cannot_continue_expr = self . look_ahead ( 1 , token_cannot_continue_expr) ;
505- if cannot_continue_expr {
506- self . bump ( ) ;
507- // Emit the error ...
508- self . struct_span_err (
509- self . token . span ,
510- & format ! ( "unexpected {} after identifier" , self . this_token_descr( ) ) ,
511- )
512- . span_suggestion_short (
513- // Span the `not` plus trailing whitespace to avoid
514- // trailing whitespace after the `!` in our suggestion
515- self . sess . source_map ( ) . span_until_non_whitespace ( lo. to ( self . token . span ) ) ,
516- "use `!` to perform logical negation" ,
517- "!" . to_owned ( ) ,
518- Applicability :: MachineApplicable ,
519- )
520- . emit ( ) ;
521- // —and recover! (just as if we were in the block
522- // for the `token::Not` arm)
523- let e = self . parse_prefix_expr ( None ) ;
524- let ( span, e) = self . interpolated_or_expr_span ( e) ?;
525- ( lo. to ( span) , self . mk_unary ( UnOp :: Not , e) )
526- } else {
504+ if !self . look_ahead ( 1 , token_cannot_continue_expr) {
527505 return self . parse_dot_or_call_expr ( Some ( attrs) ) ;
528506 }
507+
508+ self . recover_not_expr ( lo) ?
529509 }
530- _ => {
531- return self . parse_dot_or_call_expr ( Some ( attrs) ) ;
532- }
510+ _ => return self . parse_dot_or_call_expr ( Some ( attrs) ) ,
533511 } ;
534512 return Ok ( self . mk_expr ( lo. to ( hi) , ex, attrs) ) ;
535513 }
536514
515+ fn recover_not_expr ( & mut self , lo : Span ) -> PResult < ' a , ( Span , ExprKind ) > {
516+ self . bump ( ) ;
517+ // Emit the error ...
518+ self . struct_span_err (
519+ self . token . span ,
520+ & format ! ( "unexpected {} after identifier" , self . this_token_descr( ) ) ,
521+ )
522+ . span_suggestion_short (
523+ // Span the `not` plus trailing whitespace to avoid
524+ // trailing whitespace after the `!` in our suggestion
525+ self . sess . source_map ( ) . span_until_non_whitespace ( lo. to ( self . token . span ) ) ,
526+ "use `!` to perform logical negation" ,
527+ "!" . to_owned ( ) ,
528+ Applicability :: MachineApplicable ,
529+ )
530+ . emit ( ) ;
531+ // —and recover! (just as if we were in the block
532+ // for the `token::Not` arm)
533+ let expr = self . parse_prefix_expr ( None ) ;
534+ let ( span, e) = self . interpolated_or_expr_span ( expr) ?;
535+ Ok ( ( lo. to ( span) , self . mk_unary ( UnOp :: Not , e) ) )
536+ }
537+
537538 /// Returns the span of expr, if it was not interpolated or the span of the interpolated token.
538539 fn interpolated_or_expr_span (
539540 & self ,
0 commit comments