Skip to content

Commit 1fb9603

Browse files
committed
Auto merge of #98020 - TaKO8Ki:use-create-snapshot-for-diagnostic-in-rustc-expand, r=Dylan-DPC
Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser` Use [`create_snapshot_for_diagnostic`](https://github.com/rust-lang/rust/blob/cd119057160cedea245aa2679add56723f3dc784/compiler/rustc_parse/src/parser/diagnostics.rs#L214-L223) I implemented in #94731 instead of `clone` to avoid duplicate unclosed delims errors being emitted when the `Parser` is dropped. I missed this one in #95068.
2 parents 546c826 + 84a13a2 commit 1fb9603

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a> ParserAnyMacro<'a> {
123123
is_trailing_mac,
124124
is_local,
125125
} = *self;
126-
let snapshot = &mut parser.clone();
126+
let snapshot = &mut parser.create_snapshot_for_diagnostic();
127127
let fragment = match parse_ast_fragment(parser, kind) {
128128
Ok(f) => f,
129129
Err(err) => {

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ struct InInTypo {
336336
// SnapshotParser is used to create a snapshot of the parser
337337
// without causing duplicate errors being emitted when the `Parser`
338338
// is dropped.
339-
pub(super) struct SnapshotParser<'a> {
339+
pub struct SnapshotParser<'a> {
340340
parser: Parser<'a>,
341341
unclosed_delims: Vec<UnmatchedBrace>,
342342
}
@@ -392,7 +392,7 @@ impl<'a> Parser<'a> {
392392
}
393393

394394
/// Create a snapshot of the `Parser`.
395-
pub(super) fn create_snapshot_for_diagnostic(&self) -> SnapshotParser<'a> {
395+
pub fn create_snapshot_for_diagnostic(&self) -> SnapshotParser<'a> {
396396
let mut snapshot = self.clone();
397397
let unclosed_delims = self.unclosed_delims.clone();
398398
// Clear `unclosed_delims` in snapshot to avoid

0 commit comments

Comments
 (0)