@@ -481,7 +481,7 @@ impl<'a> Parser<'a> {
481481 // fn foo() -> Foo {
482482 // field: value,
483483 // }
484- let mut snapshot = self . clone ( ) ;
484+ let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
485485 let path =
486486 Path { segments : vec ! [ ] , span : self . prev_token . span . shrink_to_lo ( ) , tokens : None } ;
487487 let struct_expr = snapshot. parse_struct_expr ( None , path, AttrVec :: new ( ) , false ) ;
@@ -507,7 +507,7 @@ impl<'a> Parser<'a> {
507507 Applicability :: MaybeIncorrect ,
508508 )
509509 . emit ( ) ;
510- * self = snapshot;
510+ self . restore_snapshot ( snapshot) ;
511511 let mut tail = self . mk_block (
512512 vec ! [ self . mk_stmt_err( expr. span) ] ,
513513 s,
@@ -721,7 +721,7 @@ impl<'a> Parser<'a> {
721721 /// angle brackets.
722722 pub ( super ) fn check_turbofish_missing_angle_brackets ( & mut self , segment : & mut PathSegment ) {
723723 if token:: ModSep == self . token . kind && segment. args . is_none ( ) {
724- let snapshot = self . clone ( ) ;
724+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
725725 self . bump ( ) ;
726726 let lo = self . token . span ;
727727 match self . parse_angle_args ( None ) {
@@ -755,14 +755,14 @@ impl<'a> Parser<'a> {
755755 . emit ( ) ;
756756 } else {
757757 // This doesn't look like an invalid turbofish, can't recover parse state.
758- * self = snapshot;
758+ self . restore_snapshot ( snapshot) ;
759759 }
760760 }
761761 Err ( err) => {
762762 // We couldn't parse generic parameters, unlikely to be a turbofish. Rely on
763763 // generic parse error instead.
764764 err. cancel ( ) ;
765- * self = snapshot;
765+ self . restore_snapshot ( snapshot) ;
766766 }
767767 }
768768 }
@@ -868,7 +868,7 @@ impl<'a> Parser<'a> {
868868 // `x == y < z`
869869 ( BinOpKind :: Eq , AssocOp :: Less | AssocOp :: LessEqual | AssocOp :: Greater | AssocOp :: GreaterEqual ) => {
870870 // Consume `z`/outer-op-rhs.
871- let snapshot = self . clone ( ) ;
871+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
872872 match self . parse_expr ( ) {
873873 Ok ( r2) => {
874874 // We are sure that outer-op-rhs could be consumed, the suggestion is
@@ -878,14 +878,14 @@ impl<'a> Parser<'a> {
878878 }
879879 Err ( expr_err) => {
880880 expr_err. cancel ( ) ;
881- * self = snapshot;
881+ self . restore_snapshot ( snapshot) ;
882882 false
883883 }
884884 }
885885 }
886886 // `x > y == z`
887887 ( BinOpKind :: Lt | BinOpKind :: Le | BinOpKind :: Gt | BinOpKind :: Ge , AssocOp :: Equal ) => {
888- let snapshot = self . clone ( ) ;
888+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
889889 // At this point it is always valid to enclose the lhs in parentheses, no
890890 // further checks are necessary.
891891 match self . parse_expr ( ) {
@@ -895,7 +895,7 @@ impl<'a> Parser<'a> {
895895 }
896896 Err ( expr_err) => {
897897 expr_err. cancel ( ) ;
898- * self = snapshot;
898+ self . restore_snapshot ( snapshot) ;
899899 false
900900 }
901901 }
@@ -960,7 +960,7 @@ impl<'a> Parser<'a> {
960960 || outer_op. node == AssocOp :: Greater
961961 {
962962 if outer_op. node == AssocOp :: Less {
963- let snapshot = self . clone ( ) ;
963+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
964964 self . bump ( ) ;
965965 // So far we have parsed `foo<bar<`, consume the rest of the type args.
966966 let modifiers =
@@ -972,15 +972,15 @@ impl<'a> Parser<'a> {
972972 {
973973 // We don't have `foo< bar >(` or `foo< bar >::`, so we rewind the
974974 // parser and bail out.
975- * self = snapshot . clone ( ) ;
975+ self . restore_snapshot ( snapshot ) ;
976976 }
977977 }
978978 return if token:: ModSep == self . token . kind {
979979 // We have some certainty that this was a bad turbofish at this point.
980980 // `foo< bar >::`
981981 suggest ( & mut err) ;
982982
983- let snapshot = self . clone ( ) ;
983+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
984984 self . bump ( ) ; // `::`
985985
986986 // Consume the rest of the likely `foo<bar>::new()` or return at `foo<bar>`.
@@ -997,7 +997,7 @@ impl<'a> Parser<'a> {
997997 expr_err. cancel ( ) ;
998998 // Not entirely sure now, but we bubble the error up with the
999999 // suggestion.
1000- * self = snapshot;
1000+ self . restore_snapshot ( snapshot) ;
10011001 Err ( err)
10021002 }
10031003 }
@@ -1051,7 +1051,7 @@ impl<'a> Parser<'a> {
10511051 }
10521052
10531053 fn consume_fn_args ( & mut self ) -> Result < ( ) , ( ) > {
1054- let snapshot = self . clone ( ) ;
1054+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
10551055 self . bump ( ) ; // `(`
10561056
10571057 // Consume the fn call arguments.
@@ -1061,7 +1061,7 @@ impl<'a> Parser<'a> {
10611061
10621062 if self . token . kind == token:: Eof {
10631063 // Not entirely sure that what we consumed were fn arguments, rollback.
1064- * self = snapshot;
1064+ self . restore_snapshot ( snapshot) ;
10651065 Err ( ( ) )
10661066 } else {
10671067 // 99% certain that the suggestion is correct, continue parsing.
@@ -2002,12 +2002,12 @@ impl<'a> Parser<'a> {
20022002 }
20032003
20042004 fn recover_const_param_decl ( & mut self , ty_generics : Option < & Generics > ) -> Option < GenericArg > {
2005- let snapshot = self . clone ( ) ;
2005+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
20062006 let param = match self . parse_const_param ( vec ! [ ] ) {
20072007 Ok ( param) => param,
20082008 Err ( err) => {
20092009 err. cancel ( ) ;
2010- * self = snapshot;
2010+ self . restore_snapshot ( snapshot) ;
20112011 return None ;
20122012 }
20132013 } ;
@@ -2099,7 +2099,7 @@ impl<'a> Parser<'a> {
20992099 // We perform these checks and early return to avoid taking a snapshot unnecessarily.
21002100 return Err ( err) ;
21012101 }
2102- let snapshot = self . clone ( ) ;
2102+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
21032103 if is_op_or_dot {
21042104 self . bump ( ) ;
21052105 }
@@ -2131,7 +2131,7 @@ impl<'a> Parser<'a> {
21312131 err. cancel ( ) ;
21322132 }
21332133 }
2134- * self = snapshot;
2134+ self . restore_snapshot ( snapshot) ;
21352135 Err ( err)
21362136 }
21372137
@@ -2191,7 +2191,7 @@ impl<'a> Parser<'a> {
21912191 let span = self . token . span ;
21922192 // We only emit "unexpected `:`" error here if we can successfully parse the
21932193 // whole pattern correctly in that case.
2194- let snapshot = self . clone ( ) ;
2194+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
21952195
21962196 // Create error for "unexpected `:`".
21972197 match self . expected_one_of_not_found ( & [ ] , & [ ] ) {
@@ -2203,7 +2203,7 @@ impl<'a> Parser<'a> {
22032203 // reasonable error.
22042204 inner_err. cancel ( ) ;
22052205 err. cancel ( ) ;
2206- * self = snapshot;
2206+ self . restore_snapshot ( snapshot) ;
22072207 }
22082208 Ok ( mut pat) => {
22092209 // We've parsed the rest of the pattern.
@@ -2282,7 +2282,7 @@ impl<'a> Parser<'a> {
22822282 }
22832283 _ => {
22842284 // Carry on as if we had not done anything. This should be unreachable.
2285- * self = snapshot;
2285+ self . restore_snapshot ( snapshot) ;
22862286 }
22872287 } ;
22882288 first_pat
0 commit comments