1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // The Rust abstract syntax tree.
13 pub use self::AsmDialect::*;
14 pub use self::AttrStyle::*;
15 pub use self::BindingMode::*;
16 pub use self::BinOp::*;
17 pub use self::BlockCheckMode::*;
18 pub use self::CaptureClause::*;
19 pub use self::Decl_::*;
20 pub use self::ExplicitSelf_::*;
21 pub use self::Expr_::*;
22 pub use self::FloatTy::*;
23 pub use self::FunctionRetTy::*;
24 pub use self::ForeignItem_::*;
25 pub use self::ImplItem::*;
26 pub use self::InlinedItem::*;
27 pub use self::IntTy::*;
28 pub use self::Item_::*;
29 pub use self::KleeneOp::*;
30 pub use self::Lit_::*;
31 pub use self::LitIntType::*;
32 pub use self::LocalSource::*;
33 pub use self::Mac_::*;
34 pub use self::MacStmtStyle::*;
35 pub use self::MetaItem_::*;
36 pub use self::Method_::*;
37 pub use self::Mutability::*;
38 pub use self::Onceness::*;
39 pub use self::Pat_::*;
40 pub use self::PathListItem_::*;
41 pub use self::PatWildKind::*;
42 pub use self::PrimTy::*;
43 pub use self::Sign::*;
44 pub use self::Stmt_::*;
45 pub use self::StrStyle::*;
46 pub use self::StructFieldKind::*;
47 pub use self::TokenTree::*;
48 pub use self::TraitItem::*;
50 pub use self::TyParamBound::*;
51 pub use self::UintTy::*;
52 pub use self::UnboxedClosureKind::*;
53 pub use self::UnOp::*;
54 pub use self::UnsafeSource::*;
55 pub use self::VariantKind::*;
56 pub use self::ViewItem_::*;
57 pub use self::ViewPath_::*;
58 pub use self::Visibility::*;
59 pub use self::PathParameters::*;
61 use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
64 use owned_slice::OwnedSlice;
65 use parse::token::{InternedString, str_to_ident};
73 use serialize::{Encodable, Decodable, Encoder, Decoder};
75 // FIXME #6993: in librustc, uses of "ident" should be replaced
78 /// An identifier contains a Name (index into the interner
79 /// table) and a SyntaxContext to track renaming and
80 /// macro expansion per Flatt et al., "Macros
81 /// That Work Together"
82 #[derive(Clone, Copy, Hash, PartialOrd, Eq, Ord)]
85 pub ctxt: SyntaxContext
89 /// Construct an identifier with the given name and an empty context:
90 pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}}
92 pub fn as_str<'a>(&'a self) -> &'a str {
96 pub fn encode_with_hygiene(&self) -> String {
97 format!("\x00name_{},ctxt_{}\x00",
103 impl Show for Ident {
104 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105 write!(f, "{}#{}", self.name, self.ctxt)
110 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111 let Name(nm) = *self;
112 write!(f, "\"{}\"({})", token::get_name(*self).get(), nm)
116 impl PartialEq for Ident {
117 fn eq(&self, other: &Ident) -> bool {
118 if self.ctxt == other.ctxt {
119 self.name == other.name
121 // IF YOU SEE ONE OF THESE FAILS: it means that you're comparing
122 // idents that have different contexts. You can't fix this without
123 // knowing whether the comparison should be hygienic or non-hygienic.
124 // if it should be non-hygienic (most things are), just compare the
125 // 'name' fields of the idents. Or, even better, replace the idents
128 // On the other hand, if the comparison does need to be hygienic,
129 // one example and its non-hygienic counterpart would be:
130 // syntax::parse::token::Token::mtwt_eq
131 // syntax::ext::tt::macro_parser::token_name_eq
132 panic!("not allowed to compare these idents: {}, {}. \
133 Probably related to issue \\#6993", self, other);
136 fn ne(&self, other: &Ident) -> bool {
141 /// A SyntaxContext represents a chain of macro-expandings
142 /// and renamings. Each macro expansion corresponds to
145 // I'm representing this syntax context as an index into
146 // a table, in order to work around a compiler bug
147 // that's causing unreleased memory to cause core dumps
148 // and also perhaps to save some work in destructor checks.
149 // the special uint '0' will be used to indicate an empty
152 // this uint is a reference to a table stored in thread-local
154 pub type SyntaxContext = u32;
155 pub const EMPTY_CTXT : SyntaxContext = 0;
156 pub const ILLEGAL_CTXT : SyntaxContext = 1;
158 /// A name is a part of an identifier, representing a string or gensym. It's
159 /// the result of interning.
160 #[derive(Eq, Ord, PartialEq, PartialOrd, Hash,
161 RustcEncodable, RustcDecodable, Clone, Copy)]
162 pub struct Name(pub u32);
165 pub fn as_str<'a>(&'a self) -> &'a str {
167 // FIXME #12938: can't use copy_lifetime since &str isn't a &T
168 ::std::mem::transmute::<&str,&str>(token::get_name(*self).get())
172 pub fn uint(&self) -> uint {
173 let Name(nm) = *self;
177 pub fn ident(&self) -> Ident {
178 Ident { name: *self, ctxt: 0 }
182 /// A mark represents a unique id associated with a macro expansion
186 impl<S: Encoder<E>, E> Encodable<S, E> for Ident {
187 fn encode(&self, s: &mut S) -> Result<(), E> {
188 s.emit_str(token::get_ident(*self).get())
193 impl Encodable for Ident {
194 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
195 s.emit_str(token::get_ident(*self).get())
200 impl<D: Decoder<E>, E> Decodable<D, E> for Ident {
201 fn decode(d: &mut D) -> Result<Ident, E> {
202 Ok(str_to_ident(try!(d.read_str())[]))
207 impl Decodable for Ident {
208 fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
209 Ok(str_to_ident(try!(d.read_str())[]))
213 /// Function name (not all functions have names)
214 pub type FnIdent = Option<Ident>;
216 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash,
218 pub struct Lifetime {
224 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
225 pub struct LifetimeDef {
226 pub lifetime: Lifetime,
227 pub bounds: Vec<Lifetime>
230 /// A "Path" is essentially Rust's notion of a name; for instance:
231 /// std::cmp::PartialEq . It's represented as a sequence of identifiers,
232 /// along with a bunch of supporting information.
233 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
236 /// A `::foo` path, is relative to the crate root rather than current
237 /// module (like paths in an import).
239 /// The segments in the path: the things separated by `::`.
240 pub segments: Vec<PathSegment>,
243 /// A segment of a path: an identifier, an optional lifetime, and a set of
245 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
246 pub struct PathSegment {
247 /// The identifier portion of this path segment.
248 pub identifier: Ident,
250 /// Type/lifetime parameters attached to this path. They come in
251 /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
252 /// this is more than just simple syntactic sugar; the use of
253 /// parens affects the region binding rules, so we preserve the
255 pub parameters: PathParameters,
258 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
259 pub enum PathParameters {
260 AngleBracketedParameters(AngleBracketedParameterData),
261 ParenthesizedParameters(ParenthesizedParameterData),
264 impl PathParameters {
265 pub fn none() -> PathParameters {
266 AngleBracketedParameters(AngleBracketedParameterData {
267 lifetimes: Vec::new(),
268 types: OwnedSlice::empty(),
269 bindings: OwnedSlice::empty(),
273 pub fn is_empty(&self) -> bool {
275 AngleBracketedParameters(ref data) => data.is_empty(),
277 // Even if the user supplied no types, something like
278 // `X()` is equivalent to `X<(),()>`.
279 ParenthesizedParameters(..) => false,
283 pub fn has_lifetimes(&self) -> bool {
285 AngleBracketedParameters(ref data) => !data.lifetimes.is_empty(),
286 ParenthesizedParameters(_) => false,
290 pub fn has_types(&self) -> bool {
292 AngleBracketedParameters(ref data) => !data.types.is_empty(),
293 ParenthesizedParameters(..) => true,
297 /// Returns the types that the user wrote. Note that these do not necessarily map to the type
298 /// parameters in the parenthesized case.
299 pub fn types(&self) -> Vec<&P<Ty>> {
301 AngleBracketedParameters(ref data) => {
302 data.types.iter().collect()
304 ParenthesizedParameters(ref data) => {
306 .chain(data.output.iter())
312 pub fn lifetimes(&self) -> Vec<&Lifetime> {
314 AngleBracketedParameters(ref data) => {
315 data.lifetimes.iter().collect()
317 ParenthesizedParameters(_) => {
323 pub fn bindings(&self) -> Vec<&P<TypeBinding>> {
325 AngleBracketedParameters(ref data) => {
326 data.bindings.iter().collect()
328 ParenthesizedParameters(_) => {
335 /// A path like `Foo<'a, T>`
336 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
337 pub struct AngleBracketedParameterData {
338 /// The lifetime parameters for this path segment.
339 pub lifetimes: Vec<Lifetime>,
340 /// The type parameters for this path segment, if present.
341 pub types: OwnedSlice<P<Ty>>,
342 /// Bindings (equality constraints) on associated types, if present.
343 /// E.g., `Foo<A=Bar>`.
344 pub bindings: OwnedSlice<P<TypeBinding>>,
347 impl AngleBracketedParameterData {
348 fn is_empty(&self) -> bool {
349 self.lifetimes.is_empty() && self.types.is_empty() && self.bindings.is_empty()
353 /// A path like `Foo(A,B) -> C`
354 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
355 pub struct ParenthesizedParameterData {
357 pub inputs: Vec<P<Ty>>,
360 pub output: Option<P<Ty>>,
363 pub type CrateNum = u32;
365 pub type NodeId = u32;
367 #[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
368 RustcDecodable, Hash, Show, Copy)]
374 /// Item definitions in the currently-compiled crate would have the CrateNum
375 /// LOCAL_CRATE in their DefId.
376 pub const LOCAL_CRATE: CrateNum = 0;
377 pub const CRATE_NODE_ID: NodeId = 0;
379 /// When parsing and doing expansions, we initially give all AST nodes this AST
380 /// node value. Then later, in the renumber pass, we renumber them to have
381 /// small, positive ids.
382 pub const DUMMY_NODE_ID: NodeId = -1;
384 /// The AST represents all type param bounds as types.
385 /// typeck::collect::compute_bounds matches these against
386 /// the "special" built-in traits (see middle::lang_items) and
387 /// detects Copy, Send and Sync.
388 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
389 pub enum TyParamBound {
390 TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
391 RegionTyParamBound(Lifetime)
394 /// A modifier on a bound, currently this is only used for `?Sized`, where the
395 /// modifier is `Maybe`. Negative bounds should also be handled here.
396 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
397 pub enum TraitBoundModifier {
402 pub type TyParamBounds = OwnedSlice<TyParamBound>;
404 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
408 pub bounds: TyParamBounds,
409 pub default: Option<P<Ty>>,
413 /// Represents lifetimes and type parameters attached to a declaration
414 /// of a function, enum, trait, etc.
415 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
416 pub struct Generics {
417 pub lifetimes: Vec<LifetimeDef>,
418 pub ty_params: OwnedSlice<TyParam>,
419 pub where_clause: WhereClause,
423 pub fn is_parameterized(&self) -> bool {
424 self.lifetimes.len() + self.ty_params.len() > 0
426 pub fn is_lt_parameterized(&self) -> bool {
427 self.lifetimes.len() > 0
429 pub fn is_type_parameterized(&self) -> bool {
430 self.ty_params.len() > 0
434 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
435 pub struct WhereClause {
437 pub predicates: Vec<WherePredicate>,
440 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
441 pub enum WherePredicate {
442 BoundPredicate(WhereBoundPredicate),
443 RegionPredicate(WhereRegionPredicate),
444 EqPredicate(WhereEqPredicate)
447 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
448 pub struct WhereBoundPredicate {
450 pub bounded_ty: P<Ty>,
451 pub bounds: OwnedSlice<TyParamBound>,
454 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
455 pub struct WhereRegionPredicate {
457 pub lifetime: Lifetime,
458 pub bounds: Vec<Lifetime>,
461 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
462 pub struct WhereEqPredicate {
469 /// The set of MetaItems that define the compilation environment of the crate,
470 /// used to drive conditional compilation
471 pub type CrateConfig = Vec<P<MetaItem>> ;
473 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
476 pub attrs: Vec<Attribute>,
477 pub config: CrateConfig,
479 pub exported_macros: Vec<MacroDef>,
482 pub type MetaItem = Spanned<MetaItem_>;
484 #[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
486 MetaWord(InternedString),
487 MetaList(InternedString, Vec<P<MetaItem>>),
488 MetaNameValue(InternedString, Lit),
491 // can't be derived because the MetaList requires an unordered comparison
492 impl PartialEq for MetaItem_ {
493 fn eq(&self, other: &MetaItem_) -> bool {
495 MetaWord(ref ns) => match *other {
496 MetaWord(ref no) => (*ns) == (*no),
499 MetaNameValue(ref ns, ref vs) => match *other {
500 MetaNameValue(ref no, ref vo) => {
501 (*ns) == (*no) && vs.node == vo.node
505 MetaList(ref ns, ref miss) => match *other {
506 MetaList(ref no, ref miso) => {
508 miss.iter().all(|mi| miso.iter().any(|x| x.node == mi.node))
516 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
518 pub view_items: Vec<ViewItem>,
519 pub stmts: Vec<P<Stmt>>,
520 pub expr: Option<P<Expr>>,
522 pub rules: BlockCheckMode,
526 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
533 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
534 pub struct FieldPat {
537 pub is_shorthand: bool,
540 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
541 pub enum BindingMode {
542 BindByRef(Mutability),
543 BindByValue(Mutability),
546 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
547 pub enum PatWildKind {
548 /// Represents the wildcard pattern `_`
551 /// Represents the wildcard pattern `..`
555 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
557 /// Represents a wildcard pattern (either `_` or `..`)
558 PatWild(PatWildKind),
560 /// A PatIdent may either be a new bound variable,
561 /// or a nullary enum (in which case the third field
563 /// In the nullary enum case, the parser can't determine
564 /// which it is. The resolver determines this, and
565 /// records this pattern's NodeId in an auxiliary
566 /// set (of "PatIdents that refer to nullary enums")
567 PatIdent(BindingMode, SpannedIdent, Option<P<Pat>>),
569 /// "None" means a * pattern where we don't bind the fields to names.
570 PatEnum(Path, Option<Vec<P<Pat>>>),
572 PatStruct(Path, Vec<Spanned<FieldPat>>, bool),
575 PatRegion(P<Pat>, Mutability), // reference pattern
577 PatRange(P<Expr>, P<Expr>),
578 /// [a, b, ..i, y, z] is represented as:
579 /// PatVec(box [a, b], Some(i), box [y, z])
580 PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
584 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
585 pub enum Mutability {
590 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
612 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
620 pub type Stmt = Spanned<Stmt_>;
622 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
624 /// Could be an item or a local (let) binding:
625 StmtDecl(P<Decl>, NodeId),
627 /// Expr without trailing semi-colon (must have unit type):
628 StmtExpr(P<Expr>, NodeId),
630 /// Expr with trailing semi-colon (may have any type):
631 StmtSemi(P<Expr>, NodeId),
633 StmtMac(P<Mac>, MacStmtStyle),
636 #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
637 pub enum MacStmtStyle {
638 /// The macro statement had a trailing semicolon, e.g. `foo! { ... };`
639 /// `foo!(...);`, `foo![...];`
640 MacStmtWithSemicolon,
641 /// The macro statement had braces; e.g. foo! { ... }
643 /// The macro statement had parentheses or brackets and no semicolon; e.g.
644 /// `foo!(...)`. All of these will end up being converted into macro
646 MacStmtWithoutBraces,
649 /// Where a local declaration came from: either a true `let ... =
650 /// ...;`, or one desugared from the pattern of a for loop.
651 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
652 pub enum LocalSource {
657 // FIXME (pending discussion of #1697, #2178...): local should really be
658 // a refinement on pat.
659 /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
660 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
663 pub ty: Option<P<Ty>>,
664 pub init: Option<P<Expr>>,
667 pub source: LocalSource,
670 pub type Decl = Spanned<Decl_>;
672 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
674 /// A local (let) binding:
680 /// represents one arm of a 'match'
681 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
683 pub attrs: Vec<Attribute>,
684 pub pats: Vec<P<Pat>>,
685 pub guard: Option<P<Expr>>,
689 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
691 pub ident: SpannedIdent,
696 pub type SpannedIdent = Spanned<Ident>;
698 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
699 pub enum BlockCheckMode {
701 UnsafeBlock(UnsafeSource),
704 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
705 pub enum UnsafeSource {
710 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
717 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
719 /// First expr is the place; second expr is the value.
720 ExprBox(Option<P<Expr>>, P<Expr>),
721 ExprVec(Vec<P<Expr>>),
722 ExprCall(P<Expr>, Vec<P<Expr>>),
723 ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
724 ExprTup(Vec<P<Expr>>),
725 ExprBinary(BinOp, P<Expr>, P<Expr>),
726 ExprUnary(UnOp, P<Expr>),
728 ExprCast(P<Expr>, P<Ty>),
729 ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
730 ExprIfLet(P<Pat>, P<Expr>, P<Block>, Option<P<Expr>>),
731 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
732 ExprWhile(P<Expr>, P<Block>, Option<Ident>),
733 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
734 ExprWhileLet(P<Pat>, P<Expr>, P<Block>, Option<Ident>),
735 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
736 ExprForLoop(P<Pat>, P<Expr>, P<Block>, Option<Ident>),
737 // Conditionless loop (can be exited with break, cont, or ret)
738 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
739 ExprLoop(P<Block>, Option<Ident>),
740 ExprMatch(P<Expr>, Vec<Arm>, MatchSource),
741 ExprClosure(CaptureClause, Option<UnboxedClosureKind>, P<FnDecl>, P<Block>),
744 ExprAssign(P<Expr>, P<Expr>),
745 ExprAssignOp(BinOp, P<Expr>, P<Expr>),
746 ExprField(P<Expr>, SpannedIdent),
747 ExprTupField(P<Expr>, Spanned<uint>),
748 ExprIndex(P<Expr>, P<Expr>),
749 ExprRange(Option<P<Expr>>, Option<P<Expr>>),
751 /// Variable reference, possibly containing `::` and/or
752 /// type parameters, e.g. foo::bar::<baz>
755 ExprAddrOf(Mutability, P<Expr>),
756 ExprBreak(Option<Ident>),
757 ExprAgain(Option<Ident>),
758 ExprRet(Option<P<Expr>>),
760 ExprInlineAsm(InlineAsm),
764 /// A struct literal expression.
765 ExprStruct(Path, Vec<Field>, Option<P<Expr>> /* base */),
767 /// A vector literal constructed from one repeated element.
768 ExprRepeat(P<Expr> /* element */, P<Expr> /* count */),
770 /// No-op: used solely so we can pretty-print faithfully
774 /// A "qualified path":
776 /// <Vec<T> as SomeTrait>::SomeAssociatedItem
777 /// ^~~~~ ^~~~~~~~~ ^~~~~~~~~~~~~~~~~~
778 /// self_type trait_name item_name
779 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
781 pub self_type: P<Ty>,
782 pub trait_ref: P<TraitRef>,
783 pub item_name: Ident, // FIXME(#20301) -- should use Name
786 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
787 pub enum MatchSource {
789 IfLetDesugar { contains_else_clause: bool },
793 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
794 pub enum CaptureClause {
799 /// A delimited sequence of token trees
800 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
801 pub struct Delimited {
802 /// The type of delimiter
803 pub delim: token::DelimToken,
804 /// The span covering the opening delimiter
806 /// The delimited sequence of token trees
807 pub tts: Vec<TokenTree>,
808 /// The span covering the closing delimiter
809 pub close_span: Span,
813 /// Returns the opening delimiter as a token.
814 pub fn open_token(&self) -> token::Token {
815 token::OpenDelim(self.delim)
818 /// Returns the closing delimiter as a token.
819 pub fn close_token(&self) -> token::Token {
820 token::CloseDelim(self.delim)
823 /// Returns the opening delimiter as a token tree.
824 pub fn open_tt(&self) -> TokenTree {
825 TtToken(self.open_span, self.open_token())
828 /// Returns the closing delimiter as a token tree.
829 pub fn close_tt(&self) -> TokenTree {
830 TtToken(self.close_span, self.close_token())
834 /// A sequence of token treesee
835 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
836 pub struct SequenceRepetition {
837 /// The sequence of token trees
838 pub tts: Vec<TokenTree>,
839 /// The optional separator
840 pub separator: Option<token::Token>,
841 /// Whether the sequence can be repeated zero (*), or one or more times (+)
843 /// The number of `MatchNt`s that appear in the sequence (and subsequences)
844 pub num_captures: uint,
847 /// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
848 /// for token sequences.
849 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
855 /// When the main rust parser encounters a syntax-extension invocation, it
856 /// parses the arguments to the invocation as a token-tree. This is a very
857 /// loose structure, such that all sorts of different AST-fragments can
858 /// be passed to syntax extensions using a uniform type.
860 /// If the syntax extension is an MBE macro, it will attempt to match its
861 /// LHS token tree against the provided token tree, and if it finds a
862 /// match, will transcribe the RHS token tree, splicing in any captured
863 /// macro_parser::matched_nonterminals into the `SubstNt`s it finds.
865 /// The RHS of an MBE macro is the only place `SubstNt`s are substituted.
866 /// Nothing special happens to misnamed or misplaced `SubstNt`s.
867 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
868 #[doc="For macro invocations; parsing is delegated to the macro"]
871 TtToken(Span, token::Token),
872 /// A delimited sequence of token trees
873 TtDelimited(Span, Rc<Delimited>),
875 // This only makes sense in MBE macros.
877 /// A kleene-style repetition sequence with a span
878 // FIXME(eddyb) #12938 Use DST.
879 TtSequence(Span, Rc<SequenceRepetition>),
883 pub fn len(&self) -> uint {
885 TtToken(_, token::DocComment(_)) => 2,
886 TtToken(_, token::SubstNt(..)) => 2,
887 TtToken(_, token::SpecialVarNt(..)) => 2,
888 TtToken(_, token::MatchNt(..)) => 3,
889 TtDelimited(_, ref delimed) => {
890 delimed.tts.len() + 2
892 TtSequence(_, ref seq) => {
899 pub fn get_tt(&self, index: uint) -> TokenTree {
900 match (self, index) {
901 (&TtToken(sp, token::DocComment(_)), 0) => {
902 TtToken(sp, token::Pound)
904 (&TtToken(sp, token::DocComment(name)), 1) => {
905 TtDelimited(sp, Rc::new(Delimited {
906 delim: token::Bracket,
908 tts: vec![TtToken(sp, token::Ident(token::str_to_ident("doc"),
910 TtToken(sp, token::Eq),
911 TtToken(sp, token::Literal(token::Str_(name), None))],
915 (&TtDelimited(_, ref delimed), _) => {
917 return delimed.open_tt();
919 if index == delimed.tts.len() + 1 {
920 return delimed.close_tt();
922 delimed.tts[index - 1].clone()
924 (&TtToken(sp, token::SubstNt(name, name_st)), _) => {
925 let v = [TtToken(sp, token::Dollar),
926 TtToken(sp, token::Ident(name, name_st))];
929 (&TtToken(sp, token::SpecialVarNt(var)), _) => {
930 let v = [TtToken(sp, token::Dollar),
931 TtToken(sp, token::Ident(token::str_to_ident(var.as_str()),
935 (&TtToken(sp, token::MatchNt(name, kind, name_st, kind_st)), _) => {
936 let v = [TtToken(sp, token::SubstNt(name, name_st)),
937 TtToken(sp, token::Colon),
938 TtToken(sp, token::Ident(kind, kind_st))];
941 (&TtSequence(_, ref seq), _) => {
942 seq.tts[index].clone()
944 _ => panic!("Cannot expand a token tree")
948 /// Returns the `Span` corresponding to this token tree.
949 pub fn get_span(&self) -> Span {
951 TtToken(span, _) => span,
952 TtDelimited(span, _) => span,
953 TtSequence(span, _) => span,
958 pub type Mac = Spanned<Mac_>;
960 /// Represents a macro invocation. The Path indicates which macro
961 /// is being invoked, and the vector of token-trees contains the source
962 /// of the macro invocation.
963 /// There's only one flavor, now, so this could presumably be simplified.
964 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
966 // NB: the additional ident for a macro_rules-style macro is actually
967 // stored in the enclosing item. Oog.
968 MacInvocTT(Path, Vec<TokenTree> , SyntaxContext), // new macro-invocation
971 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
977 pub type Lit = Spanned<Lit_>;
979 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
985 impl<T> Sign where T: Int {
986 pub fn new(n: T) -> Sign {
995 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
996 pub enum LitIntType {
997 SignedIntLit(IntTy, Sign),
998 UnsignedIntLit(UintTy),
999 UnsuffixedIntLit(Sign)
1003 pub fn suffix_len(&self) -> uint {
1005 UnsuffixedIntLit(_) => 0,
1006 SignedIntLit(s, _) => s.suffix_len(),
1007 UnsignedIntLit(u) => u.suffix_len()
1012 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1014 LitStr(InternedString, StrStyle),
1015 LitBinary(Rc<Vec<u8>>),
1018 LitInt(u64, LitIntType),
1019 LitFloat(InternedString, FloatTy),
1020 LitFloatUnsuffixed(InternedString),
1024 // NB: If you change this, you'll probably want to change the corresponding
1025 // type structure in middle/ty.rs as well.
1026 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1029 pub mutbl: Mutability,
1032 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1033 pub struct TypeField {
1039 /// Represents a required method in a trait declaration,
1040 /// one without a default implementation
1041 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1042 pub struct TypeMethod {
1044 pub attrs: Vec<Attribute>,
1045 pub unsafety: Unsafety,
1047 pub decl: P<FnDecl>,
1048 pub generics: Generics,
1049 pub explicit_self: ExplicitSelf,
1052 pub vis: Visibility,
1055 /// Represents a method declaration in a trait declaration, possibly including
1056 /// a default implementation A trait method is either required (meaning it
1057 /// doesn't have an implementation, just a signature) or provided (meaning it
1058 /// has a default implementation).
1059 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1060 pub enum TraitItem {
1061 RequiredMethod(TypeMethod),
1062 ProvidedMethod(P<Method>),
1063 TypeTraitItem(P<AssociatedType>),
1066 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1068 MethodImplItem(P<Method>),
1069 TypeImplItem(P<Typedef>),
1072 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1073 pub struct AssociatedType {
1074 pub attrs: Vec<Attribute>,
1075 pub ty_param: TyParam,
1078 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1079 pub struct Typedef {
1083 pub vis: Visibility,
1084 pub attrs: Vec<Attribute>,
1088 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1097 impl fmt::Show for IntTy {
1098 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1099 write!(f, "{}", ast_util::int_ty_to_string(*self, None))
1104 pub fn suffix_len(&self) -> uint {
1108 TyI16 | TyI32 | TyI64 => 3,
1113 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1123 pub fn suffix_len(&self) -> uint {
1127 TyU16 | TyU32 | TyU64 => 3,
1132 impl fmt::Show for UintTy {
1133 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1134 write!(f, "{}", ast_util::uint_ty_to_string(*self, None))
1138 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1144 impl fmt::Show for FloatTy {
1145 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1146 write!(f, "{}", ast_util::float_ty_to_string(*self))
1151 pub fn suffix_len(&self) -> uint {
1153 TyF32 | TyF64 => 3, // add F128 handling here
1158 // Bind a type to an associated type: `A=Foo`.
1159 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1160 pub struct TypeBinding {
1168 // NB PartialEq method appears below.
1169 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1176 /// Not represented directly in the AST, referred to by name through a ty_path.
1177 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1187 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1193 impl fmt::Show for Onceness {
1194 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1196 Once => "once".fmt(f),
1197 Many => "many".fmt(f),
1202 /// Represents the type of a closure
1203 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1204 pub struct ClosureTy {
1205 pub lifetimes: Vec<LifetimeDef>,
1206 pub unsafety: Unsafety,
1207 pub onceness: Onceness,
1208 pub decl: P<FnDecl>,
1209 pub bounds: TyParamBounds,
1212 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1213 pub struct BareFnTy {
1214 pub unsafety: Unsafety,
1216 pub lifetimes: Vec<LifetimeDef>,
1220 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1221 /// The different kinds of types recognized by the compiler
1224 /// A fixed length array (`[T, ..n]`)
1225 TyFixedLengthVec(P<Ty>, P<Expr>),
1226 /// A raw pointer (`*const T` or `*mut T`)
1228 /// A reference (`&'a T` or `&'a mut T`)
1229 TyRptr(Option<Lifetime>, MutTy),
1230 /// A bare function (e.g. `fn(uint) -> bool`)
1231 TyBareFn(P<BareFnTy>),
1232 /// A tuple (`(A, B, C, D,...)`)
1234 /// A path (`module::module::...::Type`) or primitive
1236 /// Type parameters are stored in the Path itself
1237 TyPath(Path, NodeId),
1238 /// Something like `A+B`. Note that `B` must always be a path.
1239 TyObjectSum(P<Ty>, TyParamBounds),
1240 /// A type like `for<'a> Foo<&'a Bar>`
1241 TyPolyTraitRef(TyParamBounds),
1242 /// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
1244 /// No-op; kept solely so that we can pretty-print faithfully
1248 /// TyInfer means the type should be inferred instead of it having been
1249 /// specified. This can appear anywhere in a type.
1253 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1254 pub enum AsmDialect {
1259 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1260 pub struct InlineAsm {
1261 pub asm: InternedString,
1262 pub asm_str_style: StrStyle,
1263 pub outputs: Vec<(InternedString, P<Expr>, bool)>,
1264 pub inputs: Vec<(InternedString, P<Expr>)>,
1265 pub clobbers: Vec<InternedString>,
1267 pub alignstack: bool,
1268 pub dialect: AsmDialect,
1269 pub expn_id: ExpnId,
1272 /// represents an argument in a function header
1273 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1281 pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg {
1282 let path = Spanned{span:span,node:self_ident};
1284 // HACK(eddyb) fake type for the self argument.
1292 node: PatIdent(BindByValue(mutability), path, None),
1300 /// represents the header (not the body) of a function declaration
1301 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1303 pub inputs: Vec<Arg>,
1304 pub output: FunctionRetTy,
1308 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1314 impl fmt::Show for Unsafety {
1315 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1317 Unsafety::Normal => "normal".fmt(f),
1318 Unsafety::Unsafe => "unsafe".fmt(f),
1323 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1324 pub enum ImplPolarity {
1325 /// impl Trait for Type
1327 /// impl !Trait for Type
1331 impl fmt::Show for ImplPolarity {
1332 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1334 ImplPolarity::Positive => "positive".fmt(f),
1335 ImplPolarity::Negative => "negative".fmt(f),
1341 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1342 pub enum FunctionRetTy {
1343 /// Functions with return type ! that always
1344 /// raise an error or exit (i.e. never return to the caller)
1350 impl FunctionRetTy {
1351 pub fn span(&self) -> Span {
1353 NoReturn(span) => span,
1354 Return(ref ty) => ty.span
1359 /// Represents the kind of 'self' associated with a method
1360 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1361 pub enum ExplicitSelf_ {
1366 /// `&'lt self`, `&'lt mut self`
1367 SelfRegion(Option<Lifetime>, Mutability, Ident),
1369 SelfExplicit(P<Ty>, Ident),
1372 pub type ExplicitSelf = Spanned<ExplicitSelf_>;
1374 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1376 pub attrs: Vec<Attribute>,
1382 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1384 /// Represents a method declaration
1393 /// Represents a macro in method position
1397 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1399 /// A span from the first token past `{` to the last token until `}`.
1400 /// For `mod foo;`, the inner span ranges from the first token
1401 /// to the last token in the external file.
1403 pub view_items: Vec<ViewItem>,
1404 pub items: Vec<P<Item>>,
1407 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1408 pub struct ForeignMod {
1410 pub view_items: Vec<ViewItem>,
1411 pub items: Vec<P<ForeignItem>>,
1414 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1415 pub struct VariantArg {
1420 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1421 pub enum VariantKind {
1422 TupleVariantKind(Vec<VariantArg>),
1423 StructVariantKind(P<StructDef>),
1426 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1427 pub struct EnumDef {
1428 pub variants: Vec<P<Variant>>,
1431 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1432 pub struct Variant_ {
1434 pub attrs: Vec<Attribute>,
1435 pub kind: VariantKind,
1437 pub disr_expr: Option<P<Expr>>,
1438 pub vis: Visibility,
1441 pub type Variant = Spanned<Variant_>;
1443 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1444 pub enum PathListItem_ {
1445 PathListIdent { name: Ident, id: NodeId },
1446 PathListMod { id: NodeId }
1449 impl PathListItem_ {
1450 pub fn id(&self) -> NodeId {
1452 PathListIdent { id, .. } | PathListMod { id } => id
1457 pub type PathListItem = Spanned<PathListItem_>;
1459 pub type ViewPath = Spanned<ViewPath_>;
1461 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1462 pub enum ViewPath_ {
1464 /// `foo::bar::baz as quux`
1468 /// `foo::bar::baz` (with `as baz` implicitly on the right)
1469 ViewPathSimple(Ident, Path, NodeId),
1472 ViewPathGlob(Path, NodeId),
1474 /// `foo::bar::{a,b,c}`
1475 ViewPathList(Path, Vec<PathListItem> , NodeId)
1478 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1479 pub struct ViewItem {
1480 pub node: ViewItem_,
1481 pub attrs: Vec<Attribute>,
1482 pub vis: Visibility,
1486 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1487 pub enum ViewItem_ {
1488 /// Ident: name used to refer to this crate in the code
1489 /// optional (InternedString,StrStyle): if present, this is a location
1490 /// (containing arbitrary characters) from which to fetch the crate sources
1491 /// For example, extern crate whatever = "github.com/rust-lang/rust"
1492 ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
1493 ViewItemUse(P<ViewPath>),
1496 /// Meta-data associated with an item
1497 pub type Attribute = Spanned<Attribute_>;
1499 /// Distinguishes between Attributes that decorate items and Attributes that
1500 /// are contained as statements within items. These two cases need to be
1501 /// distinguished for pretty-printing.
1502 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1503 pub enum AttrStyle {
1508 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1509 pub struct AttrId(pub uint);
1511 /// Doc-comments are promoted to attributes that have is_sugared_doc = true
1512 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1513 pub struct Attribute_ {
1515 pub style: AttrStyle,
1516 pub value: P<MetaItem>,
1517 pub is_sugared_doc: bool,
1520 /// TraitRef's appear in impls.
1521 /// resolve maps each TraitRef's ref_id to its defining trait; that's all
1522 /// that the ref_id is for. The impl_id maps to the "self type" of this impl.
1523 /// If this impl is an ItemImpl, the impl_id is redundant (it could be the
1524 /// same as the impl's node id).
1525 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1526 pub struct TraitRef {
1531 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1532 pub struct PolyTraitRef {
1533 /// The `'a` in `<'a> Foo<&'a T>`
1534 pub bound_lifetimes: Vec<LifetimeDef>,
1536 /// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
1537 pub trait_ref: TraitRef,
1540 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1541 pub enum Visibility {
1547 pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
1549 &Inherited => parent_visibility,
1555 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1556 pub struct StructField_ {
1557 pub kind: StructFieldKind,
1560 pub attrs: Vec<Attribute>,
1564 pub fn ident(&self) -> Option<Ident> {
1566 NamedField(ref ident, _) => Some(ident.clone()),
1567 UnnamedField(_) => None
1572 pub type StructField = Spanned<StructField_>;
1574 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1575 pub enum StructFieldKind {
1576 NamedField(Ident, Visibility),
1577 /// Element of a tuple-like struct
1578 UnnamedField(Visibility),
1581 impl StructFieldKind {
1582 pub fn is_unnamed(&self) -> bool {
1584 UnnamedField(..) => true,
1585 NamedField(..) => false,
1590 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1591 pub struct StructDef {
1592 /// Fields, not including ctor
1593 pub fields: Vec<StructField>,
1594 /// ID of the constructor. This is only used for tuple- or enum-like
1596 pub ctor_id: Option<NodeId>,
1600 FIXME (#3300): Should allow items to be anonymous. Right now
1601 we just use dummy names for anon items.
1603 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1606 pub attrs: Vec<Attribute>,
1609 pub vis: Visibility,
1613 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1615 ItemStatic(P<Ty>, Mutability, P<Expr>),
1616 ItemConst(P<Ty>, P<Expr>),
1617 ItemFn(P<FnDecl>, Unsafety, Abi, Generics, P<Block>),
1619 ItemForeignMod(ForeignMod),
1620 ItemTy(P<Ty>, Generics),
1621 ItemEnum(EnumDef, Generics),
1622 ItemStruct(P<StructDef>, Generics),
1623 /// Represents a Trait Declaration
1631 Option<TraitRef>, // (optional) trait this impl implements
1634 /// A macro invocation (which includes macro definition)
1639 pub fn descriptive_variant(&self) -> &str {
1641 ItemStatic(..) => "static item",
1642 ItemConst(..) => "constant item",
1643 ItemFn(..) => "function",
1644 ItemMod(..) => "module",
1645 ItemForeignMod(..) => "foreign module",
1646 ItemTy(..) => "type alias",
1647 ItemEnum(..) => "enum",
1648 ItemStruct(..) => "struct",
1649 ItemTrait(..) => "trait",
1651 ItemImpl(..) => "item"
1656 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1657 pub struct ForeignItem {
1659 pub attrs: Vec<Attribute>,
1660 pub node: ForeignItem_,
1663 pub vis: Visibility,
1666 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1667 pub enum ForeignItem_ {
1668 ForeignItemFn(P<FnDecl>, Generics),
1669 ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
1673 pub fn descriptive_variant(&self) -> &str {
1675 ForeignItemFn(..) => "foreign function",
1676 ForeignItemStatic(..) => "foreign static item"
1681 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1682 pub enum UnboxedClosureKind {
1683 FnUnboxedClosureKind,
1684 FnMutUnboxedClosureKind,
1685 FnOnceUnboxedClosureKind,
1688 /// The data we save and restore about an inlined item or method. This is not
1689 /// part of the AST that we parse from a file, but it becomes part of the tree
1691 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1692 pub enum InlinedItem {
1694 IITraitItem(DefId /* impl id */, TraitItem),
1695 IIImplItem(DefId /* impl id */, ImplItem),
1696 IIForeign(P<ForeignItem>),
1699 /// A macro definition, in this crate or imported from another.
1701 /// Not parsed directly, but created on macro import or `macro_rules!` expansion.
1702 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1703 pub struct MacroDef {
1705 pub attrs: Vec<Attribute>,
1708 pub imported_from: Option<Ident>,
1710 pub use_locally: bool,
1711 pub body: Vec<TokenTree>,
1716 use serialize::json;
1722 // are ASTs encodable?
1724 fn check_asts_encodable() {
1725 fn assert_encodable<T: serialize::Encodable>() {}
1726 assert_encodable::<Crate>();