@@ -1754,16 +1754,7 @@ impl<'a> Parser<'a> {
17541754 } else {
17551755 debug ! ( "parse_arg_general ident_to_pat" ) ;
17561756
1757- // If we see `ident :`, then we know that the argument is not just of the
1758- // form `type`, which means we won't need to recover from parsing a
1759- // pattern and so we don't need to store a parser snapshot.
1760- let parser_snapshot_before_pat = if
1761- self . look_ahead ( 1 , |t| t. is_ident ( ) ) &&
1762- self . look_ahead ( 2 , |t| t == & token:: Colon ) {
1763- None
1764- } else {
1765- Some ( self . clone ( ) )
1766- } ;
1757+ let parser_snapshot_before_pat = self . clone ( ) ;
17671758
17681759 // We're going to try parsing the argument as a pattern (even though it's not
17691760 // allowed). This way we can provide better errors to the user.
@@ -1777,7 +1768,7 @@ impl<'a> Parser<'a> {
17771768 Ok ( ( pat, ty) ) => {
17781769 let mut err = self . diagnostic ( ) . struct_span_err_with_code (
17791770 pat. span ,
1780- "patterns aren't allowed in trait methods" ,
1771+ "patterns aren't allowed in methods without bodies " ,
17811772 DiagnosticId :: Error ( "E0642" . into ( ) ) ,
17821773 ) ;
17831774 err. span_suggestion_short_with_applicability (
@@ -1799,7 +1790,7 @@ impl<'a> Parser<'a> {
17991790 err. cancel ( ) ;
18001791 // Recover from attempting to parse the argument as a pattern. This means
18011792 // the type is alone, with no name, e.g. `fn foo(u32)`.
1802- mem:: replace ( self , parser_snapshot_before_pat. unwrap ( ) ) ;
1793+ mem:: replace ( self , parser_snapshot_before_pat) ;
18031794 debug ! ( "parse_arg_general ident_to_pat" ) ;
18041795 let ident = Ident :: new ( keywords:: Invalid . name ( ) , self . prev_span ) ;
18051796 let ty = self . parse_ty ( ) ?;
0 commit comments