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::util::parser::ExprPrecedence;
pub use crate::node_id::NodeId;
pub use crate::node_id::CRATE_NODE_ID;
pub use crate::node_id::DUMMY_NODE_ID;
pub use crate::format::*;
pub use GenericArgs::*;
pub use UnsafeSource::*;
Structs
- A path like
Foo<'a, T>
. - 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. - An arm of a ‘match’.
- A constraint on an associated type (e.g.,
A = Bar
inFoo<A = Bar>
orA: TraitA + TraitB
inFoo<A: TraitA + TraitB>
). - A syntax-level representation of an attribute.
- Explicit binding annotations given in the HIR for a binding. Note that this is not the final binding mode that we infer after type inference.
- A block (
{ .. }
). - Delimited arguments, as used in
#[attr()/[]/{}]
ormac!()/[]/{}
. - An expression.
- A single field in a struct expression, e.g.
x: value
andy
inFoo { x: value, y }
. - Field definition in a struct, variant or union.
- A signature (not the body) of a function declaration.
- A function header.
- Represents a function’s signature in a trait declaration, trait implementation, or free function.
- Foreign module declaration.
- Represents lifetime, type and const parameters attached to a declaration of a function, enum, trait, etc.
- Inline assembly.
- Inline assembly symbol operands get their own AST node that is somewhat similar to
AnonConst
. - An item definition.
- A “Label” is an identifier of some point in sources, e.g. in the following code:
- A “Lifetime” is an annotation of the scope in which variable can be used, e.g.
'a
in&'a i32
. - Local represents a
let
statement, e.g.,let <pat>:<ty> = <expr>;
. - Represents a macro invocation. The
path
indicates which macro is being invoked, and theargs
are arguments passed to it. - Represents a macro definition.
- 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.
- A literal in a meta item.
- A method call (e.g.
x.foo::<Bar, Baz>(a, b, c)
). - A parameter in a function header.
- A path like
Foo(A, B) -> C
. - A match pattern.
- A single field in a struct pattern.
- A “Path” is essentially Rust’s notion of a name.
- A segment of a path: an identifier, an optional lifetime, and a set of types.
- 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. - A statement
- Similar to
MetaItemLit
, but restricted to string literals. TraitRef
s appear in impls.- 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. - A tree of paths sharing common prefixes. Used in
use
items both at top-level and inside of braces in import groups. - Enum variant.
- A type bound.
- A where-clause in a definition.
- An equality predicate (unsupported).
- A lifetime predicate.
Enums
- Either an argument for a parameter e.g.,
'a
,Vec<u8>
,0
, or a constraint on an associated item, e.g.,Item = String
orItem: Bound
. - The kinds of an
AssocConstraint
. - Represents associated item kinds.
- Arguments passed to an attribute macro.
- 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. - The kind of borrow in an
AddrOf
expression, e.g.,&place
or&raw const place
. - A capture clause used in closures and
async
blocks. - Closure lifetime binder,
for<'a, 'b>
infor<'a, 'b> |_: &'a (), _: &'b ()|
. - Item defaultness. For details see the RFC #2532.
extern
qualifier on a function item or function type.- An item in
extern
block. - Concrete argument in the sequence of generic args.
- The arguments of a path segment.
- The AST represents all type param bounds as types.
typeck::collect::compute_bounds
matches these against the “special” built-in traits (seemiddle::lang_items
) and detectsCopy
,Send
andSync
. - Inline assembly operand.
- Inline assembly operand explicit register or register class.
- Is the trait definition an auto trait?
- Type of the float literal based on provided suffix.
- Type of the integer literal based on provided suffix.
- This type is used within both
ast::MetaItemLit
andhir::Lit
. - The meta item kind, containing the data after the initial path.
- Module item kind.
- The movability of a generator / closure literal: whether a generator contains self-references, causing it to be
!Unpin
. - Values inside meta item lists.
- 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. - All the different flavors of pattern that Rust recognizes.
- Limit types of a range (inclusive or exclusive)
- Alternative representation for
Arg
s describingself
parameter of methods. - The kinds of an
AssocConstraint
. - A modifier on a bound, e.g.,
?Trait
or~const Trait
. - Syntax used to declare a trait object.
- The various kinds of type recognized by the compiler.
- Unary operator.
- Part of
use
item to the right of its prefix. - Fields and constructor ids of enum variants and structs.
- A single predicate in a where-clause.
Type Aliases
- Represents associated items. These include items in
impl
andtrait
definitions. - A list of attributes.