From 5627b0e69cc67b9e05fe050e433503801e8da76c Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Fri, 22 Dec 2023 23:29:20 +0000 Subject: [PATCH] Clairify `ast::PatKind::Struct` docs. The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases. See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. --- compiler/rustc_ast/src/ast.rs | 4 ++-- compiler/rustc_parse/src/parser/pat.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index a121b5a9bed3d..30317c59d376e 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -779,8 +779,8 @@ pub enum PatKind { Ident(BindingAnnotation, Ident, Option>), /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). - /// The `bool` is `true` in the presence of a `..`. - Struct(Option>, Path, ThinVec, /* recovered */ bool), + /// The `bool` is `true` in the presence of a `..` (or when recovered). + Struct(Option>, Path, ThinVec, bool), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). TupleStruct(Option>, Path, ThinVec>), diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 80233eddb9b7f..1a5329affe3fc 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -890,6 +890,7 @@ impl<'a> Parser<'a> { e.span_label(path.span, "while parsing the fields for this pattern"); e.emit(); self.recover_stmt(); + // When recovering, pretend we had `Foo { .. }`, to avoid cascading errors. (ThinVec::new(), true) }); self.bump(); @@ -964,6 +965,8 @@ impl<'a> Parser<'a> { } /// Parses the fields of a struct-like pattern. + /// + /// The `bool` is `true` in the presence of a `..` at the end. fn parse_pat_fields(&mut self) -> PResult<'a, (ThinVec, bool)> { let mut fields = ThinVec::new(); let mut etc = false;