diff options
| author | Takayuki Maeda <takoyaki0316@gmail.com> | 2022-03-10 22:11:00 +0900 |
|---|---|---|
| committer | Takayuki Maeda <takoyaki0316@gmail.com> | 2022-03-10 22:11:00 +0900 |
| commit | 9a6532276ec45e22695f0a012a0782c97bf39a2d (patch) | |
| tree | 70d129a529c2b93bebfc8be07e3f22b67228e4af /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 2db82368574b7b751203418300345a4eb75f1147 (diff) | |
| download | rust-9a6532276ec45e22695f0a012a0782c97bf39a2d.tar.gz rust-9a6532276ec45e22695f0a012a0782c97bf39a2d.zip | |
replace `self.clone()` with `self.create_snapshot_for_diagnostic()`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index df865d77b9b..e160385d3a4 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -704,7 +704,7 @@ impl<'a> Parser<'a> { ExprKind::Path(None, ast::Path { segments, .. }), TokenKind::Ident(kw::For | kw::Loop | kw::While, false), ) if segments.len() == 1 => { - let snapshot = self.clone(); + let snapshot = self.create_snapshot_for_diagnostic(); let label = Label { ident: Ident::from_str_and_span( &format!("'{}", segments[0].ident), @@ -726,7 +726,7 @@ impl<'a> Parser<'a> { } Err(err) => { err.cancel(); - *self = snapshot; + self.restore_snapshot(snapshot); } } } @@ -1886,7 +1886,7 @@ impl<'a> Parser<'a> { lo: Span, attrs: AttrVec, ) -> Option<P<Expr>> { - let mut snapshot = self.clone(); + let mut snapshot = self.create_snapshot_for_diagnostic(); match snapshot.parse_array_or_repeat_expr(attrs, token::Brace) { Ok(arr) => { let hi = snapshot.prev_token.span; @@ -1902,7 +1902,7 @@ impl<'a> Parser<'a> { .note("to define an array, one would use square brackets instead of curly braces") .emit(); - *self = snapshot; + self.restore_snapshot(snapshot); Some(self.mk_expr_err(arr.span)) } Err(e) => { @@ -2370,7 +2370,7 @@ impl<'a> Parser<'a> { if self.token.kind != token::Semi { return None; } - let start_snapshot = self.clone(); + let start_snapshot = self.create_snapshot_for_diagnostic(); let semi_sp = self.token.span; self.bump(); // `;` let mut stmts = @@ -2418,15 +2418,15 @@ impl<'a> Parser<'a> { return Some(err(self, stmts)); } if self.token.kind == token::Comma { - *self = start_snapshot; + self.restore_snapshot(start_snapshot); return None; } - let pre_pat_snapshot = self.clone(); + let pre_pat_snapshot = self.create_snapshot_for_diagnostic(); match self.parse_pat_no_top_alt(None) { Ok(_pat) => { if self.token.kind == token::FatArrow { // Reached arm end. - *self = pre_pat_snapshot; + self.restore_snapshot(pre_pat_snapshot); return Some(err(self, stmts)); } } @@ -2435,21 +2435,21 @@ impl<'a> Parser<'a> { } } - *self = pre_pat_snapshot; + self.restore_snapshot(pre_pat_snapshot); match self.parse_stmt_without_recovery(true, ForceCollect::No) { // Consume statements for as long as possible. Ok(Some(stmt)) => { stmts.push(stmt); } Ok(None) => { - *self = start_snapshot; + self.restore_snapshot(start_snapshot); break; } // We couldn't parse either yet another statement missing it's // enclosing block nor the next arm's pattern or closing brace. Err(stmt_err) => { stmt_err.cancel(); - *self = start_snapshot; + self.restore_snapshot(start_snapshot); break; } } |
