Expand description
The Rust abstract syntax tree module.
This module contains common structures forming the language AST.
Two main entities in the module are Item
(which represents an AST element with
additional metadata), and ItemKind
(which represents a concrete type and contains
information specific to the type of the item).
Other module items worth mentioning:
Ty
andTyKind
: A parsed Rust type.Expr
andExprKind
: A parsed Rust expression.Pat
andPatKind
: A parsed Rust pattern. Patterns are often dual to expressions.Stmt
andStmtKind
: An executable action that does not return a value.FnDecl
,FnHeader
andParam
: Metadata associated with a function declaration.Generics
,GenericParam
,WhereClause
: Metadata associated with generic parameters.EnumDef
andVariant
: Enum declaration.MetaItemLit
andLitKind
: Literal expressions.MacroDef
,MacStmtStyle
,MacCall
: Macro definition and invocation.Attribute
: Metadata associated with item.UnOp
,BinOp
, andBinOpKind
: Unary and binary operators.
Re-exports§
pub use crate::node_id::CRATE_NODE_ID;
pub use crate::node_id::DUMMY_NODE_ID;
pub use crate::node_id::NodeId;
pub use GenericArgs::*;
pub use UnsafeSource::*;
pub use crate::format::*;
Modules§
Structs§
- Angle
Bracketed Args - A path like
Foo<'a, T>
. - Anon
Const - A constant (expression) that’s not an item or associated item,
but needs its own
DefId
for type-checking, const-eval, etc. These are usually found nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also used to define explicit discriminant values for enum variants. - Arm
- An arm of a ‘match’.
- Assoc
Item Constraint - A constraint on an associated item.
- AttrId
- Attr
Item - Attribute
- A syntax-level representation of an attribute.
- Bare
FnTy - Binding
Mode - The mode of a binding (
mut
,ref mut
, etc). Used for both the explicit binding annotations given in the HIR for a binding and the final binding mode that we infer after type inference/match ergonomics..0
is the by-reference mode (ref
,ref mut
, or by value),.1
is the mutability of the binding. - Block
- A block (
{ .. }
). - Closure
- Const
Item - Crate
- Delegation
- Delegation
Mac - Delim
Args - Delimited arguments, as used in
#[attr()/[]/{}]
ormac!()/[]/{}
. - EnumDef
- Expr
- An expression.
- Expr
Field - A single field in a struct expression, e.g.
x: value
andy
inFoo { x: value, y }
. - Field
Def - Field definition in a struct, variant or union.
- Fn
- FnContract
- FnDecl
- A signature (not the body) of a function declaration.
- FnHeader
- A function header.
- FnSig
- Represents a function’s signature in a trait declaration, trait implementation, or free function.
- Foreign
Mod - Foreign module declaration.
- Generic
Param - Generics
- Represents lifetime, type and const parameters attached to a declaration of a function, enum, trait, etc.
- Impl
- Inline
Asm - Inline assembly.
- Inline
AsmOptions - Inline
AsmSym - Inline assembly symbol operands get their own AST node that is somewhat
similar to
AnonConst
. - Item
- An item definition.
- Label
- A “Label” is an identifier of some point in sources, e.g. in the following code:
- Lifetime
- A “Lifetime” is an annotation of the scope in which variable
can be used, e.g.
'a
in&'a i32
. - Local
- Local represents a
let
statement, e.g.,let <pat>:<ty> = <expr>;
. - MacCall
- Represents a macro invocation. The
path
indicates which macro is being invoked, and theargs
are arguments passed to it. - MacCall
Stmt - Macro
Def - Represents a macro definition.
- Meta
Item - A semantic representation of a meta item. A meta item is a slightly restricted form of an attribute – it can only contain expressions in certain leaf positions, rather than arbitrary token streams – that is used for most built-in attributes.
- Meta
Item Lit - A literal in a meta item.
- Method
Call - A method call (e.g.
x.foo::<Bar, Baz>(a, b, c)
). - ModSpans
- MutTy
- Normal
Attr - Param
- A parameter in a function header.
- Parenthesized
Args - A path like
Foo(A, B) -> C
. - Pat
- A match pattern.
- PatField
- A single field in a struct pattern.
- Path
- A “Path” is essentially Rust’s notion of a name.
- Path
Segment - A segment of a path: an identifier, an optional lifetime, and a set of types.
- Poly
Trait Ref - QSelf
- The explicit
Self
type in a “qualified path”. The actual path, including the trait and the associated item, is stored separately.position
represents the index of the associated item qualified with thisSelf
type. - Static
Item - Stmt
- A statement. No
attrs
ortokens
fields because eachStmtKind
variant contains an AST node with those fields. (Except forStmtKind::Empty
, which never has attrs or tokens) - StrLit
- Similar to
MetaItemLit
, but restricted to string literals. - Struct
Expr - Trait
- Trait
Bound Modifiers - Modifiers on a trait bound like
~const
,?
and!
. - Trait
Ref TraitRef
s appear in impls.- Ty
- TyAlias
- TyAlias
Where Clause - The location of a where clause on a
TyAlias
(Span
) and whether there was awhere
keyword (bool
). This is split out fromWhereClause
, since there are two locations for where clause on type aliases, but their predicates are concatenated together. - TyAlias
Where Clauses - The span information for the two where clauses on a
TyAlias
. - TyPat
- A pattern type pattern.
- Unsafe
Binder Ty - UseTree
- A tree of paths sharing common prefixes.
Used in
use
items both at top-level and inside of braces in import groups. - Variant
- Enum variant.
- Visibility
- Where
Bound Predicate - A type bound.
- Where
Clause - A where-clause in a definition.
- Where
EqPredicate - An equality predicate (unsupported).
- Where
Predicate - A single predicate in a where-clause.
- Where
Region Predicate - A lifetime predicate.
Enums§
- Angle
Bracketed Arg - Either an argument for a generic parameter or a constraint on an associated item.
- AsmMacro
- Assoc
Item Constraint Kind - The kind of associated item constraint.
- Assoc
Item Kind - Represents associated item kinds.
- Attr
Args - Arguments passed to an attribute macro.
- Attr
Kind - Attr
Style - Distinguishes between
Attribute
s that decorate items and Attributes that are contained as statements within items. These two cases need to be distinguished for pretty-printing. - BinOp
Kind - Block
Check Mode - Borrow
Kind - The kind of borrow in an
AddrOf
expression, e.g.,&place
or&raw const place
. - Bound
Asyncness - The asyncness of a trait bound.
- Bound
Constness - The constness of a trait bound.
- Bound
Polarity - The polarity of a trait bound.
- ByRef
- Capture
By - A capture clause used in closures and
async
blocks. - Closure
Binder - Closure lifetime binder,
for<'a, 'b>
infor<'a, 'b> |_: &'a (), _: &'b ()|
. - Const
- Coroutine
Kind - Describes what kind of coroutine markers, if any, a function has.
- Defaultness
- Item defaultness. For details see the RFC #2532.
- Expr
Kind - Extern
extern
qualifier on a function item or function type.- FloatTy
- FnRetTy
- ForLoop
Kind - Used to differentiate between
for
loops andfor await
loops. - Foreign
Item Kind - An item in
extern
block. - GenBlock
Kind - Used to differentiate between
async {}
blocks andgen {}
blocks. - Generic
Arg - Concrete argument in the sequence of generic args.
- Generic
Args - The generic arguments and associated item constraints of a path segment.
- Generic
Bound - Generic
Param Kind - Impl
Polarity - Inline
- Inline
AsmOperand - Inline assembly operand.
- Inline
AsmReg OrReg Class - Inline assembly operand explicit register or register class.
- Inline
AsmTemplate Piece - IntTy
- IsAuto
- Is the trait definition an auto trait?
- Item
Kind - LitFloat
Type - Type of the float literal based on provided suffix.
- LitInt
Type - Type of the integer literal based on provided suffix.
- LitKind
- This type is used within both
ast::MetaItemLit
andhir::Lit
. - Local
Kind - MacStmt
Style - Match
Kind - The kind of match expression
- Meta
Item Inner - Values inside meta item lists.
- Meta
Item Kind - The meta item kind, containing the data after the initial path.
- ModKind
- Module item kind.
- Movability
- The movability of a coroutine / closure literal:
whether a coroutine contains self-references, causing it to be
!Unpin
. - Mutability
- Param
Kind Ord - Specifies the enforced ordering for generic parameters. In the future,
if we wanted to relax this order, we could override
PartialEq
andPartialOrd
, to allow the kinds to be unordered. - PatFields
Rest - Whether the
..
is present in a struct fields pattern. - PatKind
- All the different flavors of pattern that Rust recognizes.
- Pinnedness
- Precise
Capturing Arg - Range
End - Range
Limits - Limit types of a range (inclusive or exclusive).
- Range
Syntax - Recovered
- Was parsing recovery performed?
- Safety
- Safety of items.
- Self
Kind - Alternative representation for
Arg
s describingself
parameter of methods. - Stmt
Kind - StrStyle
- Struct
Rest - Term
- Trait
Object Syntax - Syntax used to declare a trait object.
- TyKind
- The various kinds of type recognized by the compiler.
- TyPat
Kind - All the different flavors of pattern that Rust recognizes.
- UintTy
- UnOp
- Unary operator.
- Unsafe
Binder Cast Kind - Whether we’re unwrapping or wrapping an unsafe binder
- Unsafe
Source - UseTree
Kind - Part of
use
item to the right of its prefix. - Variant
Data - Fields and constructor ids of enum variants and structs.
- Visibility
Kind - Where
Predicate Kind - Predicate kind in where-clause.
- Yield
Kind - The kind of yield expression
Type Aliases§
- Assoc
Item - Represents associated items.
These include items in
impl
andtrait
definitions. - AttrVec
- A list of attributes.
- BinOp
- Explicit
Self - Foreign
Item - Generic
Bounds