@@ -481,7 +481,7 @@ impl<'a> Parser<'a> {
481
481
// fn foo() -> Foo {
482
482
// field: value,
483
483
// }
484
- let mut snapshot = self . clone ( ) ;
484
+ let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
485
485
let path =
486
486
Path { segments : vec ! [ ] , span : self . prev_token . span . shrink_to_lo ( ) , tokens : None } ;
487
487
let struct_expr = snapshot. parse_struct_expr ( None , path, AttrVec :: new ( ) , false ) ;
@@ -507,7 +507,7 @@ impl<'a> Parser<'a> {
507
507
Applicability :: MaybeIncorrect ,
508
508
)
509
509
. emit ( ) ;
510
- * self = snapshot;
510
+ self . restore_snapshot ( snapshot) ;
511
511
let mut tail = self . mk_block (
512
512
vec ! [ self . mk_stmt_err( expr. span) ] ,
513
513
s,
@@ -721,7 +721,7 @@ impl<'a> Parser<'a> {
721
721
/// angle brackets.
722
722
pub ( super ) fn check_turbofish_missing_angle_brackets ( & mut self , segment : & mut PathSegment ) {
723
723
if token:: ModSep == self . token . kind && segment. args . is_none ( ) {
724
- let snapshot = self . clone ( ) ;
724
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
725
725
self . bump ( ) ;
726
726
let lo = self . token . span ;
727
727
match self . parse_angle_args ( None ) {
@@ -755,14 +755,14 @@ impl<'a> Parser<'a> {
755
755
. emit ( ) ;
756
756
} else {
757
757
// This doesn't look like an invalid turbofish, can't recover parse state.
758
- * self = snapshot;
758
+ self . restore_snapshot ( snapshot) ;
759
759
}
760
760
}
761
761
Err ( err) => {
762
762
// We couldn't parse generic parameters, unlikely to be a turbofish. Rely on
763
763
// generic parse error instead.
764
764
err. cancel ( ) ;
765
- * self = snapshot;
765
+ self . restore_snapshot ( snapshot) ;
766
766
}
767
767
}
768
768
}
@@ -868,7 +868,7 @@ impl<'a> Parser<'a> {
868
868
// `x == y < z`
869
869
( BinOpKind :: Eq , AssocOp :: Less | AssocOp :: LessEqual | AssocOp :: Greater | AssocOp :: GreaterEqual ) => {
870
870
// Consume `z`/outer-op-rhs.
871
- let snapshot = self . clone ( ) ;
871
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
872
872
match self . parse_expr ( ) {
873
873
Ok ( r2) => {
874
874
// We are sure that outer-op-rhs could be consumed, the suggestion is
@@ -878,14 +878,14 @@ impl<'a> Parser<'a> {
878
878
}
879
879
Err ( expr_err) => {
880
880
expr_err. cancel ( ) ;
881
- * self = snapshot;
881
+ self . restore_snapshot ( snapshot) ;
882
882
false
883
883
}
884
884
}
885
885
}
886
886
// `x > y == z`
887
887
( BinOpKind :: Lt | BinOpKind :: Le | BinOpKind :: Gt | BinOpKind :: Ge , AssocOp :: Equal ) => {
888
- let snapshot = self . clone ( ) ;
888
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
889
889
// At this point it is always valid to enclose the lhs in parentheses, no
890
890
// further checks are necessary.
891
891
match self . parse_expr ( ) {
@@ -895,7 +895,7 @@ impl<'a> Parser<'a> {
895
895
}
896
896
Err ( expr_err) => {
897
897
expr_err. cancel ( ) ;
898
- * self = snapshot;
898
+ self . restore_snapshot ( snapshot) ;
899
899
false
900
900
}
901
901
}
@@ -960,7 +960,7 @@ impl<'a> Parser<'a> {
960
960
|| outer_op. node == AssocOp :: Greater
961
961
{
962
962
if outer_op. node == AssocOp :: Less {
963
- let snapshot = self . clone ( ) ;
963
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
964
964
self . bump ( ) ;
965
965
// So far we have parsed `foo<bar<`, consume the rest of the type args.
966
966
let modifiers =
@@ -972,15 +972,15 @@ impl<'a> Parser<'a> {
972
972
{
973
973
// We don't have `foo< bar >(` or `foo< bar >::`, so we rewind the
974
974
// parser and bail out.
975
- * self = snapshot . clone ( ) ;
975
+ self . restore_snapshot ( snapshot ) ;
976
976
}
977
977
}
978
978
return if token:: ModSep == self . token . kind {
979
979
// We have some certainty that this was a bad turbofish at this point.
980
980
// `foo< bar >::`
981
981
suggest ( & mut err) ;
982
982
983
- let snapshot = self . clone ( ) ;
983
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
984
984
self . bump ( ) ; // `::`
985
985
986
986
// Consume the rest of the likely `foo<bar>::new()` or return at `foo<bar>`.
@@ -997,7 +997,7 @@ impl<'a> Parser<'a> {
997
997
expr_err. cancel ( ) ;
998
998
// Not entirely sure now, but we bubble the error up with the
999
999
// suggestion.
1000
- * self = snapshot;
1000
+ self . restore_snapshot ( snapshot) ;
1001
1001
Err ( err)
1002
1002
}
1003
1003
}
@@ -1051,7 +1051,7 @@ impl<'a> Parser<'a> {
1051
1051
}
1052
1052
1053
1053
fn consume_fn_args ( & mut self ) -> Result < ( ) , ( ) > {
1054
- let snapshot = self . clone ( ) ;
1054
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
1055
1055
self . bump ( ) ; // `(`
1056
1056
1057
1057
// Consume the fn call arguments.
@@ -1061,7 +1061,7 @@ impl<'a> Parser<'a> {
1061
1061
1062
1062
if self . token . kind == token:: Eof {
1063
1063
// Not entirely sure that what we consumed were fn arguments, rollback.
1064
- * self = snapshot;
1064
+ self . restore_snapshot ( snapshot) ;
1065
1065
Err ( ( ) )
1066
1066
} else {
1067
1067
// 99% certain that the suggestion is correct, continue parsing.
@@ -2002,12 +2002,12 @@ impl<'a> Parser<'a> {
2002
2002
}
2003
2003
2004
2004
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 ( ) ;
2006
2006
let param = match self . parse_const_param ( vec ! [ ] ) {
2007
2007
Ok ( param) => param,
2008
2008
Err ( err) => {
2009
2009
err. cancel ( ) ;
2010
- * self = snapshot;
2010
+ self . restore_snapshot ( snapshot) ;
2011
2011
return None ;
2012
2012
}
2013
2013
} ;
@@ -2099,7 +2099,7 @@ impl<'a> Parser<'a> {
2099
2099
// We perform these checks and early return to avoid taking a snapshot unnecessarily.
2100
2100
return Err ( err) ;
2101
2101
}
2102
- let snapshot = self . clone ( ) ;
2102
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
2103
2103
if is_op_or_dot {
2104
2104
self . bump ( ) ;
2105
2105
}
@@ -2131,7 +2131,7 @@ impl<'a> Parser<'a> {
2131
2131
err. cancel ( ) ;
2132
2132
}
2133
2133
}
2134
- * self = snapshot;
2134
+ self . restore_snapshot ( snapshot) ;
2135
2135
Err ( err)
2136
2136
}
2137
2137
@@ -2191,7 +2191,7 @@ impl<'a> Parser<'a> {
2191
2191
let span = self . token . span ;
2192
2192
// We only emit "unexpected `:`" error here if we can successfully parse the
2193
2193
// whole pattern correctly in that case.
2194
- let snapshot = self . clone ( ) ;
2194
+ let snapshot = self . create_snapshot_for_diagnostic ( ) ;
2195
2195
2196
2196
// Create error for "unexpected `:`".
2197
2197
match self . expected_one_of_not_found ( & [ ] , & [ ] ) {
@@ -2203,7 +2203,7 @@ impl<'a> Parser<'a> {
2203
2203
// reasonable error.
2204
2204
inner_err. cancel ( ) ;
2205
2205
err. cancel ( ) ;
2206
- * self = snapshot;
2206
+ self . restore_snapshot ( snapshot) ;
2207
2207
}
2208
2208
Ok ( mut pat) => {
2209
2209
// We've parsed the rest of the pattern.
@@ -2282,7 +2282,7 @@ impl<'a> Parser<'a> {
2282
2282
}
2283
2283
_ => {
2284
2284
// Carry on as if we had not done anything. This should be unreachable.
2285
- * self = snapshot;
2285
+ self . restore_snapshot ( snapshot) ;
2286
2286
}
2287
2287
} ;
2288
2288
first_pat
0 commit comments