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 //NOTE(stage0): remove after snapshot
104 impl fmt::Show for Ident {
105 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
106 write!(f, "{}#{}", self.name, self.ctxt)
110 impl fmt::String for Ident {
111 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
112 fmt::String::fmt(&self.name, f)
116 impl fmt::Show for Name {
117 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
118 let Name(nm) = *self;
119 write!(f, "{:?}({})", token::get_name(*self).get(), nm)
123 impl fmt::String for Name {
124 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125 fmt::String::fmt(token::get_name(*self).get(), f)
129 impl PartialEq for Ident {
130 fn eq(&self, other: &Ident) -> bool {
131 if self.ctxt == other.ctxt {
132 self.name == other.name
134 // IF YOU SEE ONE OF THESE FAILS: it means that you're comparing
135 // idents that have different contexts. You can't fix this without
136 // knowing whether the comparison should be hygienic or non-hygienic.
137 // if it should be non-hygienic (most things are), just compare the
138 // 'name' fields of the idents. Or, even better, replace the idents
141 // On the other hand, if the comparison does need to be hygienic,
142 // one example and its non-hygienic counterpart would be:
143 // syntax::parse::token::Token::mtwt_eq
144 // syntax::ext::tt::macro_parser::token_name_eq
145 panic!("not allowed to compare these idents: {}, {}. \
146 Probably related to issue \\#6993", self, other);
149 fn ne(&self, other: &Ident) -> bool {
154 /// A SyntaxContext represents a chain of macro-expandings
155 /// and renamings. Each macro expansion corresponds to
158 // I'm representing this syntax context as an index into
159 // a table, in order to work around a compiler bug
160 // that's causing unreleased memory to cause core dumps
161 // and also perhaps to save some work in destructor checks.
162 // the special uint '0' will be used to indicate an empty
165 // this uint is a reference to a table stored in thread-local
167 pub type SyntaxContext = u32;
168 pub const EMPTY_CTXT : SyntaxContext = 0;
169 pub const ILLEGAL_CTXT : SyntaxContext = 1;
171 /// A name is a part of an identifier, representing a string or gensym. It's
172 /// the result of interning.
173 #[derive(Eq, Ord, PartialEq, PartialOrd, Hash,
174 RustcEncodable, RustcDecodable, Clone, Copy)]
175 pub struct Name(pub u32);
178 pub fn as_str<'a>(&'a self) -> &'a str {
180 // FIXME #12938: can't use copy_lifetime since &str isn't a &T
181 ::std::mem::transmute::<&str,&str>(token::get_name(*self).get())
185 pub fn uint(&self) -> uint {
186 let Name(nm) = *self;
190 pub fn ident(&self) -> Ident {
191 Ident { name: *self, ctxt: 0 }
195 /// A mark represents a unique id associated with a macro expansion
198 impl Encodable for Ident {
199 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
200 s.emit_str(token::get_ident(*self).get())
204 impl Decodable for Ident {
205 fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
206 Ok(str_to_ident(&try!(d.read_str())[]))
210 /// Function name (not all functions have names)
211 pub type FnIdent = Option<Ident>;
213 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash,
215 pub struct Lifetime {
221 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
222 pub struct LifetimeDef {
223 pub lifetime: Lifetime,
224 pub bounds: Vec<Lifetime>
227 /// A "Path" is essentially Rust's notion of a name; for instance:
228 /// std::cmp::PartialEq . It's represented as a sequence of identifiers,
229 /// along with a bunch of supporting information.
230 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
233 /// A `::foo` path, is relative to the crate root rather than current
234 /// module (like paths in an import).
236 /// The segments in the path: the things separated by `::`.
237 pub segments: Vec<PathSegment>,
240 /// A segment of a path: an identifier, an optional lifetime, and a set of
242 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
243 pub struct PathSegment {
244 /// The identifier portion of this path segment.
245 pub identifier: Ident,
247 /// Type/lifetime parameters attached to this path. They come in
248 /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
249 /// this is more than just simple syntactic sugar; the use of
250 /// parens affects the region binding rules, so we preserve the
252 pub parameters: PathParameters,
255 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
256 pub enum PathParameters {
257 AngleBracketedParameters(AngleBracketedParameterData),
258 ParenthesizedParameters(ParenthesizedParameterData),
261 impl PathParameters {
262 pub fn none() -> PathParameters {
263 AngleBracketedParameters(AngleBracketedParameterData {
264 lifetimes: Vec::new(),
265 types: OwnedSlice::empty(),
266 bindings: OwnedSlice::empty(),
270 pub fn is_empty(&self) -> bool {
272 AngleBracketedParameters(ref data) => data.is_empty(),
274 // Even if the user supplied no types, something like
275 // `X()` is equivalent to `X<(),()>`.
276 ParenthesizedParameters(..) => false,
280 pub fn has_lifetimes(&self) -> bool {
282 AngleBracketedParameters(ref data) => !data.lifetimes.is_empty(),
283 ParenthesizedParameters(_) => false,
287 pub fn has_types(&self) -> bool {
289 AngleBracketedParameters(ref data) => !data.types.is_empty(),
290 ParenthesizedParameters(..) => true,
294 /// Returns the types that the user wrote. Note that these do not necessarily map to the type
295 /// parameters in the parenthesized case.
296 pub fn types(&self) -> Vec<&P<Ty>> {
298 AngleBracketedParameters(ref data) => {
299 data.types.iter().collect()
301 ParenthesizedParameters(ref data) => {
303 .chain(data.output.iter())
309 pub fn lifetimes(&self) -> Vec<&Lifetime> {
311 AngleBracketedParameters(ref data) => {
312 data.lifetimes.iter().collect()
314 ParenthesizedParameters(_) => {
320 pub fn bindings(&self) -> Vec<&P<TypeBinding>> {
322 AngleBracketedParameters(ref data) => {
323 data.bindings.iter().collect()
325 ParenthesizedParameters(_) => {
332 /// A path like `Foo<'a, T>`
333 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
334 pub struct AngleBracketedParameterData {
335 /// The lifetime parameters for this path segment.
336 pub lifetimes: Vec<Lifetime>,
337 /// The type parameters for this path segment, if present.
338 pub types: OwnedSlice<P<Ty>>,
339 /// Bindings (equality constraints) on associated types, if present.
340 /// E.g., `Foo<A=Bar>`.
341 pub bindings: OwnedSlice<P<TypeBinding>>,
344 impl AngleBracketedParameterData {
345 fn is_empty(&self) -> bool {
346 self.lifetimes.is_empty() && self.types.is_empty() && self.bindings.is_empty()
350 /// A path like `Foo(A,B) -> C`
351 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
352 pub struct ParenthesizedParameterData {
354 pub inputs: Vec<P<Ty>>,
357 pub output: Option<P<Ty>>,
360 pub type CrateNum = u32;
362 pub type NodeId = u32;
364 #[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
365 RustcDecodable, Hash, Show, Copy)]
371 /// Item definitions in the currently-compiled crate would have the CrateNum
372 /// LOCAL_CRATE in their DefId.
373 pub const LOCAL_CRATE: CrateNum = 0;
374 pub const CRATE_NODE_ID: NodeId = 0;
376 /// When parsing and doing expansions, we initially give all AST nodes this AST
377 /// node value. Then later, in the renumber pass, we renumber them to have
378 /// small, positive ids.
379 pub const DUMMY_NODE_ID: NodeId = -1;
381 /// The AST represents all type param bounds as types.
382 /// typeck::collect::compute_bounds matches these against
383 /// the "special" built-in traits (see middle::lang_items) and
384 /// detects Copy, Send and Sync.
385 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
386 pub enum TyParamBound {
387 TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
388 RegionTyParamBound(Lifetime)
391 /// A modifier on a bound, currently this is only used for `?Sized`, where the
392 /// modifier is `Maybe`. Negative bounds should also be handled here.
393 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
394 pub enum TraitBoundModifier {
399 pub type TyParamBounds = OwnedSlice<TyParamBound>;
401 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
405 pub bounds: TyParamBounds,
406 pub default: Option<P<Ty>>,
410 /// Represents lifetimes and type parameters attached to a declaration
411 /// of a function, enum, trait, etc.
412 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
413 pub struct Generics {
414 pub lifetimes: Vec<LifetimeDef>,
415 pub ty_params: OwnedSlice<TyParam>,
416 pub where_clause: WhereClause,
420 pub fn is_parameterized(&self) -> bool {
421 self.lifetimes.len() + self.ty_params.len() > 0
423 pub fn is_lt_parameterized(&self) -> bool {
424 self.lifetimes.len() > 0
426 pub fn is_type_parameterized(&self) -> bool {
427 self.ty_params.len() > 0
431 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
432 pub struct WhereClause {
434 pub predicates: Vec<WherePredicate>,
437 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
438 pub enum WherePredicate {
439 BoundPredicate(WhereBoundPredicate),
440 RegionPredicate(WhereRegionPredicate),
441 EqPredicate(WhereEqPredicate)
444 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
445 pub struct WhereBoundPredicate {
447 pub bounded_ty: P<Ty>,
448 pub bounds: OwnedSlice<TyParamBound>,
451 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
452 pub struct WhereRegionPredicate {
454 pub lifetime: Lifetime,
455 pub bounds: Vec<Lifetime>,
458 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
459 pub struct WhereEqPredicate {
466 /// The set of MetaItems that define the compilation environment of the crate,
467 /// used to drive conditional compilation
468 pub type CrateConfig = Vec<P<MetaItem>> ;
470 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
473 pub attrs: Vec<Attribute>,
474 pub config: CrateConfig,
476 pub exported_macros: Vec<MacroDef>,
479 pub type MetaItem = Spanned<MetaItem_>;
481 #[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
483 MetaWord(InternedString),
484 MetaList(InternedString, Vec<P<MetaItem>>),
485 MetaNameValue(InternedString, Lit),
488 // can't be derived because the MetaList requires an unordered comparison
489 impl PartialEq for MetaItem_ {
490 fn eq(&self, other: &MetaItem_) -> bool {
492 MetaWord(ref ns) => match *other {
493 MetaWord(ref no) => (*ns) == (*no),
496 MetaNameValue(ref ns, ref vs) => match *other {
497 MetaNameValue(ref no, ref vo) => {
498 (*ns) == (*no) && vs.node == vo.node
502 MetaList(ref ns, ref miss) => match *other {
503 MetaList(ref no, ref miso) => {
505 miss.iter().all(|mi| miso.iter().any(|x| x.node == mi.node))
513 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
515 pub view_items: Vec<ViewItem>,
516 pub stmts: Vec<P<Stmt>>,
517 pub expr: Option<P<Expr>>,
519 pub rules: BlockCheckMode,
523 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
530 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
531 pub struct FieldPat {
534 pub is_shorthand: bool,
537 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
538 pub enum BindingMode {
539 BindByRef(Mutability),
540 BindByValue(Mutability),
543 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
544 pub enum PatWildKind {
545 /// Represents the wildcard pattern `_`
548 /// Represents the wildcard pattern `..`
552 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
554 /// Represents a wildcard pattern (either `_` or `..`)
555 PatWild(PatWildKind),
557 /// A PatIdent may either be a new bound variable,
558 /// or a nullary enum (in which case the third field
560 /// In the nullary enum case, the parser can't determine
561 /// which it is. The resolver determines this, and
562 /// records this pattern's NodeId in an auxiliary
563 /// set (of "PatIdents that refer to nullary enums")
564 PatIdent(BindingMode, SpannedIdent, Option<P<Pat>>),
566 /// "None" means a * pattern where we don't bind the fields to names.
567 PatEnum(Path, Option<Vec<P<Pat>>>),
569 PatStruct(Path, Vec<Spanned<FieldPat>>, bool),
572 PatRegion(P<Pat>, Mutability), // reference pattern
574 PatRange(P<Expr>, P<Expr>),
575 /// [a, b, ..i, y, z] is represented as:
576 /// PatVec(box [a, b], Some(i), box [y, z])
577 PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
581 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
582 pub enum Mutability {
587 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
609 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
617 pub type Stmt = Spanned<Stmt_>;
619 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
621 /// Could be an item or a local (let) binding:
622 StmtDecl(P<Decl>, NodeId),
624 /// Expr without trailing semi-colon (must have unit type):
625 StmtExpr(P<Expr>, NodeId),
627 /// Expr with trailing semi-colon (may have any type):
628 StmtSemi(P<Expr>, NodeId),
630 StmtMac(P<Mac>, MacStmtStyle),
633 #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
634 pub enum MacStmtStyle {
635 /// The macro statement had a trailing semicolon, e.g. `foo! { ... };`
636 /// `foo!(...);`, `foo![...];`
637 MacStmtWithSemicolon,
638 /// The macro statement had braces; e.g. foo! { ... }
640 /// The macro statement had parentheses or brackets and no semicolon; e.g.
641 /// `foo!(...)`. All of these will end up being converted into macro
643 MacStmtWithoutBraces,
646 /// Where a local declaration came from: either a true `let ... =
647 /// ...;`, or one desugared from the pattern of a for loop.
648 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
649 pub enum LocalSource {
654 // FIXME (pending discussion of #1697, #2178...): local should really be
655 // a refinement on pat.
656 /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
657 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
660 pub ty: Option<P<Ty>>,
661 pub init: Option<P<Expr>>,
664 pub source: LocalSource,
667 pub type Decl = Spanned<Decl_>;
669 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
671 /// A local (let) binding:
677 /// represents one arm of a 'match'
678 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
680 pub attrs: Vec<Attribute>,
681 pub pats: Vec<P<Pat>>,
682 pub guard: Option<P<Expr>>,
686 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
688 pub ident: SpannedIdent,
693 pub type SpannedIdent = Spanned<Ident>;
695 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
696 pub enum BlockCheckMode {
698 UnsafeBlock(UnsafeSource),
701 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
702 pub enum UnsafeSource {
707 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
714 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
716 /// First expr is the place; second expr is the value.
717 ExprBox(Option<P<Expr>>, P<Expr>),
718 ExprVec(Vec<P<Expr>>),
719 ExprCall(P<Expr>, Vec<P<Expr>>),
720 ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
721 ExprTup(Vec<P<Expr>>),
722 ExprBinary(BinOp, P<Expr>, P<Expr>),
723 ExprUnary(UnOp, P<Expr>),
725 ExprCast(P<Expr>, P<Ty>),
726 ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
727 ExprIfLet(P<Pat>, P<Expr>, P<Block>, Option<P<Expr>>),
728 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
729 ExprWhile(P<Expr>, P<Block>, Option<Ident>),
730 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
731 ExprWhileLet(P<Pat>, P<Expr>, P<Block>, Option<Ident>),
732 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
733 ExprForLoop(P<Pat>, P<Expr>, P<Block>, Option<Ident>),
734 // Conditionless loop (can be exited with break, cont, or ret)
735 // FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
736 ExprLoop(P<Block>, Option<Ident>),
737 ExprMatch(P<Expr>, Vec<Arm>, MatchSource),
738 ExprClosure(CaptureClause, Option<UnboxedClosureKind>, P<FnDecl>, P<Block>),
741 ExprAssign(P<Expr>, P<Expr>),
742 ExprAssignOp(BinOp, P<Expr>, P<Expr>),
743 ExprField(P<Expr>, SpannedIdent),
744 ExprTupField(P<Expr>, Spanned<uint>),
745 ExprIndex(P<Expr>, P<Expr>),
746 ExprRange(Option<P<Expr>>, Option<P<Expr>>),
748 /// Variable reference, possibly containing `::` and/or
749 /// type parameters, e.g. foo::bar::<baz>
752 ExprAddrOf(Mutability, P<Expr>),
753 ExprBreak(Option<Ident>),
754 ExprAgain(Option<Ident>),
755 ExprRet(Option<P<Expr>>),
757 ExprInlineAsm(InlineAsm),
761 /// A struct literal expression.
762 ExprStruct(Path, Vec<Field>, Option<P<Expr>> /* base */),
764 /// A vector literal constructed from one repeated element.
765 ExprRepeat(P<Expr> /* element */, P<Expr> /* count */),
767 /// No-op: used solely so we can pretty-print faithfully
771 /// A "qualified path":
773 /// <Vec<T> as SomeTrait>::SomeAssociatedItem
774 /// ^~~~~ ^~~~~~~~~ ^~~~~~~~~~~~~~~~~~
775 /// self_type trait_name item_name
776 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
778 pub self_type: P<Ty>,
779 pub trait_ref: P<TraitRef>,
780 pub item_name: Ident, // FIXME(#20301) -- should use Name
783 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
784 pub enum MatchSource {
786 IfLetDesugar { contains_else_clause: bool },
790 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
791 pub enum CaptureClause {
796 /// A delimited sequence of token trees
797 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
798 pub struct Delimited {
799 /// The type of delimiter
800 pub delim: token::DelimToken,
801 /// The span covering the opening delimiter
803 /// The delimited sequence of token trees
804 pub tts: Vec<TokenTree>,
805 /// The span covering the closing delimiter
806 pub close_span: Span,
810 /// Returns the opening delimiter as a token.
811 pub fn open_token(&self) -> token::Token {
812 token::OpenDelim(self.delim)
815 /// Returns the closing delimiter as a token.
816 pub fn close_token(&self) -> token::Token {
817 token::CloseDelim(self.delim)
820 /// Returns the opening delimiter as a token tree.
821 pub fn open_tt(&self) -> TokenTree {
822 TtToken(self.open_span, self.open_token())
825 /// Returns the closing delimiter as a token tree.
826 pub fn close_tt(&self) -> TokenTree {
827 TtToken(self.close_span, self.close_token())
831 /// A sequence of token treesee
832 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
833 pub struct SequenceRepetition {
834 /// The sequence of token trees
835 pub tts: Vec<TokenTree>,
836 /// The optional separator
837 pub separator: Option<token::Token>,
838 /// Whether the sequence can be repeated zero (*), or one or more times (+)
840 /// The number of `MatchNt`s that appear in the sequence (and subsequences)
841 pub num_captures: uint,
844 /// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
845 /// for token sequences.
846 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
852 /// When the main rust parser encounters a syntax-extension invocation, it
853 /// parses the arguments to the invocation as a token-tree. This is a very
854 /// loose structure, such that all sorts of different AST-fragments can
855 /// be passed to syntax extensions using a uniform type.
857 /// If the syntax extension is an MBE macro, it will attempt to match its
858 /// LHS token tree against the provided token tree, and if it finds a
859 /// match, will transcribe the RHS token tree, splicing in any captured
860 /// macro_parser::matched_nonterminals into the `SubstNt`s it finds.
862 /// The RHS of an MBE macro is the only place `SubstNt`s are substituted.
863 /// Nothing special happens to misnamed or misplaced `SubstNt`s.
864 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
865 #[doc="For macro invocations; parsing is delegated to the macro"]
868 TtToken(Span, token::Token),
869 /// A delimited sequence of token trees
870 TtDelimited(Span, Rc<Delimited>),
872 // This only makes sense in MBE macros.
874 /// A kleene-style repetition sequence with a span
875 // FIXME(eddyb) #12938 Use DST.
876 TtSequence(Span, Rc<SequenceRepetition>),
880 pub fn len(&self) -> uint {
882 TtToken(_, token::DocComment(_)) => 2,
883 TtToken(_, token::SpecialVarNt(..)) => 2,
884 TtToken(_, token::MatchNt(..)) => 3,
885 TtDelimited(_, ref delimed) => {
886 delimed.tts.len() + 2
888 TtSequence(_, ref seq) => {
895 pub fn get_tt(&self, index: uint) -> TokenTree {
896 match (self, index) {
897 (&TtToken(sp, token::DocComment(_)), 0) => {
898 TtToken(sp, token::Pound)
900 (&TtToken(sp, token::DocComment(name)), 1) => {
901 TtDelimited(sp, Rc::new(Delimited {
902 delim: token::Bracket,
904 tts: vec![TtToken(sp, token::Ident(token::str_to_ident("doc"),
906 TtToken(sp, token::Eq),
907 TtToken(sp, token::Literal(token::Str_(name), None))],
911 (&TtDelimited(_, ref delimed), _) => {
913 return delimed.open_tt();
915 if index == delimed.tts.len() + 1 {
916 return delimed.close_tt();
918 delimed.tts[index - 1].clone()
920 (&TtToken(sp, token::SpecialVarNt(var)), _) => {
921 let v = [TtToken(sp, token::Dollar),
922 TtToken(sp, token::Ident(token::str_to_ident(var.as_str()),
926 (&TtToken(sp, token::MatchNt(name, kind, name_st, kind_st)), _) => {
927 let v = [TtToken(sp, token::SubstNt(name, name_st)),
928 TtToken(sp, token::Colon),
929 TtToken(sp, token::Ident(kind, kind_st))];
932 (&TtSequence(_, ref seq), _) => {
933 seq.tts[index].clone()
935 _ => panic!("Cannot expand a token tree")
939 /// Returns the `Span` corresponding to this token tree.
940 pub fn get_span(&self) -> Span {
942 TtToken(span, _) => span,
943 TtDelimited(span, _) => span,
944 TtSequence(span, _) => span,
949 pub type Mac = Spanned<Mac_>;
951 /// Represents a macro invocation. The Path indicates which macro
952 /// is being invoked, and the vector of token-trees contains the source
953 /// of the macro invocation.
954 /// There's only one flavor, now, so this could presumably be simplified.
955 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
957 // NB: the additional ident for a macro_rules-style macro is actually
958 // stored in the enclosing item. Oog.
959 MacInvocTT(Path, Vec<TokenTree> , SyntaxContext), // new macro-invocation
962 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
968 pub type Lit = Spanned<Lit_>;
970 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
977 pub fn new<T:Int>(n: T) -> Sign {
986 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
987 pub enum LitIntType {
988 SignedIntLit(IntTy, Sign),
989 UnsignedIntLit(UintTy),
990 UnsuffixedIntLit(Sign)
994 pub fn suffix_len(&self) -> uint {
996 UnsuffixedIntLit(_) => 0,
997 SignedIntLit(s, _) => s.suffix_len(),
998 UnsignedIntLit(u) => u.suffix_len()
1003 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1005 LitStr(InternedString, StrStyle),
1006 LitBinary(Rc<Vec<u8>>),
1009 LitInt(u64, LitIntType),
1010 LitFloat(InternedString, FloatTy),
1011 LitFloatUnsuffixed(InternedString),
1015 // NB: If you change this, you'll probably want to change the corresponding
1016 // type structure in middle/ty.rs as well.
1017 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1020 pub mutbl: Mutability,
1023 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1024 pub struct TypeField {
1030 /// Represents a required method in a trait declaration,
1031 /// one without a default implementation
1032 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1033 pub struct TypeMethod {
1035 pub attrs: Vec<Attribute>,
1036 pub unsafety: Unsafety,
1038 pub decl: P<FnDecl>,
1039 pub generics: Generics,
1040 pub explicit_self: ExplicitSelf,
1043 pub vis: Visibility,
1046 /// Represents a method declaration in a trait declaration, possibly including
1047 /// a default implementation A trait method is either required (meaning it
1048 /// doesn't have an implementation, just a signature) or provided (meaning it
1049 /// has a default implementation).
1050 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1051 pub enum TraitItem {
1052 RequiredMethod(TypeMethod),
1053 ProvidedMethod(P<Method>),
1054 TypeTraitItem(P<AssociatedType>),
1057 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1059 MethodImplItem(P<Method>),
1060 TypeImplItem(P<Typedef>),
1063 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1064 pub struct AssociatedType {
1065 pub attrs: Vec<Attribute>,
1066 pub ty_param: TyParam,
1069 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1070 pub struct Typedef {
1074 pub vis: Visibility,
1075 pub attrs: Vec<Attribute>,
1079 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1088 //NOTE(stage0): remove after snapshot
1089 impl fmt::Show for IntTy {
1090 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1091 fmt::String::fmt(self, f)
1095 impl fmt::String for IntTy {
1096 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1097 write!(f, "{}", ast_util::int_ty_to_string(*self, None))
1102 pub fn suffix_len(&self) -> uint {
1106 TyI16 | TyI32 | TyI64 => 3,
1111 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1121 pub fn suffix_len(&self) -> uint {
1125 TyU16 | TyU32 | TyU64 => 3,
1130 //NOTE(stage0): remove after snapshot
1131 impl fmt::Show for UintTy {
1132 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1133 fmt::String::fmt(self, f)
1137 impl fmt::String for UintTy {
1138 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1139 write!(f, "{}", ast_util::uint_ty_to_string(*self, None))
1143 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1149 //NOTE(stage0): remove after snapshot
1150 impl fmt::Show for FloatTy {
1151 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1152 fmt::String::fmt(self, f)
1156 impl fmt::String for FloatTy {
1157 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1158 write!(f, "{}", ast_util::float_ty_to_string(*self))
1163 pub fn suffix_len(&self) -> uint {
1165 TyF32 | TyF64 => 3, // add F128 handling here
1170 // Bind a type to an associated type: `A=Foo`.
1171 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1172 pub struct TypeBinding {
1180 // NB PartialEq method appears below.
1181 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1188 /// Not represented directly in the AST, referred to by name through a ty_path.
1189 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1199 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1205 impl fmt::Show for Onceness {
1206 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1207 fmt::String::fmt(match *self {
1214 impl fmt::String for Onceness {
1215 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1216 fmt::String::fmt(match *self {
1223 /// Represents the type of a closure
1224 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1225 pub struct ClosureTy {
1226 pub lifetimes: Vec<LifetimeDef>,
1227 pub unsafety: Unsafety,
1228 pub onceness: Onceness,
1229 pub decl: P<FnDecl>,
1230 pub bounds: TyParamBounds,
1233 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1234 pub struct BareFnTy {
1235 pub unsafety: Unsafety,
1237 pub lifetimes: Vec<LifetimeDef>,
1241 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1242 /// The different kinds of types recognized by the compiler
1245 /// A fixed length array (`[T, ..n]`)
1246 TyFixedLengthVec(P<Ty>, P<Expr>),
1247 /// A raw pointer (`*const T` or `*mut T`)
1249 /// A reference (`&'a T` or `&'a mut T`)
1250 TyRptr(Option<Lifetime>, MutTy),
1251 /// A bare function (e.g. `fn(uint) -> bool`)
1252 TyBareFn(P<BareFnTy>),
1253 /// A tuple (`(A, B, C, D,...)`)
1255 /// A path (`module::module::...::Type`) or primitive
1257 /// Type parameters are stored in the Path itself
1258 TyPath(Path, NodeId),
1259 /// Something like `A+B`. Note that `B` must always be a path.
1260 TyObjectSum(P<Ty>, TyParamBounds),
1261 /// A type like `for<'a> Foo<&'a Bar>`
1262 TyPolyTraitRef(TyParamBounds),
1263 /// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
1265 /// No-op; kept solely so that we can pretty-print faithfully
1269 /// TyInfer means the type should be inferred instead of it having been
1270 /// specified. This can appear anywhere in a type.
1274 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1275 pub enum AsmDialect {
1280 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1281 pub struct InlineAsm {
1282 pub asm: InternedString,
1283 pub asm_str_style: StrStyle,
1284 pub outputs: Vec<(InternedString, P<Expr>, bool)>,
1285 pub inputs: Vec<(InternedString, P<Expr>)>,
1286 pub clobbers: Vec<InternedString>,
1288 pub alignstack: bool,
1289 pub dialect: AsmDialect,
1290 pub expn_id: ExpnId,
1293 /// represents an argument in a function header
1294 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1302 pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg {
1303 let path = Spanned{span:span,node:self_ident};
1305 // HACK(eddyb) fake type for the self argument.
1313 node: PatIdent(BindByValue(mutability), path, None),
1321 /// represents the header (not the body) of a function declaration
1322 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1324 pub inputs: Vec<Arg>,
1325 pub output: FunctionRetTy,
1329 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1335 impl fmt::String for Unsafety {
1336 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1337 fmt::String::fmt(match *self {
1338 Unsafety::Normal => "normal",
1339 Unsafety::Unsafe => "unsafe",
1344 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1345 pub enum ImplPolarity {
1346 /// impl Trait for Type
1348 /// impl !Trait for Type
1352 impl fmt::Show for ImplPolarity {
1353 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1355 ImplPolarity::Positive => "positive".fmt(f),
1356 ImplPolarity::Negative => "negative".fmt(f),
1362 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1363 pub enum FunctionRetTy {
1364 /// Functions with return type ! that always
1365 /// raise an error or exit (i.e. never return to the caller)
1371 impl FunctionRetTy {
1372 pub fn span(&self) -> Span {
1374 NoReturn(span) => span,
1375 Return(ref ty) => ty.span
1380 /// Represents the kind of 'self' associated with a method
1381 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1382 pub enum ExplicitSelf_ {
1387 /// `&'lt self`, `&'lt mut self`
1388 SelfRegion(Option<Lifetime>, Mutability, Ident),
1390 SelfExplicit(P<Ty>, Ident),
1393 pub type ExplicitSelf = Spanned<ExplicitSelf_>;
1395 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1397 pub attrs: Vec<Attribute>,
1403 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1405 /// Represents a method declaration
1414 /// Represents a macro in method position
1418 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1420 /// A span from the first token past `{` to the last token until `}`.
1421 /// For `mod foo;`, the inner span ranges from the first token
1422 /// to the last token in the external file.
1424 pub view_items: Vec<ViewItem>,
1425 pub items: Vec<P<Item>>,
1428 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1429 pub struct ForeignMod {
1431 pub view_items: Vec<ViewItem>,
1432 pub items: Vec<P<ForeignItem>>,
1435 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1436 pub struct VariantArg {
1441 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1442 pub enum VariantKind {
1443 TupleVariantKind(Vec<VariantArg>),
1444 StructVariantKind(P<StructDef>),
1447 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1448 pub struct EnumDef {
1449 pub variants: Vec<P<Variant>>,
1452 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1453 pub struct Variant_ {
1455 pub attrs: Vec<Attribute>,
1456 pub kind: VariantKind,
1458 pub disr_expr: Option<P<Expr>>,
1459 pub vis: Visibility,
1462 pub type Variant = Spanned<Variant_>;
1464 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1465 pub enum PathListItem_ {
1466 PathListIdent { name: Ident, id: NodeId },
1467 PathListMod { id: NodeId }
1470 impl PathListItem_ {
1471 pub fn id(&self) -> NodeId {
1473 PathListIdent { id, .. } | PathListMod { id } => id
1478 pub type PathListItem = Spanned<PathListItem_>;
1480 pub type ViewPath = Spanned<ViewPath_>;
1482 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1483 pub enum ViewPath_ {
1485 /// `foo::bar::baz as quux`
1489 /// `foo::bar::baz` (with `as baz` implicitly on the right)
1490 ViewPathSimple(Ident, Path, NodeId),
1493 ViewPathGlob(Path, NodeId),
1495 /// `foo::bar::{a,b,c}`
1496 ViewPathList(Path, Vec<PathListItem> , NodeId)
1499 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1500 pub struct ViewItem {
1501 pub node: ViewItem_,
1502 pub attrs: Vec<Attribute>,
1503 pub vis: Visibility,
1507 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1508 pub enum ViewItem_ {
1509 /// Ident: name used to refer to this crate in the code
1510 /// optional (InternedString,StrStyle): if present, this is a location
1511 /// (containing arbitrary characters) from which to fetch the crate sources
1512 /// For example, extern crate whatever = "github.com/rust-lang/rust"
1513 ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
1514 ViewItemUse(P<ViewPath>),
1517 /// Meta-data associated with an item
1518 pub type Attribute = Spanned<Attribute_>;
1520 /// Distinguishes between Attributes that decorate items and Attributes that
1521 /// are contained as statements within items. These two cases need to be
1522 /// distinguished for pretty-printing.
1523 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1524 pub enum AttrStyle {
1529 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1530 pub struct AttrId(pub uint);
1532 /// Doc-comments are promoted to attributes that have is_sugared_doc = true
1533 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1534 pub struct Attribute_ {
1536 pub style: AttrStyle,
1537 pub value: P<MetaItem>,
1538 pub is_sugared_doc: bool,
1541 /// TraitRef's appear in impls.
1542 /// resolve maps each TraitRef's ref_id to its defining trait; that's all
1543 /// that the ref_id is for. The impl_id maps to the "self type" of this impl.
1544 /// If this impl is an ItemImpl, the impl_id is redundant (it could be the
1545 /// same as the impl's node id).
1546 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1547 pub struct TraitRef {
1552 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1553 pub struct PolyTraitRef {
1554 /// The `'a` in `<'a> Foo<&'a T>`
1555 pub bound_lifetimes: Vec<LifetimeDef>,
1557 /// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
1558 pub trait_ref: TraitRef,
1561 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1562 pub enum Visibility {
1568 pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
1570 &Inherited => parent_visibility,
1576 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1577 pub struct StructField_ {
1578 pub kind: StructFieldKind,
1581 pub attrs: Vec<Attribute>,
1585 pub fn ident(&self) -> Option<Ident> {
1587 NamedField(ref ident, _) => Some(ident.clone()),
1588 UnnamedField(_) => None
1593 pub type StructField = Spanned<StructField_>;
1595 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1596 pub enum StructFieldKind {
1597 NamedField(Ident, Visibility),
1598 /// Element of a tuple-like struct
1599 UnnamedField(Visibility),
1602 impl StructFieldKind {
1603 pub fn is_unnamed(&self) -> bool {
1605 UnnamedField(..) => true,
1606 NamedField(..) => false,
1611 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1612 pub struct StructDef {
1613 /// Fields, not including ctor
1614 pub fields: Vec<StructField>,
1615 /// ID of the constructor. This is only used for tuple- or enum-like
1617 pub ctor_id: Option<NodeId>,
1621 FIXME (#3300): Should allow items to be anonymous. Right now
1622 we just use dummy names for anon items.
1624 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1627 pub attrs: Vec<Attribute>,
1630 pub vis: Visibility,
1634 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1636 ItemStatic(P<Ty>, Mutability, P<Expr>),
1637 ItemConst(P<Ty>, P<Expr>),
1638 ItemFn(P<FnDecl>, Unsafety, Abi, Generics, P<Block>),
1640 ItemForeignMod(ForeignMod),
1641 ItemTy(P<Ty>, Generics),
1642 ItemEnum(EnumDef, Generics),
1643 ItemStruct(P<StructDef>, Generics),
1644 /// Represents a Trait Declaration
1652 Option<TraitRef>, // (optional) trait this impl implements
1655 /// A macro invocation (which includes macro definition)
1660 pub fn descriptive_variant(&self) -> &str {
1662 ItemStatic(..) => "static item",
1663 ItemConst(..) => "constant item",
1664 ItemFn(..) => "function",
1665 ItemMod(..) => "module",
1666 ItemForeignMod(..) => "foreign module",
1667 ItemTy(..) => "type alias",
1668 ItemEnum(..) => "enum",
1669 ItemStruct(..) => "struct",
1670 ItemTrait(..) => "trait",
1672 ItemImpl(..) => "item"
1677 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1678 pub struct ForeignItem {
1680 pub attrs: Vec<Attribute>,
1681 pub node: ForeignItem_,
1684 pub vis: Visibility,
1687 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1688 pub enum ForeignItem_ {
1689 ForeignItemFn(P<FnDecl>, Generics),
1690 ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
1694 pub fn descriptive_variant(&self) -> &str {
1696 ForeignItemFn(..) => "foreign function",
1697 ForeignItemStatic(..) => "foreign static item"
1702 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1703 pub enum UnboxedClosureKind {
1704 FnUnboxedClosureKind,
1705 FnMutUnboxedClosureKind,
1706 FnOnceUnboxedClosureKind,
1709 /// The data we save and restore about an inlined item or method. This is not
1710 /// part of the AST that we parse from a file, but it becomes part of the tree
1712 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1713 pub enum InlinedItem {
1715 IITraitItem(DefId /* impl id */, TraitItem),
1716 IIImplItem(DefId /* impl id */, ImplItem),
1717 IIForeign(P<ForeignItem>),
1720 /// A macro definition, in this crate or imported from another.
1722 /// Not parsed directly, but created on macro import or `macro_rules!` expansion.
1723 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1724 pub struct MacroDef {
1726 pub attrs: Vec<Attribute>,
1729 pub imported_from: Option<Ident>,
1731 pub use_locally: bool,
1732 pub body: Vec<TokenTree>,
1737 use serialize::json;
1743 // are ASTs encodable?
1745 fn check_asts_encodable() {
1746 fn assert_encodable<T: serialize::Encodable>() {}
1747 assert_encodable::<Crate>();