@@ -1754,16 +1754,7 @@ impl<'a> Parser<'a> {
1754
1754
} else {
1755
1755
debug ! ( "parse_arg_general ident_to_pat" ) ;
1756
1756
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 ( ) ;
1767
1758
1768
1759
// We're going to try parsing the argument as a pattern (even though it's not
1769
1760
// allowed). This way we can provide better errors to the user.
@@ -1777,7 +1768,7 @@ impl<'a> Parser<'a> {
1777
1768
Ok ( ( pat, ty) ) => {
1778
1769
let mut err = self . diagnostic ( ) . struct_span_err_with_code (
1779
1770
pat. span ,
1780
- "patterns aren't allowed in trait methods" ,
1771
+ "patterns aren't allowed in methods without bodies " ,
1781
1772
DiagnosticId :: Error ( "E0642" . into ( ) ) ,
1782
1773
) ;
1783
1774
err. span_suggestion_short_with_applicability (
@@ -1799,7 +1790,7 @@ impl<'a> Parser<'a> {
1799
1790
err. cancel ( ) ;
1800
1791
// Recover from attempting to parse the argument as a pattern. This means
1801
1792
// 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) ;
1803
1794
debug ! ( "parse_arg_general ident_to_pat" ) ;
1804
1795
let ident = Ident :: new ( keywords:: Invalid . name ( ) , self . prev_span ) ;
1805
1796
let ty = self . parse_ty ( ) ?;
0 commit comments