Module ast

Source
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:

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§

size_asserts 🔒

Structs§

AngleBracketedArgs
A path like Foo<'a, T>.
AnonConst
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’.
AssocItemConstraint
A constraint on an associated item.
AttrId
AttrItem
Attribute
A syntax-level representation of an attribute.
BareFnTy
BindingMode
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
ConstItem
Crate
Delegation
DelegationMac
DelimArgs
Delimited arguments, as used in #[attr()/[]/{}] or mac!()/[]/{}.
EnumDef
Expr
An expression.
ExprField
A single field in a struct expression, e.g. x: value and y in Foo { x: value, y }.
FieldDef
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.
ForeignMod
Foreign module declaration.
GenericParam
Generics
Represents lifetime, type and const parameters attached to a declaration of a function, enum, trait, etc.
Impl
InlineAsm
Inline assembly.
InlineAsmOptions
InlineAsmSym
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 the args are arguments passed to it.
MacCallStmt
MacroDef
Represents a macro definition.
MetaItem
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.
MetaItemLit
A literal in a meta item.
MethodCall
A method call (e.g. x.foo::<Bar, Baz>(a, b, c)).
ModSpans
MutTy
NormalAttr
Param
A parameter in a function header.
ParenthesizedArgs
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.
PathSegment
A segment of a path: an identifier, an optional lifetime, and a set of types.
PolyTraitRef
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 this Self type.
StaticItem
Stmt
A statement. No attrs or tokens fields because each StmtKind variant contains an AST node with those fields. (Except for StmtKind::Empty, which never has attrs or tokens)
StrLit
Similar to MetaItemLit, but restricted to string literals.
StructExpr
Trait
TraitBoundModifiers
Modifiers on a trait bound like ~const, ? and !.
TraitRef
TraitRefs appear in impls.
Ty
TyAlias
TyAliasWhereClause
The location of a where clause on a TyAlias (Span) and whether there was a where keyword (bool). This is split out from WhereClause, since there are two locations for where clause on type aliases, but their predicates are concatenated together.
TyAliasWhereClauses
The span information for the two where clauses on a TyAlias.
TyPat
A pattern type pattern.
UnsafeBinderTy
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
WhereBoundPredicate
A type bound.
WhereClause
A where-clause in a definition.
WhereEqPredicate
An equality predicate (unsupported).
WherePredicate
A single predicate in a where-clause.
WhereRegionPredicate
A lifetime predicate.

Enums§

AngleBracketedArg
Either an argument for a generic parameter or a constraint on an associated item.
AsmMacro
AssocItemConstraintKind
The kind of associated item constraint.
AssocItemKind
Represents associated item kinds.
AttrArgs
Arguments passed to an attribute macro.
AttrKind
AttrStyle
Distinguishes between Attributes that decorate items and Attributes that are contained as statements within items. These two cases need to be distinguished for pretty-printing.
BinOpKind
BlockCheckMode
BorrowKind
The kind of borrow in an AddrOf expression, e.g., &place or &raw const place.
BoundAsyncness
The asyncness of a trait bound.
BoundConstness
The constness of a trait bound.
BoundPolarity
The polarity of a trait bound.
ByRef
CaptureBy
A capture clause used in closures and async blocks.
ClosureBinder
Closure lifetime binder, for<'a, 'b> in for<'a, 'b> |_: &'a (), _: &'b ()|.
Const
CoroutineKind
Describes what kind of coroutine markers, if any, a function has.
Defaultness
Item defaultness. For details see the RFC #2532.
ExprKind
Extern
extern qualifier on a function item or function type.
FloatTy
FnRetTy
ForLoopKind
Used to differentiate between for loops and for await loops.
ForeignItemKind
An item in extern block.
GenBlockKind
Used to differentiate between async {} blocks and gen {} blocks.
GenericArg
Concrete argument in the sequence of generic args.
GenericArgs
The generic arguments and associated item constraints of a path segment.
GenericBound
GenericParamKind
ImplPolarity
Inline
InlineAsmOperand
Inline assembly operand.
InlineAsmRegOrRegClass
Inline assembly operand explicit register or register class.
InlineAsmTemplatePiece
IntTy
IsAuto
Is the trait definition an auto trait?
ItemKind
LitFloatType
Type of the float literal based on provided suffix.
LitIntType
Type of the integer literal based on provided suffix.
LitKind
This type is used within both ast::MetaItemLit and hir::Lit.
LocalKind
MacStmtStyle
MatchKind
The kind of match expression
MetaItemInner
Values inside meta item lists.
MetaItemKind
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
ParamKindOrd
Specifies the enforced ordering for generic parameters. In the future, if we wanted to relax this order, we could override PartialEq and PartialOrd, to allow the kinds to be unordered.
PatFieldsRest
Whether the .. is present in a struct fields pattern.
PatKind
All the different flavors of pattern that Rust recognizes.
Pinnedness
PreciseCapturingArg
RangeEnd
RangeLimits
Limit types of a range (inclusive or exclusive).
RangeSyntax
Recovered
Was parsing recovery performed?
Safety
Safety of items.
SelfKind
Alternative representation for Args describing self parameter of methods.
StmtKind
StrStyle
StructRest
Term
TraitObjectSyntax
Syntax used to declare a trait object.
TyKind
The various kinds of type recognized by the compiler.
TyPatKind
All the different flavors of pattern that Rust recognizes.
UintTy
UnOp
Unary operator.
UnsafeBinderCastKind
Whether we’re unwrapping or wrapping an unsafe binder
UnsafeSource
UseTreeKind
Part of use item to the right of its prefix.
VariantData
Fields and constructor ids of enum variants and structs.
VisibilityKind
WherePredicateKind
Predicate kind in where-clause.
YieldKind
The kind of yield expression

Type Aliases§

AssocItem
Represents associated items. These include items in impl and trait definitions.
AttrVec
A list of attributes.
BinOp
ExplicitSelf
ForeignItem
GenericBounds