Skip to content

Commit

Permalink
Clairify ast::PatKind::Struct docs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aDotInTheVoid committed Dec 22, 2023
1 parent 3d0e6be commit 5627b0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ pub enum PatKind {
Ident(BindingAnnotation, Ident, Option<P<Pat>>),

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

/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<PatField>, bool)> {
let mut fields = ThinVec::new();
let mut etc = false;
Expand Down

0 comments on commit 5627b0e

Please sign in to comment.