Copyright | (c) Alec Theriault 2017-2018 |
---|---|
License | BSD-style |
Maintainer | alec.theriault@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
This module defines Haskell data types corresponding to the abstract syntax tree(s) of the Rust
language, based on the definitions rustc
uses (defined in libsyntax
) whenever possible.
Unfortunately, since the internals of rustc
are not exposed, there are no official
docs. https://manishearth.github.io/rust-internals-docs/syntax/ast/index.html are the
unofficial docs.
- data SourceFile a = SourceFile (Maybe Name) [Attribute a] [Item a]
- data Mutability
- data Unsafety
- data Arg a
- = Arg (Maybe (Pat a)) (Ty a) a
- | SelfValue Mutability a
- | SelfRegion (Maybe (Lifetime a)) Mutability a
- | SelfExplicit (Ty a) Mutability a
- data FnDecl a = FnDecl [Arg a] (Maybe (Ty a)) Bool a
- data Path a = Path Bool [PathSegment a] a
- data PathParameters a
- = AngleBracketed [Lifetime a] [Ty a] [(Ident, Ty a)] a
- | Parenthesized [Ty a] (Maybe (Ty a)) a
- data PathSegment a = PathSegment Ident (Maybe (PathParameters a)) a
- data QSelf a = QSelf (Ty a) Int
- data Attribute a
- = Attribute AttrStyle (Path a) TokenStream a
- | SugaredDoc AttrStyle Bool Name a
- data AttrStyle
- data Lit a
- byteStr :: String -> StrStyle -> Suffix -> a -> Lit a
- data Suffix
- suffix :: Lit a -> Suffix
- data IntRep
- data StrStyle
- data Expr a
- = Box [Attribute a] (Expr a) a
- | InPlace [Attribute a] (Expr a) (Expr a) a
- | Vec [Attribute a] [Expr a] a
- | Call [Attribute a] (Expr a) [Expr a] a
- | MethodCall [Attribute a] (Expr a) Ident (Maybe [Ty a]) [Expr a] a
- | TupExpr [Attribute a] [Expr a] a
- | Binary [Attribute a] BinOp (Expr a) (Expr a) a
- | Unary [Attribute a] UnOp (Expr a) a
- | Lit [Attribute a] (Lit a) a
- | Cast [Attribute a] (Expr a) (Ty a) a
- | TypeAscription [Attribute a] (Expr a) (Ty a) a
- | If [Attribute a] (Expr a) (Block a) (Maybe (Expr a)) a
- | IfLet [Attribute a] (NonEmpty (Pat a)) (Expr a) (Block a) (Maybe (Expr a)) a
- | While [Attribute a] (Expr a) (Block a) (Maybe (Label a)) a
- | WhileLet [Attribute a] (NonEmpty (Pat a)) (Expr a) (Block a) (Maybe (Label a)) a
- | ForLoop [Attribute a] (Pat a) (Expr a) (Block a) (Maybe (Label a)) a
- | Loop [Attribute a] (Block a) (Maybe (Label a)) a
- | Match [Attribute a] (Expr a) [Arm a] a
- | Closure [Attribute a] Movability CaptureBy (FnDecl a) (Expr a) a
- | BlockExpr [Attribute a] (Block a) a
- | Catch [Attribute a] (Block a) a
- | Assign [Attribute a] (Expr a) (Expr a) a
- | AssignOp [Attribute a] BinOp (Expr a) (Expr a) a
- | FieldAccess [Attribute a] (Expr a) Ident a
- | TupField [Attribute a] (Expr a) Int a
- | Index [Attribute a] (Expr a) (Expr a) a
- | Range [Attribute a] (Maybe (Expr a)) (Maybe (Expr a)) RangeLimits a
- | PathExpr [Attribute a] (Maybe (QSelf a)) (Path a) a
- | AddrOf [Attribute a] Mutability (Expr a) a
- | Break [Attribute a] (Maybe (Label a)) (Maybe (Expr a)) a
- | Continue [Attribute a] (Maybe (Label a)) a
- | Ret [Attribute a] (Maybe (Expr a)) a
- | MacExpr [Attribute a] (Mac a) a
- | Struct [Attribute a] (Path a) [Field a] (Maybe (Expr a)) a
- | Repeat [Attribute a] (Expr a) (Expr a) a
- | ParenExpr [Attribute a] (Expr a) a
- | Try [Attribute a] (Expr a) a
- | Yield [Attribute a] (Maybe (Expr a)) a
- data Abi
- data Arm a = Arm [Attribute a] (NonEmpty (Pat a)) (Maybe (Expr a)) (Expr a) a
- data UnOp
- data BinOp
- data Label a = Label Name a
- data CaptureBy
- data Movability
- data Field a = Field Ident (Maybe (Expr a)) a
- data RangeLimits
- data Ty a
- = Slice (Ty a) a
- | Array (Ty a) (Expr a) a
- | Ptr Mutability (Ty a) a
- | Rptr (Maybe (Lifetime a)) Mutability (Ty a) a
- | BareFn Unsafety Abi [LifetimeDef a] (FnDecl a) a
- | Never a
- | TupTy [Ty a] a
- | PathTy (Maybe (QSelf a)) (Path a) a
- | TraitObject (NonEmpty (TyParamBound a)) a
- | ImplTrait (NonEmpty (TyParamBound a)) a
- | ParenTy (Ty a) a
- | Typeof (Expr a) a
- | Infer a
- | MacTy (Mac a) a
- data Generics a = Generics [LifetimeDef a] [TyParam a] (WhereClause a) a
- data Lifetime a = Lifetime Name a
- data LifetimeDef a = LifetimeDef [Attribute a] (Lifetime a) [Lifetime a] a
- data TyParam a = TyParam [Attribute a] Ident [TyParamBound a] (Maybe (Ty a)) a
- data TyParamBound a
- = TraitTyParamBound (PolyTraitRef a) TraitBoundModifier a
- | RegionTyParamBound (Lifetime a) a
- partitionTyParamBounds :: [TyParamBound a] -> ([TyParamBound a], [TyParamBound a])
- data WhereClause a = WhereClause [WherePredicate a] a
- whereClause :: Generics a -> WhereClause a
- data WherePredicate a
- = BoundPredicate [LifetimeDef a] (Ty a) [TyParamBound a] a
- | RegionPredicate (Lifetime a) [Lifetime a] a
- | EqPredicate (Ty a) (Ty a) a
- data PolyTraitRef a = PolyTraitRef [LifetimeDef a] (TraitRef a) a
- newtype TraitRef a = TraitRef (Path a)
- data TraitBoundModifier
- data Pat a
- = WildP a
- | IdentP BindingMode Ident (Maybe (Pat a)) a
- | StructP (Path a) [FieldPat a] Bool a
- | TupleStructP (Path a) [Pat a] (Maybe Int) a
- | PathP (Maybe (QSelf a)) (Path a) a
- | TupleP [Pat a] (Maybe Int) a
- | BoxP (Pat a) a
- | RefP (Pat a) Mutability a
- | LitP (Expr a) a
- | RangeP (Expr a) (Expr a) a
- | SliceP [Pat a] (Maybe (Pat a)) [Pat a] a
- | MacP (Mac a) a
- data BindingMode
- data FieldPat a = FieldPat (Maybe Ident) (Pat a) a
- data Stmt a
- data Item a
- = ExternCrate [Attribute a] (Visibility a) Ident (Maybe Ident) a
- | Use [Attribute a] (Visibility a) (UseTree a) a
- | Static [Attribute a] (Visibility a) Ident (Ty a) Mutability (Expr a) a
- | ConstItem [Attribute a] (Visibility a) Ident (Ty a) (Expr a) a
- | Fn [Attribute a] (Visibility a) Ident (FnDecl a) Unsafety Constness Abi (Generics a) (Block a) a
- | Mod [Attribute a] (Visibility a) Ident (Maybe [Item a]) a
- | ForeignMod [Attribute a] (Visibility a) Abi [ForeignItem a] a
- | TyAlias [Attribute a] (Visibility a) Ident (Ty a) (Generics a) a
- | Enum [Attribute a] (Visibility a) Ident [Variant a] (Generics a) a
- | StructItem [Attribute a] (Visibility a) Ident (VariantData a) (Generics a) a
- | Union [Attribute a] (Visibility a) Ident (VariantData a) (Generics a) a
- | Trait [Attribute a] (Visibility a) Ident Bool Unsafety (Generics a) [TyParamBound a] [TraitItem a] a
- | TraitAlias [Attribute a] (Visibility a) Ident (Generics a) (NonEmpty (TyParamBound a)) a
- | Impl [Attribute a] (Visibility a) Defaultness Unsafety ImplPolarity (Generics a) (Maybe (TraitRef a)) (Ty a) [ImplItem a] a
- | MacItem [Attribute a] (Maybe Ident) (Mac a) a
- | MacroDef [Attribute a] Ident TokenStream a
- data ForeignItem a
- = ForeignFn [Attribute a] (Visibility a) Ident (FnDecl a) (Generics a) a
- | ForeignStatic [Attribute a] (Visibility a) Ident (Ty a) Mutability a
- | ForeignTy [Attribute a] (Visibility a) Ident a
- data ImplItem a
- = ConstI [Attribute a] (Visibility a) Defaultness Ident (Ty a) (Expr a) a
- | MethodI [Attribute a] (Visibility a) Defaultness Ident (Generics a) (MethodSig a) (Block a) a
- | TypeI [Attribute a] (Visibility a) Defaultness Ident (Ty a) a
- | MacroI [Attribute a] Defaultness (Mac a) a
- data TraitItem a
- data Defaultness
- data ImplPolarity
- data StructField a = StructField (Maybe Ident) (Visibility a) (Ty a) [Attribute a] a
- data Variant a = Variant Ident [Attribute a] (VariantData a) (Maybe (Expr a)) a
- data VariantData a
- = StructD [StructField a] a
- | TupleD [StructField a] a
- | UnitD a
- data UseTree a
- = UseTreeSimple (Path a) (Maybe Ident) a
- | UseTreeGlob (Path a) a
- | UseTreeNested (Path a) [UseTree a] a
- data Visibility a
- = PublicV
- | CrateV
- | RestrictedV (Path a)
- | InheritedV
- data Constness
- data MethodSig a = MethodSig Unsafety Constness Abi (FnDecl a)
- data Block a = Block [Stmt a] Unsafety a
- data TokenTree
- data TokenStream
- = Tree TokenTree
- | Stream [TokenStream]
- unconsTokenStream :: TokenStream -> Maybe (TokenTree, TokenStream)
- data Nonterminal a
- data Mac a = Mac (Path a) TokenStream a
- data MacStmtStyle
- data Token
- = Equal
- | Less
- | Greater
- | Ampersand
- | Pipe
- | Exclamation
- | Tilde
- | Plus
- | Minus
- | Star
- | Slash
- | Percent
- | Caret
- | GreaterEqual
- | GreaterGreaterEqual
- | AmpersandAmpersand
- | PipePipe
- | LessLess
- | GreaterGreater
- | EqualEqual
- | NotEqual
- | LessEqual
- | LessLessEqual
- | MinusEqual
- | AmpersandEqual
- | PipeEqual
- | PlusEqual
- | StarEqual
- | SlashEqual
- | CaretEqual
- | PercentEqual
- | At
- | Dot
- | DotDot
- | DotDotEqual
- | DotDotDot
- | Comma
- | Semicolon
- | Colon
- | ModSep
- | RArrow
- | LArrow
- | FatArrow
- | Pound
- | Dollar
- | Question
- | OpenDelim !Delim
- | CloseDelim !Delim
- | LiteralTok LitTok (Maybe Name)
- | IdentTok Ident
- | Underscore
- | LifetimeTok Ident
- | Space Space Name
- | Doc String !AttrStyle !Bool
- | Shebang
- | Eof
- | Interpolated (Nonterminal Span)
- spaceNeeded :: Token -> Token -> Bool
- data Space
- data Delim
- data LitTok
- data AttrStyle
Abstract syntax trees
Top level
data SourceFile a Source #
This is the fundamental unit of parsing - it represents the contents of one source file. It is composed of an optional shebang line, inner attributes that follow, and then the module items.
Example:
#!/usr/bin/env rust #![allow(dead_code)] fn main() { println!("Hello world") }
SourceFile (Maybe Name) [Attribute a] [Item a] |
Functor SourceFile Source # | |
Generic1 SourceFile Source # | |
PrettyAnnotated SourceFile Source # | |
Eq a => Eq (SourceFile a) Source # | |
Data a => Data (SourceFile a) Source # | |
Ord a => Ord (SourceFile a) Source # | |
Show a => Show (SourceFile a) Source # | |
Generic (SourceFile a) Source # | |
NFData a => NFData (SourceFile a) Source # | |
Parse (SourceFile Span) Source # | |
(Typeable * a, Monoid a) => Resolve (SourceFile a) Source # | |
Pretty (SourceFile a) Source # | |
type Rep1 SourceFile Source # | |
type Rep (SourceFile a) Source # | |
General
data Mutability Source #
Encodes whether something can be updated or changed (syntax::ast::Mutability
).
Qualifies whether something is using unsafe Rust or not (syntax::ast::Unsafety
). Note that we
also use this to describe whether a Block
is unsafe or not, while Rust has a seperate structure
(syntax::ast::BlockCheckMode
) for that. This is because they also need to keep track of whether
an unsafe block is compiler generated.
An argument in a function header (syntax::ast::Arg
, except with SelfKind
and ExplicitSelf
inlined).
Example: x: usize
, self
, mut self
, &self
, &'lt mut self
, mut self: Foo
as in
trait Foo { // Regular argument fn new(x: usize) -> Foo; // Self argument, by value fn foo(self) -> i32; fn bar(mut self); // Self argument, by reference fn baz(&self) -> Bar<'lt>; fn qux(&'lt mut self) -> Bar<'lt>; // Explicit self argument fn quux(mut self: Foo); }
Arg (Maybe (Pat a)) (Ty a) a | Regular argument |
SelfValue Mutability a | Self argument, by value |
SelfRegion (Maybe (Lifetime a)) Mutability a | Self argument, by reference |
SelfExplicit (Ty a) Mutability a | Explicit self argument |
Functor Arg Source # | |
Generic1 Arg Source # | |
Eq a => Eq (Arg a) Source # | |
Data a => Data (Arg a) Source # | |
Ord a => Ord (Arg a) Source # | |
Show a => Show (Arg a) Source # | |
Generic (Arg a) Source # | |
NFData a => NFData (Arg a) Source # | |
Located a => Located (Arg a) Source # | |
(Typeable * a, Monoid a) => Resolve (Arg a) Source # | |
type Rep1 Arg Source # | |
type Rep (Arg a) Source # | |
Header (not the body) of a function declaration (syntax::ast::FnDecl
). The Bool
argument
indicates whether the header is variadic (so whether the argument list ends in ...
).
Example: (bar: i32) -> i32
as in
fn foo(bar: i32) -> i32 { bar + 2 }
Functor FnDecl Source # | |
Generic1 FnDecl Source # | |
PrettyAnnotated FnDecl Source # | |
Eq a => Eq (FnDecl a) Source # | |
Data a => Data (FnDecl a) Source # | |
Ord a => Ord (FnDecl a) Source # | |
Show a => Show (FnDecl a) Source # | |
Generic (FnDecl a) Source # | |
NFData a => NFData (FnDecl a) Source # | |
Located a => Located (FnDecl a) Source # | |
(Typeable * a, Monoid a) => Resolve (FnDecl a) Source # | |
Pretty (FnDecl a) Source # | |
type Rep1 FnDecl Source # | |
type Rep (FnDecl a) Source # | |
Paths
Everything in Rust is namespaced using nested modules. A Path
represents a path into nested
modules, possibly instantiating type parameters along the way (syntax::ast::Path
). Much like
file paths, these paths can be relative or absolute (global) with respect to the crate root.
Paths are used to identify expressions (see PathExpr
), types (see PathTy
), and modules
(indirectly through ViewPath
and such).
The Bool
argument identifies whether the path is relative or absolute.
Example: std::cmp::PartialEq
Path Bool [PathSegment a] a |
Functor Path Source # | |
Generic1 Path Source # | |
PrettyAnnotated Path Source # | |
Eq a => Eq (Path a) Source # | |
Data a => Data (Path a) Source # | |
Ord a => Ord (Path a) Source # | |
Show a => Show (Path a) Source # | |
Generic (Path a) Source # | |
NFData a => NFData (Path a) Source # | |
Located a => Located (Path a) Source # | |
(Typeable * a, Monoid a) => Resolve (Path a) Source # | There are three potential instances for resolving a path (depending on what type it is). The
|
Pretty (Path a) Source # | |
type Rep1 Path Source # | |
type Rep (Path a) Source # | |
data PathParameters a Source #
Parameters on a path segment (syntax::ast::PathParameters
).
AngleBracketed [Lifetime a] [Ty a] [(Ident, Ty a)] a | Parameters in a chevron comma-delimited list ( Example: |
Parenthesized [Ty a] (Maybe (Ty a)) a | Parameters in a parenthesized comma-delimited list, with an optional output type
( Example: |
Functor PathParameters Source # | |
Generic1 PathParameters Source # | |
Eq a => Eq (PathParameters a) Source # | |
Data a => Data (PathParameters a) Source # | |
Ord a => Ord (PathParameters a) Source # | |
Show a => Show (PathParameters a) Source # | |
Generic (PathParameters a) Source # | |
NFData a => NFData (PathParameters a) Source # | |
Located a => Located (PathParameters a) Source # | |
(Typeable * a, Monoid a) => Resolve (PathParameters a) Source # | |
type Rep1 PathParameters Source # | |
type Rep (PathParameters a) Source # | |
data PathSegment a Source #
Segment of a path (syntax::ast::PathSegment
).
PathSegment Ident (Maybe (PathParameters a)) a |
Functor PathSegment Source # | |
Generic1 PathSegment Source # | |
Eq a => Eq (PathSegment a) Source # | |
Data a => Data (PathSegment a) Source # | |
Ord a => Ord (PathSegment a) Source # | |
Show a => Show (PathSegment a) Source # | |
Generic (PathSegment a) Source # | |
NFData a => NFData (PathSegment a) Source # | |
Located a => Located (PathSegment a) Source # | |
type Rep1 PathSegment Source # | |
type Rep (PathSegment a) Source # | |
The explicit Self
type in a "qualified path". The actual path, including the trait and the
associated item, is stored separately. The first argument is the type given to Self
and the
second is the index of the associated qualified with this Self
type
Functor QSelf Source # | |
Generic1 QSelf Source # | |
Eq a => Eq (QSelf a) Source # | |
Data a => Data (QSelf a) Source # | |
Ord a => Ord (QSelf a) Source # | |
Show a => Show (QSelf a) Source # | |
Generic (QSelf a) Source # | |
NFData a => NFData (QSelf a) Source # | |
(Typeable * a, Monoid a) => Resolve (QSelf a) Source # | |
type Rep1 QSelf Source # | |
type Rep (QSelf a) Source # | |
Attributes
Attribute
s are annotations for other AST nodes (syntax::ast::Attribute
). Note that
doc-comments are promoted to attributes.
Example: #[derive(Copy,Clone)]
as in
#[derive(Clone, Copy)] struct Complex { re: f32, im: f32 }
Attribute AttrStyle (Path a) TokenStream a | Regular attributes of the form |
SugaredDoc AttrStyle Bool Name a | Doc comment attributes. The |
Functor Attribute Source # | |
Generic1 Attribute Source # | |
PrettyAnnotated Attribute Source # | This instance prints attributes inline |
Eq a => Eq (Attribute a) Source # | |
Data a => Data (Attribute a) Source # | |
Ord a => Ord (Attribute a) Source # | |
Show a => Show (Attribute a) Source # | |
Generic (Attribute a) Source # | |
NFData a => NFData (Attribute a) Source # | |
Located a => Located (Attribute a) Source # | |
Parse (Attribute Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Attribute a) Source # | |
Pretty (Attribute a) Source # | |
type Rep1 Attribute Source # | |
type Rep (Attribute a) Source # | |
Distinguishes between attributes that decorate what follows them and attributes that are
describe the node that contains them (syntax::ast::AttrStyle
). These two cases need to be
distinguished only for pretty printing - they are otherwise fundamentally equivalent.
Example: #[repr(C)]
is an outer attribute while #![feature(slice_patterns)]
is an inner one
Literals
Literals in Rust (syntax::ast::Lit
). As discussed in Suffix
, Rust AST is designed to parse
suffixes for all literals, even if they are currently only valid on Int
and Float
literals.
Str String StrStyle Suffix a | string (example: |
ByteStr [Word8] StrStyle Suffix a | byte string (example: |
Char Char Suffix a | character (example: |
Byte Word8 Suffix a | byte (example: |
Int IntRep Integer Suffix a | integer (example: |
Float Double Suffix a | float (example: |
Bool Bool Suffix a | boolean (example: |
Functor Lit Source # | |
Generic1 Lit Source # | |
PrettyAnnotated Lit Source # | |
Eq a => Eq (Lit a) Source # | |
Data a => Data (Lit a) Source # | |
Ord a => Ord (Lit a) Source # | |
Show a => Show (Lit a) Source # | |
Generic (Lit a) Source # | |
NFData a => NFData (Lit a) Source # | |
Located a => Located (Lit a) Source # | |
Parse (Lit Span) Source # | |
Resolve (Lit a) Source # | |
Pretty (Lit a) Source # | |
type Rep1 Lit Source # | |
type Rep (Lit a) Source # | |
The suffix on a literal (unifies syntax::ast::LitIntType
, syntax::ast::IntTy
,
syntax::ast::UintTy
, and syntax::ast::FloatTy
). As of today, only numeric types can have
suffixes, but the possibility of adding more (possibly arbitrary) suffixes to literals in general
is being kept open intentionally. RFC about future-proofing literal
suffixes
Examples: i32
, isize
, and f32
The base of the number in an Int
literal can be binary (like 0b1100
), octal (like 0o14
),
decimal (like 12
), or hexadecimal (like 0xc
).
Expressions
Expression (syntax::ast::Expr
). Note that Rust pushes into expressions an unusual number
of constructs including if
, while
, match
, etc.
Box [Attribute a] (Expr a) a | box expression (example: |
InPlace [Attribute a] (Expr a) (Expr a) a | in-place expression - first |
Vec [Attribute a] [Expr a] a | array literal (example: |
Call [Attribute a] (Expr a) [Expr a] a | function call where the first |
MethodCall [Attribute a] (Expr a) Ident (Maybe [Ty a]) [Expr a] a | method call where the first |
TupExpr [Attribute a] [Expr a] a | tuple (example: |
Binary [Attribute a] BinOp (Expr a) (Expr a) a | binary operation (example: |
Unary [Attribute a] UnOp (Expr a) a | unary operation (example: |
Lit [Attribute a] (Lit a) a | literal (example: |
Cast [Attribute a] (Expr a) (Ty a) a | cast (example: |
TypeAscription [Attribute a] (Expr a) (Ty a) a | type annotation (example: |
If [Attribute a] (Expr a) (Block a) (Maybe (Expr a)) a | if expression, with an optional |
IfLet [Attribute a] (NonEmpty (Pat a)) (Expr a) (Block a) (Maybe (Expr a)) a | if-let expression with an optional else block (example: |
While [Attribute a] (Expr a) (Block a) (Maybe (Label a)) a | while loop, with an optional label (example: |
WhileLet [Attribute a] (NonEmpty (Pat a)) (Expr a) (Block a) (Maybe (Label a)) a | while-let loop, with an optional label (example: |
ForLoop [Attribute a] (Pat a) (Expr a) (Block a) (Maybe (Label a)) a | for loop, with an optional label (example: |
Loop [Attribute a] (Block a) (Maybe (Label a)) a | conditionless loop (can be exited with |
Match [Attribute a] (Expr a) [Arm a] a | match block |
Closure [Attribute a] Movability CaptureBy (FnDecl a) (Expr a) a | closure (example: |
BlockExpr [Attribute a] (Block a) a | (possibly unsafe) block (example: |
Catch [Attribute a] (Block a) a | a catch block (example: |
Assign [Attribute a] (Expr a) (Expr a) a | assignment (example: |
AssignOp [Attribute a] BinOp (Expr a) (Expr a) a | assignment with an operator (example: |
FieldAccess [Attribute a] (Expr a) Ident a | access of a named struct field (example: |
TupField [Attribute a] (Expr a) Int a | access of an unnamed field of a struct or tuple-struct (example: |
Index [Attribute a] (Expr a) (Expr a) a | indexing operation (example: |
Range [Attribute a] (Maybe (Expr a)) (Maybe (Expr a)) RangeLimits a | range (examples: |
PathExpr [Attribute a] (Maybe (QSelf a)) (Path a) a | variable reference |
AddrOf [Attribute a] Mutability (Expr a) a | referencing operation (example: |
Break [Attribute a] (Maybe (Label a)) (Maybe (Expr a)) a |
|
Continue [Attribute a] (Maybe (Label a)) a |
|
Ret [Attribute a] (Maybe (Expr a)) a |
|
MacExpr [Attribute a] (Mac a) a | macro invocation before expansion |
Struct [Attribute a] (Path a) [Field a] (Maybe (Expr a)) a | struct literal expression (examples: |
Repeat [Attribute a] (Expr a) (Expr a) a | array literal constructed from one repeated element (example: |
ParenExpr [Attribute a] (Expr a) a | no-op: used solely so we can pretty print faithfully |
Try [Attribute a] (Expr a) a | sugar for error handling with |
Yield [Attribute a] (Maybe (Expr a)) a | a |
Functor Expr Source # | |
Generic1 Expr Source # | |
PrettyAnnotated Expr Source # | |
Eq a => Eq (Expr a) Source # | |
Data a => Data (Expr a) Source # | |
Ord a => Ord (Expr a) Source # | |
Show a => Show (Expr a) Source # | |
Generic (Expr a) Source # | |
NFData a => NFData (Expr a) Source # | |
Located a => Located (Expr a) Source # | |
Parse (Expr Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Expr a) Source # | |
Pretty (Expr a) Source # | |
type Rep1 Expr Source # | |
type Rep (Expr a) Source # | |
ABIs support by Rust's foreign function interface (syntax::abi::Abi
). Note that of these,
only Rust
, C
, System
, RustIntrinsic
, RustCall
, and PlatformIntrinsic
and Unadjusted
are cross-platform - all the rest are platform-specific.
Example: "C"
as in extern "C" fn foo(x: i32);
An arm of a Match
expression (syntax::ast::Arm
). An arm has at least one patten, possibly a
guard expression, and a body expression.
Example: n if n % 4 == 3 => { println!("{} % 4 = 3", n) }
as in
match n { n if n % 4 == 3 => { println!("{} % 4 = 3", n) } n if n % 4 == 1 => { println!("{} % 4 = 1", n) } _ => println!("{} % 2 = 0", n) }
Functor Arm Source # | |
Generic1 Arm Source # | |
Eq a => Eq (Arm a) Source # | |
Data a => Data (Arm a) Source # | |
Ord a => Ord (Arm a) Source # | |
Show a => Show (Arm a) Source # | |
Generic (Arm a) Source # | |
NFData a => NFData (Arm a) Source # | |
Located a => Located (Arm a) Source # | |
(Typeable * a, Monoid a) => Resolve (Arm a) Source # | |
type Rep1 Arm Source # | |
type Rep (Arm a) Source # | |
Binary operators, used in the Binary
and AssignOp
constructors of Expr
(syntax::ast::BinOp
).
Example: +
as in 1 + 1
or 1 += 1
AddOp |
|
SubOp |
|
MulOp |
|
DivOp |
|
RemOp |
|
AndOp |
|
OrOp |
|
BitXorOp |
|
BitAndOp |
|
BitOrOp |
|
ShlOp |
|
ShrOp |
|
EqOp |
|
LtOp |
|
LeOp |
|
NeOp |
|
GeOp |
|
GtOp |
|
Used to annotate loops, breaks, continues, etc.
Functor Label Source # | |
Generic1 Label Source # | |
Eq a => Eq (Label a) Source # | |
Data a => Data (Label a) Source # | |
Ord a => Ord (Label a) Source # | |
Show a => Show (Label a) Source # | |
Generic (Label a) Source # | |
NFData a => NFData (Label a) Source # | |
Located a => Located (Label a) Source # | |
type Rep1 Label Source # | |
type Rep (Label a) Source # | |
Describes how a Closure
should close over its free variables (syntax::ast::CaptureBy
).
data Movability Source #
The movability of a generator / closure literal (syntax::ast::Movability
).
Field in a struct literal expression (syntax::ast::Field
).
Example: x: 1
in Point { x: 1, y: 2 }
Functor Field Source # | |
Generic1 Field Source # | |
PrettyAnnotated Field Source # | |
Eq a => Eq (Field a) Source # | |
Data a => Data (Field a) Source # | |
Ord a => Ord (Field a) Source # | |
Show a => Show (Field a) Source # | |
Generic (Field a) Source # | |
NFData a => NFData (Field a) Source # | |
Located a => Located (Field a) Source # | |
(Typeable * a, Monoid a) => Resolve (Field a) Source # | |
Pretty (Field a) Source # | |
type Rep1 Field Source # | |
type Rep (Field a) Source # | |
data RangeLimits Source #
Limit types of a Range
Types and lifetimes
Types (syntax::ast::Ty
).
Slice (Ty a) a | variable-length slice (example: |
Array (Ty a) (Expr a) a | fixed length array (example: |
Ptr Mutability (Ty a) a | raw pointer (example: |
Rptr (Maybe (Lifetime a)) Mutability (Ty a) a | reference (example: |
BareFn Unsafety Abi [LifetimeDef a] (FnDecl a) a | bare function (example: |
Never a | never type: |
TupTy [Ty a] a | tuple (example: |
PathTy (Maybe (QSelf a)) (Path a) a | path type (examples: |
TraitObject (NonEmpty (TyParamBound a)) a | trait object type (example: |
ImplTrait (NonEmpty (TyParamBound a)) a | impl trait type (see the
RFC)
(example: |
ParenTy (Ty a) a | no-op; kept solely so that we can pretty print faithfully |
Typeof (Expr a) a | typeof, currently unsupported in |
Infer a | inferred type: |
MacTy (Mac a) a | generated from a call to a macro (example: |
Functor Ty Source # | |
Generic1 Ty Source # | |
PrettyAnnotated Ty Source # | |
Eq a => Eq (Ty a) Source # | |
Data a => Data (Ty a) Source # | |
Ord a => Ord (Ty a) Source # | |
Show a => Show (Ty a) Source # | |
Generic (Ty a) Source # | |
NFData a => NFData (Ty a) Source # | |
Located a => Located (Ty a) Source # | |
Parse (Ty Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Ty a) Source # | |
Pretty (Ty a) Source # | |
type Rep1 Ty Source # | |
type Rep (Ty a) Source # | |
Represents lifetimes and type parameters attached to a declaration of a functions, enums,
traits, etc. (syntax::ast::Generics
). Note that lifetime definitions are always required to be
before the type parameters.
This one AST node is also a bit weird: it is the only node that whose source representation is
not compact - the lifetimes and type parameters occur by themselves between <
and >
then a
bit further the where clause occurs after a where
.
Example: <'a, 'b: 'c, T: 'a>
and where Option<T>: Copy
as in
fn nonsense<'a, 'b: 'c, T: 'a>(x: i32) -> i32
where Option<T>: Copy {
1
}
.
Generics [LifetimeDef a] [TyParam a] (WhereClause a) a |
Functor Generics Source # | |
Generic1 Generics Source # | |
PrettyAnnotated Generics Source # | |
Eq a => Eq (Generics a) Source # | |
Data a => Data (Generics a) Source # | |
Ord a => Ord (Generics a) Source # | |
Show a => Show (Generics a) Source # | |
Generic (Generics a) Source # | |
NFData a => NFData (Generics a) Source # | |
Located a => Located (Generics a) Source # | |
Parse (Generics Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Generics a) Source # | |
Pretty (Generics a) Source # | |
type Rep1 Generics Source # | |
type Rep (Generics a) Source # | |
A lifetime is a name for a scope in a program (syntax::ast::Lifetime
). One of the novel
features of Rust is that code can be parametrized over lifetimes. Syntactically, they are like
regular identifiers, but start with a tick '
mark. The Name
argument is not supposed to
include that tick.
Examples: 'a
or 'static
Functor Lifetime Source # | |
Generic1 Lifetime Source # | |
PrettyAnnotated Lifetime Source # | |
Eq a => Eq (Lifetime a) Source # | |
Data a => Data (Lifetime a) Source # | |
Ord a => Ord (Lifetime a) Source # | |
Show a => Show (Lifetime a) Source # | |
Generic (Lifetime a) Source # | |
NFData a => NFData (Lifetime a) Source # | |
Located a => Located (Lifetime a) Source # | |
Typeable * a => Resolve (Lifetime a) Source # | |
Pretty (Lifetime a) Source # | |
type Rep1 Lifetime Source # | |
type Rep (Lifetime a) Source # | |
data LifetimeDef a Source #
A lifetime definition, introducing a lifetime and the other lifetimes that bound it
(syntax::ast::LifetimeDef
).
Example: 'a: 'b + 'c + 'd
LifetimeDef [Attribute a] (Lifetime a) [Lifetime a] a |
Functor LifetimeDef Source # | |
Generic1 LifetimeDef Source # | |
PrettyAnnotated LifetimeDef Source # | |
Eq a => Eq (LifetimeDef a) Source # | |
Data a => Data (LifetimeDef a) Source # | |
Ord a => Ord (LifetimeDef a) Source # | |
Show a => Show (LifetimeDef a) Source # | |
Generic (LifetimeDef a) Source # | |
NFData a => NFData (LifetimeDef a) Source # | |
Located a => Located (LifetimeDef a) Source # | |
Parse (LifetimeDef Span) Source # | |
(Typeable * a, Monoid a) => Resolve (LifetimeDef a) Source # | |
Pretty (LifetimeDef a) Source # | |
type Rep1 LifetimeDef Source # | |
type Rep (LifetimeDef a) Source # | |
type parameter definition used in Generics
(syntax::ast::TyParam
). Note that each
parameter can have any number of (lifetime or trait) bounds, as well as possibly a default type.
Functor TyParam Source # | |
Generic1 TyParam Source # | |
PrettyAnnotated TyParam Source # | |
Eq a => Eq (TyParam a) Source # | |
Data a => Data (TyParam a) Source # | |
Ord a => Ord (TyParam a) Source # | |
Show a => Show (TyParam a) Source # | |
Generic (TyParam a) Source # | |
NFData a => NFData (TyParam a) Source # | |
Located a => Located (TyParam a) Source # | |
Parse (TyParam Span) Source # | |
(Typeable * a, Monoid a) => Resolve (TyParam a) Source # | |
Pretty (TyParam a) Source # | |
type Rep1 TyParam Source # | |
type Rep (TyParam a) Source # | |
data TyParamBound a Source #
Bounds that can be placed on types (syntax::ast::TyParamBound
). These can be either traits or
lifetimes.
TraitTyParamBound (PolyTraitRef a) TraitBoundModifier a | trait bound |
RegionTyParamBound (Lifetime a) a | lifetime bound |
Functor TyParamBound Source # | |
Generic1 TyParamBound Source # | |
PrettyAnnotated TyParamBound Source # | |
Eq a => Eq (TyParamBound a) Source # | |
Data a => Data (TyParamBound a) Source # | |
Ord a => Ord (TyParamBound a) Source # | |
Show a => Show (TyParamBound a) Source # | |
Generic (TyParamBound a) Source # | |
NFData a => NFData (TyParamBound a) Source # | |
Located a => Located (TyParamBound a) Source # | |
(Typeable * a, Monoid a) => Resolve (TyParamBound a) Source # | |
Pretty (TyParamBound a) Source # | |
type Rep1 TyParamBound Source # | |
type Rep (TyParamBound a) Source # | |
partitionTyParamBounds :: [TyParamBound a] -> ([TyParamBound a], [TyParamBound a]) Source #
Partion a list of TyParamBound
into a tuple of the TraitTyParamBound
and RegionTyParamBound
variants.
data WhereClause a Source #
A where
clause in a definition, where one can apply a series of constraints to the types
introduced and used by a Generic
clause (syntax::ast::WhereClause
). In many cases, where
is the only way to express certain bounds (since those bounds may not be immediately on a type
defined in the generic, but on a type derived from types defined in the generic).
Note that while WhereClause
is a field of Generic
, not all uses of generics are coupled with
a where clause. In those cases, we leave the list of predicates empty.
Example: where Option<T>: Debug
as in
impl<T> PrintInOption for T where Option<T>: Debug { }
WhereClause [WherePredicate a] a |
Functor WhereClause Source # | |
Generic1 WhereClause Source # | |
PrettyAnnotated WhereClause Source # | |
Eq a => Eq (WhereClause a) Source # | |
Data a => Data (WhereClause a) Source # | |
Ord a => Ord (WhereClause a) Source # | |
Show a => Show (WhereClause a) Source # | |
Generic (WhereClause a) Source # | |
NFData a => NFData (WhereClause a) Source # | |
Located a => Located (WhereClause a) Source # | |
Parse (WhereClause Span) Source # | |
(Typeable * a, Monoid a) => Resolve (WhereClause a) Source # | |
Pretty (WhereClause a) Source # | |
type Rep1 WhereClause Source # | |
type Rep (WhereClause a) Source # | |
whereClause :: Generics a -> WhereClause a Source #
Extract the where clause from a Generics
.
data WherePredicate a Source #
An individual predicate in a WhereClause
(syntax::ast::WherePredicate
).
BoundPredicate [LifetimeDef a] (Ty a) [TyParamBound a] a | type bound ( |
RegionPredicate (Lifetime a) [Lifetime a] a | lifetime predicate ( |
EqPredicate (Ty a) (Ty a) a | equality predicate ( |
Functor WherePredicate Source # | |
Generic1 WherePredicate Source # | |
PrettyAnnotated WherePredicate Source # | |
Eq a => Eq (WherePredicate a) Source # | |
Data a => Data (WherePredicate a) Source # | |
Ord a => Ord (WherePredicate a) Source # | |
Show a => Show (WherePredicate a) Source # | |
Generic (WherePredicate a) Source # | |
NFData a => NFData (WherePredicate a) Source # | |
Located a => Located (WherePredicate a) Source # | |
(Typeable * a, Monoid a) => Resolve (WherePredicate a) Source # | |
Pretty (WherePredicate a) Source # | |
type Rep1 WherePredicate Source # | |
type Rep (WherePredicate a) Source # | |
data PolyTraitRef a Source #
Trait ref parametrized over lifetimes introduced by a for
(syntax::ast::PolyTraitRef
).
Example: for<'a,'b> Foo<&'a Bar>
PolyTraitRef [LifetimeDef a] (TraitRef a) a |
Functor PolyTraitRef Source # | |
Generic1 PolyTraitRef Source # | |
PrettyAnnotated PolyTraitRef Source # | |
Eq a => Eq (PolyTraitRef a) Source # | |
Data a => Data (PolyTraitRef a) Source # | |
Ord a => Ord (PolyTraitRef a) Source # | |
Show a => Show (PolyTraitRef a) Source # | |
Generic (PolyTraitRef a) Source # | |
NFData a => NFData (PolyTraitRef a) Source # | |
Located a => Located (PolyTraitRef a) Source # | |
(Typeable * a, Monoid a) => Resolve (PolyTraitRef a) Source # | |
Pretty (PolyTraitRef a) Source # | |
type Rep1 PolyTraitRef Source # | |
type Rep (PolyTraitRef a) Source # | |
A TraitRef
is a path which identifies a trait (syntax::ast::TraitRef
).
Functor TraitRef Source # | |
Generic1 TraitRef Source # | |
PrettyAnnotated TraitRef Source # | |
Eq a => Eq (TraitRef a) Source # | |
Data a => Data (TraitRef a) Source # | |
Ord a => Ord (TraitRef a) Source # | |
Show a => Show (TraitRef a) Source # | |
Generic (TraitRef a) Source # | |
NFData a => NFData (TraitRef a) Source # | |
Located a => Located (TraitRef a) Source # | |
(Typeable * a, Monoid a) => Resolve (TraitRef a) Source # | |
Pretty (TraitRef a) Source # | |
type Rep1 TraitRef Source # | |
type Rep (TraitRef a) Source # | |
data TraitBoundModifier Source #
Modifier on a bound, currently this is only used for ?Sized
, where the modifier is Maybe
.
Negative bounds should also be handled here.
Patterns
Patterns (syntax::ast::Pat
).
WildP a | wildcard pattern: |
IdentP BindingMode Ident (Maybe (Pat a)) a | identifier pattern - either a new bound variable or a unit (tuple) struct pattern, or a
const pattern. Disambiguation cannot be done with parser alone, so it happens during name
resolution. (example: |
StructP (Path a) [FieldPat a] Bool a | struct pattern. The |
TupleStructP (Path a) [Pat a] (Maybe Int) a | tuple struct pattern. If the |
PathP (Maybe (QSelf a)) (Path a) a | path pattern (example |
TupleP [Pat a] (Maybe Int) a | tuple pattern. If the |
BoxP (Pat a) a | box pattern (example: |
RefP (Pat a) Mutability a | reference pattern (example: |
LitP (Expr a) a | literal (example: |
RangeP (Expr a) (Expr a) a | range pattern (example: |
SliceP [Pat a] (Maybe (Pat a)) [Pat a] a | slice pattern where, as per this RFC,
the pattern is split into the patterns before/after the |
MacP (Mac a) a | generated from a call to a macro (example: |
Functor Pat Source # | |
Generic1 Pat Source # | |
PrettyAnnotated Pat Source # | |
Eq a => Eq (Pat a) Source # | |
Data a => Data (Pat a) Source # | |
Ord a => Ord (Pat a) Source # | |
Show a => Show (Pat a) Source # | |
Generic (Pat a) Source # | |
NFData a => NFData (Pat a) Source # | |
Located a => Located (Pat a) Source # | |
Parse (Pat Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Pat a) Source # | |
Pretty (Pat a) Source # | |
type Rep1 Pat Source # | |
type Rep (Pat a) Source # | |
data BindingMode Source #
Describes how a value bound to an identifier in a pattern is going to be borrowed
(syntax::ast::BindingMode
).
Example: &mut
in |&mut x: i32| -> { x += 1 }
Field in a struct literal pattern (syntax::ast::FieldPat
). The field name Ident
is optional
but, when it is Nothing
, the pattern the field is destructured to must be IdentP
.
Example: x
in Point { x, y }
Functor FieldPat Source # | |
Generic1 FieldPat Source # | |
PrettyAnnotated FieldPat Source # | |
Eq a => Eq (FieldPat a) Source # | |
Data a => Data (FieldPat a) Source # | |
Ord a => Ord (FieldPat a) Source # | |
Show a => Show (FieldPat a) Source # | |
Generic (FieldPat a) Source # | |
NFData a => NFData (FieldPat a) Source # | |
Located a => Located (FieldPat a) Source # | |
(Typeable * a, Monoid a) => Resolve (FieldPat a) Source # | |
Pretty (FieldPat a) Source # | |
type Rep1 FieldPat Source # | |
type Rep (FieldPat a) Source # | |
Statements
A statement (syntax::ast::Stmt
). Rust has relatively few types of statements by turning both
expressions (sometimes with a required semicolon at the end) and items into statements.
Local (Pat a) (Maybe (Ty a)) (Maybe (Expr a)) [Attribute a] a | A local |
ItemStmt (Item a) a | Item definition (example: |
NoSemi (Expr a) a | Expression without a trailing semicolon (example: |
Semi (Expr a) a | Expression with a trailing semicolon (example: |
MacStmt (Mac a) MacStmtStyle [Attribute a] a | A macro call (example: |
Functor Stmt Source # | |
Generic1 Stmt Source # | |
PrettyAnnotated Stmt Source # | |
Eq a => Eq (Stmt a) Source # | |
Data a => Data (Stmt a) Source # | |
Ord a => Ord (Stmt a) Source # | |
Show a => Show (Stmt a) Source # | |
Generic (Stmt a) Source # | |
NFData a => NFData (Stmt a) Source # | |
Located a => Located (Stmt a) Source # | |
Parse (Stmt Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Stmt a) Source # | |
Pretty (Stmt a) Source # | |
type Rep1 Stmt Source # | |
type Rep (Stmt a) Source # | |
Items
A top-level item, possibly in a Mod
or a ItemStmt
(syntax::ast::Item
with
syntax::ast::ItemKind
inlined).
Example: fn main() { return; }
ExternCrate [Attribute a] (Visibility a) Ident (Maybe Ident) a | extern crate item, with optional original crate name.
Examples: |
Use [Attribute a] (Visibility a) (UseTree a) a | use declaration ( |
Static [Attribute a] (Visibility a) Ident (Ty a) Mutability (Expr a) a | static item ( |
ConstItem [Attribute a] (Visibility a) Ident (Ty a) (Expr a) a | constant item ( |
Fn [Attribute a] (Visibility a) Ident (FnDecl a) Unsafety Constness Abi (Generics a) (Block a) a | function declaration ( |
Mod [Attribute a] (Visibility a) Ident (Maybe [Item a]) a | module declaration ( |
ForeignMod [Attribute a] (Visibility a) Abi [ForeignItem a] a | external module ( |
TyAlias [Attribute a] (Visibility a) Ident (Ty a) (Generics a) a | type alias ( |
Enum [Attribute a] (Visibility a) Ident [Variant a] (Generics a) a | enum definition ( |
StructItem [Attribute a] (Visibility a) Ident (VariantData a) (Generics a) a | struct definition ( |
Union [Attribute a] (Visibility a) Ident (VariantData a) (Generics a) a | union definition ( |
Trait [Attribute a] (Visibility a) Ident Bool Unsafety (Generics a) [TyParamBound a] [TraitItem a] a | trait declaration ( |
TraitAlias [Attribute a] (Visibility a) Ident (Generics a) (NonEmpty (TyParamBound a)) a | trait alias
Example: |
Impl [Attribute a] (Visibility a) Defaultness Unsafety ImplPolarity (Generics a) (Maybe (TraitRef a)) (Ty a) [ImplItem a] a | implementation
Example: |
MacItem [Attribute a] (Maybe Ident) (Mac a) a | generated from a call to a macro
Example: |
MacroDef [Attribute a] Ident TokenStream a | definition of a macro via |
Functor Item Source # | |
Generic1 Item Source # | |
PrettyAnnotated Item Source # | |
Eq a => Eq (Item a) Source # | |
Data a => Data (Item a) Source # | |
Ord a => Ord (Item a) Source # | |
Show a => Show (Item a) Source # | |
Generic (Item a) Source # | |
NFData a => NFData (Item a) Source # | |
Located a => Located (Item a) Source # | |
Parse (Item Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Item a) Source # | |
Pretty (Item a) Source # | |
type Rep1 Item Source # | |
type Rep (Item a) Source # | |
data ForeignItem a Source #
An item within an extern block (syntax::ast::ForeignItem
with syntax::ast::ForeignItemKind
inlined).
Example: static ext: u8
in extern "C" { static ext: u8 }
ForeignFn [Attribute a] (Visibility a) Ident (FnDecl a) (Generics a) a | Foreign function Example: |
ForeignStatic [Attribute a] (Visibility a) Ident (Ty a) Mutability a | Foreign static variable, optionally mutable Example: |
ForeignTy [Attribute a] (Visibility a) Ident a | Foreign type Example: |
Functor ForeignItem Source # | |
Generic1 ForeignItem Source # | |
PrettyAnnotated ForeignItem Source # | |
Eq a => Eq (ForeignItem a) Source # | |
Data a => Data (ForeignItem a) Source # | |
Ord a => Ord (ForeignItem a) Source # | |
Show a => Show (ForeignItem a) Source # | |
Generic (ForeignItem a) Source # | |
NFData a => NFData (ForeignItem a) Source # | |
Located a => Located (ForeignItem a) Source # | |
(Typeable * a, Monoid a) => Resolve (ForeignItem a) Source # | |
Pretty (ForeignItem a) Source # | |
type Rep1 ForeignItem Source # | |
type Rep (ForeignItem a) Source # | |
An item within an impl (syntax::ast::ImplItem
with syntax::ast::ImplItemKind
inlined).
Examples:
impl MyTrait { // Associated constant const ID: i32 = 1; // Method fn area(&self) -> f64 { 1f64 } // Associated type type N = i32; // Call to a macro foo!{} }
ConstI [Attribute a] (Visibility a) Defaultness Ident (Ty a) (Expr a) a | Associated constant |
MethodI [Attribute a] (Visibility a) Defaultness Ident (Generics a) (MethodSig a) (Block a) a | Method |
TypeI [Attribute a] (Visibility a) Defaultness Ident (Ty a) a | Associated type |
MacroI [Attribute a] Defaultness (Mac a) a | Macro call |
Functor ImplItem Source # | |
Generic1 ImplItem Source # | |
PrettyAnnotated ImplItem Source # | |
Eq a => Eq (ImplItem a) Source # | |
Data a => Data (ImplItem a) Source # | |
Ord a => Ord (ImplItem a) Source # | |
Show a => Show (ImplItem a) Source # | |
Generic (ImplItem a) Source # | |
NFData a => NFData (ImplItem a) Source # | |
Located a => Located (ImplItem a) Source # | |
Parse (ImplItem Span) Source # | |
(Typeable * a, Monoid a) => Resolve (ImplItem a) Source # | |
Pretty (ImplItem a) Source # | |
type Rep1 ImplItem Source # | |
type Rep (ImplItem a) Source # | |
Item declaration within a trait declaration (syntax::ast::TraitItem
with
syntax::ast::TraitItemKind
inlined), possibly including a default implementation. A trait item
is either required (meaning it doesn't have an implementation, just a signature) or provided
(meaning it has a default implementation).
Examples:
trait MyTrait { // Associated constant const ID: i32 = 1; // Method fn area(&self) -> f64; // Associated type type N: fmt::Display; // Call to a macro foo!{} }
ConstT [Attribute a] Ident (Ty a) (Maybe (Expr a)) a | Associated constants |
MethodT [Attribute a] Ident (Generics a) (MethodSig a) (Maybe (Block a)) a | Method with optional body |
TypeT [Attribute a] Ident [TyParamBound a] (Maybe (Ty a)) a | Possibly abstract associated types |
MacroT [Attribute a] (Mac a) a | Call to a macro |
Functor TraitItem Source # | |
Generic1 TraitItem Source # | |
PrettyAnnotated TraitItem Source # | |
Eq a => Eq (TraitItem a) Source # | |
Data a => Data (TraitItem a) Source # | |
Ord a => Ord (TraitItem a) Source # | |
Show a => Show (TraitItem a) Source # | |
Generic (TraitItem a) Source # | |
NFData a => NFData (TraitItem a) Source # | |
Located a => Located (TraitItem a) Source # | |
Parse (TraitItem Span) Source # | |
(Typeable * a, Monoid a) => Resolve (TraitItem a) Source # | |
Pretty (TraitItem a) Source # | |
type Rep1 TraitItem Source # | |
type Rep (TraitItem a) Source # | |
data Defaultness Source #
ImplItem
s can be marked default
(syntax::ast::Defaultness
).
data ImplPolarity Source #
For traits with a default impl, one can "opt out" of that impl with a negative impl, by adding
!
mark before the trait name. RFC on builtin
traits
Example: !
as in impl !Trait for Foo { }
data StructField a Source #
Field of a struct (syntax::ast::StructField
) used in declarations
Example: bar: usize
as in struct Foo { bar: usize }
StructField (Maybe Ident) (Visibility a) (Ty a) [Attribute a] a |
Functor StructField Source # | |
Generic1 StructField Source # | |
PrettyAnnotated StructField Source # | |
Eq a => Eq (StructField a) Source # | |
Data a => Data (StructField a) Source # | |
Ord a => Ord (StructField a) Source # | |
Show a => Show (StructField a) Source # | |
Generic (StructField a) Source # | |
NFData a => NFData (StructField a) Source # | |
Located a => Located (StructField a) Source # | |
(Typeable * a, Monoid a) => Resolve (StructField a) Source # | |
Pretty (StructField a) Source # | |
type Rep1 StructField Source # | |
type Rep (StructField a) Source # | |
A variant in Rust is a constructor (either in a StructItem
, Union
, or Enum
) which groups
together fields (syntax::ast::Variant
). In the case of a unit variant, there can also be an
explicit discriminant expression.
Functor Variant Source # | |
Generic1 Variant Source # | |
PrettyAnnotated Variant Source # | |
Eq a => Eq (Variant a) Source # | |
Data a => Data (Variant a) Source # | |
Ord a => Ord (Variant a) Source # | |
Show a => Show (Variant a) Source # | |
Generic (Variant a) Source # | |
NFData a => NFData (Variant a) Source # | |
Located a => Located (Variant a) Source # | |
(Typeable * a, Monoid a) => Resolve (Variant a) Source # | |
Pretty (Variant a) Source # | |
type Rep1 Variant Source # | |
type Rep (Variant a) Source # | |
data VariantData a Source #
Main payload in a Variant
(syntax::ast::VariantData
).
Examples:
enum Foo { // Struct variant Bar { x: f64 }, // Tuple variant Baz(i32, i32), // Unit variant Qux, }
StructD [StructField a] a | Struct variant |
TupleD [StructField a] a | Tuple variant |
UnitD a | Unit variant |
Functor VariantData Source # | |
Generic1 VariantData Source # | |
Eq a => Eq (VariantData a) Source # | |
Data a => Data (VariantData a) Source # | |
Ord a => Ord (VariantData a) Source # | |
Show a => Show (VariantData a) Source # | |
Generic (VariantData a) Source # | |
NFData a => NFData (VariantData a) Source # | |
Located a => Located (VariantData a) Source # | |
(Typeable * a, Monoid a) => Resolve (VariantData a) Source # | |
type Rep1 VariantData Source # | |
type Rep (VariantData a) Source # | |
Paths used in Use
items (ast::syntax::UseTree
).
Examples:
// Simple use paths use foo::bar::baz as quux; use foo::bar::baz; // Glob use paths use foo::bar::*; // Nested use paths use foo::bar::{a, b, c::quux as d}
UseTreeSimple (Path a) (Maybe Ident) a | Simple path, optionally ending in an |
UseTreeGlob (Path a) a | Path ending in a glob pattern |
UseTreeNested (Path a) [UseTree a] a | Path ending in a list of more paths |
Functor UseTree Source # | |
Generic1 UseTree Source # | |
PrettyAnnotated UseTree Source # | |
Eq a => Eq (UseTree a) Source # | |
Data a => Data (UseTree a) Source # | |
Ord a => Ord (UseTree a) Source # | |
Show a => Show (UseTree a) Source # | |
Generic (UseTree a) Source # | |
NFData a => NFData (UseTree a) Source # | |
Located a => Located (UseTree a) Source # | |
(Typeable * a, Monoid a) => Resolve (UseTree a) Source # | |
Pretty (UseTree a) Source # | |
type Rep1 UseTree Source # | |
type Rep (UseTree a) Source # | |
data Visibility a Source #
The visibility modifier dictates from where one can access something
(ast::syntax::Visibility
). RFC about adding restricted
visibility
PublicV |
|
CrateV |
|
RestrictedV (Path a) | for some path |
InheritedV | if no visbility is specified, this is the default |
Functor Visibility Source # | |
Generic1 Visibility Source # | |
PrettyAnnotated Visibility Source # | |
Eq a => Eq (Visibility a) Source # | |
Data a => Data (Visibility a) Source # | |
Ord a => Ord (Visibility a) Source # | |
Show a => Show (Visibility a) Source # | |
Generic (Visibility a) Source # | |
NFData a => NFData (Visibility a) Source # | |
(Typeable * a, Monoid a) => Resolve (Visibility a) Source # | |
Pretty (Visibility a) Source # | |
type Rep1 Visibility Source # | |
type Rep (Visibility a) Source # | |
Const annotation to specify if a function or method is allowed to be called in constants
context with constant arguments (syntax::ast::Constness
). Relevant
RFC
Example: const
in const fn inc(x: i32) -> i32 { x + 1 }
Represents a method's signature in a trait declaration, or in an implementation.
Functor MethodSig Source # | |
Generic1 MethodSig Source # | |
Eq a => Eq (MethodSig a) Source # | |
Data a => Data (MethodSig a) Source # | |
Ord a => Ord (MethodSig a) Source # | |
Show a => Show (MethodSig a) Source # | |
Generic (MethodSig a) Source # | |
NFData a => NFData (MethodSig a) Source # | |
(Typeable * a, Monoid a) => Resolve (MethodSig a) Source # | |
type Rep1 MethodSig Source # | |
type Rep (MethodSig a) Source # | |
Blocks
A curly brace delimited sequence of statements (syntax::ast::Block
). The last statement in
the block can always be a NoSemi
expression.
Example: { let x = 1; return x + y }
as in fn foo() { let x = 1; return x + y }
Functor Block Source # | |
Generic1 Block Source # | |
PrettyAnnotated Block Source # | |
Eq a => Eq (Block a) Source # | |
Data a => Data (Block a) Source # | |
Ord a => Ord (Block a) Source # | |
Show a => Show (Block a) Source # | |
Generic (Block a) Source # | |
NFData a => NFData (Block a) Source # | |
Located a => Located (Block a) Source # | |
Parse (Block Span) Source # | |
(Typeable * a, Monoid a) => Resolve (Block a) Source # | |
Pretty (Block a) Source # | |
type Rep1 Block Source # | |
type Rep (Block a) Source # | |
Token trees
When the parser encounters a macro call, it parses what follows as a Delimited
token tree.
Basically, token trees let you store raw tokens or Sequence
forms inside of balanced
parens or braces or brackets. This is a very loose structure, such that all sorts of different
AST-fragments can be passed to syntax extensions using a uniform type.
data TokenStream Source #
An abstract sequence of tokens, organized into a sequence (e.g. stream) of TokenTree
s, which
are themselves a single Token
or a Delimited
subsequence of tokens.
Tree TokenTree | a single token or a single set of delimited tokens |
Stream [TokenStream] | stream of streams of tokens |
Eq TokenStream Source # | |
Data TokenStream Source # | |
Ord TokenStream Source # | |
Show TokenStream Source # | |
Generic TokenStream Source # | |
NFData TokenStream Source # | |
Located TokenStream Source # |
|
Parse TokenStream Source # | |
Resolve TokenStream Source # | |
Pretty TokenStream Source # | |
type Rep TokenStream Source # | |
unconsTokenStream :: TokenStream -> Maybe (TokenTree, TokenStream) Source #
A TokenStream
is at its core just a stream of TokenTree
. This function lets you get at that
directly. For example, you can use 'Data.List.unfoldr unconsTokenStream' to convert between a
TokenStream
and '[TokenTree]'.
data Nonterminal a Source #
For interpolation during macro expansion (syntax::ast::NonTerminal
).
NtItem (Item a) | |
NtBlock (Block a) | |
NtStmt (Stmt a) | |
NtPat (Pat a) | |
NtExpr (Expr a) | |
NtTy (Ty a) | |
NtIdent Ident | |
NtPath (Path a) | |
NtTT TokenTree | |
NtArm (Arm a) | |
NtImplItem (ImplItem a) | |
NtTraitItem (TraitItem a) | |
NtGenerics (Generics a) | |
NtWhereClause (WhereClause a) | |
NtArg (Arg a) | |
NtLit (Lit a) |
Functor Nonterminal Source # | |
Generic1 Nonterminal Source # | |
PrettyAnnotated Nonterminal Source # | |
Eq a => Eq (Nonterminal a) Source # | |
Data a => Data (Nonterminal a) Source # | |
Ord a => Ord (Nonterminal a) Source # | |
Show a => Show (Nonterminal a) Source # | |
Generic (Nonterminal a) Source # | |
NFData a => NFData (Nonterminal a) Source # | |
Pretty (Nonterminal a) Source # | |
type Rep1 Nonterminal Source # | |
type Rep (Nonterminal a) Source # | |
Represents a macro invocation (syntax::ast::Mac
). The Path
indicates which macro is being
invoked, and the TokenStream
contains the source of the macro invocation.
Mac (Path a) TokenStream a |
Functor Mac Source # | |
Generic1 Mac Source # | |
PrettyAnnotated Mac Source # | |
Eq a => Eq (Mac a) Source # | |
Data a => Data (Mac a) Source # | |
Ord a => Ord (Mac a) Source # | |
Show a => Show (Mac a) Source # | |
Generic (Mac a) Source # | |
NFData a => NFData (Mac a) Source # | |
Located a => Located (Mac a) Source # | |
(Typeable * a, Monoid a) => Resolve (Mac a) Source # | |
Pretty (Mac a) Source # | |
type Rep1 Mac Source # | |
type Rep (Mac a) Source # | |
data MacStmtStyle Source #
Style of the macro statement (syntax::ast::MacStmtStyle
).
SemicolonMac | trailing semicolon (example: |
BracesMac | braces (example: |
Tokens
A general token (based on syntax::parse::token::Token
).
Unlike its libsyntax
counterpart, Token
has folded in syntax::parse::token::BinOpToken
and syntax::parse::token::BinOpEqToken
as regular tokens.
Equal |
|
Less |
|
Greater |
|
Ampersand |
|
Pipe |
|
Exclamation |
|
Tilde |
|
Plus |
|
Minus |
|
Star |
|
Slash |
|
Percent |
|
Caret |
|
GreaterEqual |
|
GreaterGreaterEqual |
|
AmpersandAmpersand |
|
PipePipe |
|
LessLess |
|
GreaterGreater |
|
EqualEqual |
|
NotEqual |
|
LessEqual |
|
LessLessEqual |
|
MinusEqual |
|
AmpersandEqual |
|
PipeEqual |
|
PlusEqual |
|
StarEqual |
|
SlashEqual |
|
CaretEqual |
|
PercentEqual |
|
At |
|
Dot |
|
DotDot |
|
DotDotEqual |
|
DotDotDot |
|
Comma |
|
Semicolon |
|
Colon |
|
ModSep |
|
RArrow |
|
LArrow |
|
FatArrow |
|
Pound |
|
Dollar |
|
Question |
|
OpenDelim !Delim | One of |
CloseDelim !Delim | One of |
LiteralTok LitTok (Maybe Name) | a literal token with an optional suffix (something like |
IdentTok Ident | an arbitrary identifier (something like |
Underscore |
|
LifetimeTok Ident | a lifetime (something like |
Space Space Name | whitespace |
Doc String !AttrStyle !Bool | doc comment with its contents, whether it is outer/inner, and whether it is inline or not |
Shebang |
|
Eof | end of file token |
Interpolated (Nonterminal Span) | can be expanded into several tokens in macro-expansion |
spaceNeeded :: Token -> Token -> Bool Source #
Check whether a space is needed between two tokens to avoid confusion
Rust is whitespace independent. Short of providing space between tokens, whitespace is all the same to the parser.
Whitespace | usual white space: |
Comment | comment (either inline or not) |
A delimiter token (syntax::parse::token::DelimToken
)
A literal token (syntax::parse::token::Lit
)
ByteTok Name | byte |
CharTok Name | character |
IntegerTok Name | integral literal (could have type |
FloatTok Name | floating point literal (could have type |
StrTok Name | string literal |
StrRawTok Name !Int | raw string literal and the number of |
ByteStrTok Name | byte string literal |
ByteStrRawTok Name !Int | raw byte string literal and the number of |
Distinguishes between attributes that decorate what follows them and attributes that are
describe the node that contains them (syntax::ast::AttrStyle
). These two cases need to be
distinguished only for pretty printing - they are otherwise fundamentally equivalent.
Example: #[repr(C)]
is an outer attribute while #![feature(slice_patterns)]
is an inner one