use super::*;
#[derive(Debug, Clone, PartialEq)]
pub struct Item {
pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
pub ident: Ident,
pub kind: ItemKind,
pub tokens: Option<TokenStream>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ItemKind {
Fn(Box<Fn>),
Struct(VariantData),
Enum(EnumDef),
Trait(Box<TraitDef>),
Impl(Box<ImplDef>),
Use(UseTree),
Static {
mutability: Mutability,
ty: Ty,
expr: Option<Expr>,
},
Const {
ty: Ty,
expr: Option<Expr>,
},
TyAlias {
generics: Generics,
ty: Option<Ty>,
},
Mod {
items: Option<Vec<Item>>,
},
MacroDef(Box<MacroDef>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct MacroDef {
pub macro_rules: bool, pub body: MacArgs, }
#[derive(Debug, Clone, PartialEq)]
pub struct Fn {
pub defaultness: Defaultness,
pub sig: FnSig,
pub generics: Generics,
pub body: Option<Block>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FnSig {
pub header: FnHeader,
pub decl: FnDecl,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FnHeader {
pub safety: Safety,
pub coroutine_kind: Option<CoroutineKind>,
pub constness: Constness,
pub ext: Extern,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FnDecl {
pub inputs: Vec<Param>,
pub output: FnRetTy,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Param {
pub attrs: AttrVec,
pub ty: Ty,
pub pat: Pat,
pub id: NodeId,
pub span: Span,
pub is_placeholder: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum FnRetTy {
Default(Span), Ty(Box<Ty>), }
#[derive(Debug, Clone, PartialEq)]
pub struct Generics {
pub params: Vec<GenericParam>,
pub where_clause: WhereClause,
pub span: Span,
}
impl Generics {
pub fn empty() -> Self {
Self { params: Vec::new(), where_clause: WhereClause::empty(), span: Span::DUMMY }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GenericParam {
pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub kind: GenericParamKind,
}
#[derive(Debug, Clone, PartialEq)]
pub enum GenericParamKind {
Lifetime(LifetimeParam),
Type(TypeParam),
Const(Box<ConstParam>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct LifetimeParam {
pub ident: Ident,
pub bounds: Vec<Lifetime>,
pub colon_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TypeParam {
pub ident: Ident,
pub bounds: Vec<GenericBound>,
pub default: Option<Ty>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstParam {
pub ident: Ident,
pub ty: Ty,
pub default: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhereClause {
pub has_where_token: bool,
pub predicates: Vec<WherePredicate>,
pub span: Span,
}
impl WhereClause {
pub fn empty() -> Self {
Self { has_where_token: false, predicates: Vec::new(), span: Span::DUMMY }
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum WherePredicate {
BoundPredicate(WhereBoundPredicate),
RegionPredicate(WhereRegionPredicate),
EqPredicate(WhereEqPredicate),
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhereBoundPredicate {
pub span: Span,
pub bounded_ty: Ty,
pub bounds: Vec<GenericBound>,
pub bound_lifetimes: Vec<LifetimeParam>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhereRegionPredicate {
pub span: Span,
pub lifetime: Lifetime,
pub bounds: Vec<Lifetime>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhereEqPredicate {
pub span: Span,
pub lhs_ty: Ty,
pub rhs_ty: Ty,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Ty {
pub id: NodeId,
pub kind: TyKind,
pub span: Span,
pub tokens: Option<TokenStream>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TyKind {
Path(Option<QSelf>, Path),
Ref {
lifetime: Option<Lifetime>,
mutability: Mutability,
ty: Box<Ty>,
},
Ptr {
mutability: Mutability,
ty: Box<Ty>,
},
Array {
ty: Box<Ty>,
len: Box<Expr>,
},
Slice(Box<Ty>),
Tuple(Vec<Ty>),
Never,
Infer,
BareFn {
safety: Safety,
abi: Option<String>,
inputs: Vec<BareFnParam>,
output: FnRetTy,
},
ImplTrait(Vec<GenericBound>),
TraitObject {
bounds: Vec<GenericBound>,
syntax: TraitObjectSyntax,
},
MacCall(MacCall),
Paren(Box<Ty>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Lifetime {
pub ident: Ident,
}
#[derive(Debug, Clone, PartialEq)]
pub struct QSelf {
}
#[derive(Debug, Clone, PartialEq)]
pub struct Pat {
pub id: NodeId,
pub kind: PatKind,
pub span: Span,
pub tokens: Option<TokenStream>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatKind {
Ident {
binding_mode: BindingMode,
ident: Ident,
sub: Option<Box<Pat>>,
},
Wild,
Struct {
path: Path,
fields: Vec<PatField>,
},
TupleStruct {
path: Path,
elems: Vec<Pat>,
},
Tuple(Vec<Pat>),
Slice(Vec<Pat>),
Or(Vec<Pat>),
Ref {
pat: Box<Pat>,
mutability: Mutability,
},
Lit(Box<Expr>),
Box(Box<Pat>),
Path {
qself: Option<QSelf>,
path: Path,
},
Range {
start: Option<Box<Expr>>,
end: Option<Box<Expr>>,
limits: RangeEnd,
},
Rest,
Paren(Box<Pat>),
Type {
pat: Box<Pat>,
ty: Box<Ty>,
},
Const(ConstBlock),
MacCall(MacCall),
Err,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PatField {
pub attrs: AttrVec,
pub ident: Ident,
pub pat: Pat,
pub is_shorthand: bool, pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BindingMode {
ByRef(Mutability),
ByValue(Mutability),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mutability {
Mut,
Not,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RangeEnd {
Included,
Excluded,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstBlock {
pub id: NodeId,
pub value: Box<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Block {
pub stmts: Vec<Stmt>,
pub id: NodeId,
pub rules: BlockCheckMode,
pub span: Span,
pub tokens: Option<TokenStream>,
pub could_be_bare_literal: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockCheckMode {
Default,
Unsafe,
}
impl Block {
pub fn new(stmts: Vec<Stmt>, id: NodeId, span: Span) -> Self {
Self {
stmts,
id,
rules: BlockCheckMode::Default,
span,
tokens: None,
could_be_bare_literal: false,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum VariantData {
Struct { fields: Vec<FieldDef>, recovered: bool },
Tuple(Vec<FieldDef>),
Unit,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EnumDef {
pub variants: Vec<Variant>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Variant {
pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
pub ident: Ident,
pub data: VariantData,
pub disr_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FieldDef {
pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
pub ident: Option<Ident>, pub ty: Ty,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraitDef {
pub safety: Safety,
pub generics: Generics,
pub bounds: Vec<GenericBound>,
pub items: Vec<AssocItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ImplDef {
pub safety: Safety,
pub generics: Generics,
pub of_trait: Option<TraitRef>, pub self_ty: Ty,
pub items: Vec<AssocItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AssocItem {
pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
pub ident: Ident,
pub kind: AssocItemKind,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AssocItemKind {
Fn(Box<Fn>),
Type(Box<Option<Ty>>), }
#[derive(Debug, Clone, PartialEq)]
pub struct TraitRef {
pub path: Path,
}
#[derive(Debug, Clone, PartialEq)]
pub enum GenericBound {
Trait(PolyTraitRef, TraitBoundModifier),
Outlives(Lifetime),
}
#[derive(Debug, Clone, PartialEq)]
pub struct PolyTraitRef {
pub trait_ref: TraitRef,
pub bound_lifetimes: Vec<LifetimeParam>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TraitBoundModifier {
None,
Maybe,
Negative,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BareFnParam {
pub attrs: AttrVec,
pub name: Option<Ident>,
pub ty: Ty,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TraitObjectSyntax {
Dyn,
None,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UseTree {
pub prefix: Path,
pub kind: UseTreeKind,
}
#[derive(Debug, Clone, PartialEq)]
pub enum UseTreeKind {
Simple(Option<Ident>),
Glob,
Nested(Vec<UseTree>),
}