Skip to content

Commit 5627b0e

Browse files
committed
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.
1 parent 3d0e6be commit 5627b0e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

compiler/rustc_ast/src/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ pub enum PatKind {
779779
Ident(BindingAnnotation, Ident, Option<P<Pat>>),
780780

781781
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
782-
/// The `bool` is `true` in the presence of a `..`.
783-
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, /* recovered */ bool),
782+
/// The `bool` is `true` in the presence of a `..` (or when recovered).
783+
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, bool),
784784

785785
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
786786
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),

compiler/rustc_parse/src/parser/pat.rs

+3
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ impl<'a> Parser<'a> {
890890
e.span_label(path.span, "while parsing the fields for this pattern");
891891
e.emit();
892892
self.recover_stmt();
893+
// When recovering, pretend we had `Foo { .. }`, to avoid cascading errors.
893894
(ThinVec::new(), true)
894895
});
895896
self.bump();
@@ -964,6 +965,8 @@ impl<'a> Parser<'a> {
964965
}
965966

966967
/// Parses the fields of a struct-like pattern.
968+
///
969+
/// The `bool` is `true` in the presence of a `..` at the end.
967970
fn parse_pat_fields(&mut self) -> PResult<'a, (ThinVec<PatField>, bool)> {
968971
let mut fields = ThinVec::new();
969972
let mut etc = false;

0 commit comments

Comments
 (0)