Skip to content

Commit b08d5ee

Browse files
committed
ast: Document Pat and Block
1 parent 1debe9d commit b08d5ee

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/libsyntax/ast.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,13 @@ impl PartialEq for MetaItem_ {
535535

536536
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
537537
pub struct Block {
538+
/// Statements in a block
538539
pub stmts: Vec<P<Stmt>>,
540+
/// An expression at the end of the block
541+
/// without a semicolon, if any
539542
pub expr: Option<P<Expr>>,
540543
pub id: NodeId,
544+
/// Unsafety of the block
541545
pub rules: BlockCheckMode,
542546
pub span: Span,
543547
}
@@ -550,8 +554,14 @@ pub struct Pat {
550554
}
551555

552556
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
557+
/// A single field in a struct pattern
558+
///
559+
/// For patterns like `Foo {x, y, z}`, `pat` and `ident` point to the same identifier
560+
/// and `is_shorthand` is true.
553561
pub struct FieldPat {
562+
/// The identifier for the field
554563
pub ident: Ident,
564+
/// The pattern the field is destructured to
555565
pub pat: P<Pat>,
556566
pub is_shorthand: bool,
557567
}
@@ -588,15 +598,23 @@ pub enum Pat_ {
588598
/// "None" means a * pattern where we don't bind the fields to names.
589599
PatEnum(Path, Option<Vec<P<Pat>>>),
590600

601+
/// Destructuring of a struct, e.g. `Foo {x, y, ..}`
602+
/// The `bool` is `true` in the presence of a `..`
591603
PatStruct(Path, Vec<Spanned<FieldPat>>, bool),
604+
/// A tuple pattern (`a, b`)
592605
PatTup(Vec<P<Pat>>),
606+
/// A `box` pattern
593607
PatBox(P<Pat>),
594-
PatRegion(P<Pat>, Mutability), // reference pattern
608+
/// A reference pattern, e.g. `&mut (a, b)`
609+
PatRegion(P<Pat>, Mutability),
610+
/// A literal
595611
PatLit(P<Expr>),
612+
/// A range pattern, e.g. `[1...2]`
596613
PatRange(P<Expr>, P<Expr>),
597614
/// [a, b, ..i, y, z] is represented as:
598615
/// PatVec(box [a, b], Some(i), box [y, z])
599616
PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
617+
/// A macro pattern; pre-expansion
600618
PatMac(Mac),
601619
}
602620

0 commit comments

Comments
 (0)