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<P<Item>>
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::MatchNt(..)) => 3,
888 TtDelimited(_, ref delimed) => {
889 delimed.tts.len() + 2
891 TtSequence(_, ref seq) => {
898 pub fn get_tt(&self, index: uint) -> TokenTree {
899 match (self, index) {
900 (&TtToken(sp, token::DocComment(_)), 0) => {
901 TtToken(sp, token::Pound)
903 (&TtToken(sp, token::DocComment(name)), 1) => {
904 TtDelimited(sp, Rc::new(Delimited {
905 delim: token::Bracket,
907 tts: vec![TtToken(sp, token::Ident(token::str_to_ident("doc"),
909 TtToken(sp, token::Eq),
910 TtToken(sp, token::Literal(token::Str_(name), None))],
914 (&TtDelimited(_, ref delimed), _) => {
916 return delimed.open_tt();
918 if index == delimed.tts.len() + 1 {
919 return delimed.close_tt();
921 delimed.tts[index - 1].clone()
923 (&TtToken(sp, token::SubstNt(name, name_st)), _) => {
924 let v = [TtToken(sp, token::Dollar),
925 TtToken(sp, token::Ident(name, name_st))];
928 (&TtToken(sp, token::MatchNt(name, kind, name_st, kind_st)), _) => {
929 let v = [TtToken(sp, token::SubstNt(name, name_st)),
930 TtToken(sp, token::Colon),
931 TtToken(sp, token::Ident(kind, kind_st))];
934 (&TtSequence(_, ref seq), _) => {
935 seq.tts[index].clone()
937 _ => panic!("Cannot expand a token tree")
941 /// Returns the `Span` corresponding to this token tree.
942 pub fn get_span(&self) -> Span {
944 TtToken(span, _) => span,
945 TtDelimited(span, _) => span,
946 TtSequence(span, _) => span,
951 pub type Mac = Spanned<Mac_>;
953 /// Represents a macro invocation. The Path indicates which macro
954 /// is being invoked, and the vector of token-trees contains the source
955 /// of the macro invocation.
956 /// There's only one flavor, now, so this could presumably be simplified.
957 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
959 // NB: the additional ident for a macro_rules-style macro is actually
960 // stored in the enclosing item. Oog.
961 MacInvocTT(Path, Vec<TokenTree> , SyntaxContext), // new macro-invocation
964 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
970 pub type Lit = Spanned<Lit_>;
972 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
978 impl<T> Sign where T: Int {
979 pub fn new(n: T) -> Sign {
988 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
989 pub enum LitIntType {
990 SignedIntLit(IntTy, Sign),
991 UnsignedIntLit(UintTy),
992 UnsuffixedIntLit(Sign)
996 pub fn suffix_len(&self) -> uint {
998 UnsuffixedIntLit(_) => 0,
999 SignedIntLit(s, _) => s.suffix_len(),
1000 UnsignedIntLit(u) => u.suffix_len()
1005 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1007 LitStr(InternedString, StrStyle),
1008 LitBinary(Rc<Vec<u8>>),
1011 LitInt(u64, LitIntType),
1012 LitFloat(InternedString, FloatTy),
1013 LitFloatUnsuffixed(InternedString),
1017 // NB: If you change this, you'll probably want to change the corresponding
1018 // type structure in middle/ty.rs as well.
1019 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1022 pub mutbl: Mutability,
1025 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1026 pub struct TypeField {
1032 /// Represents a required method in a trait declaration,
1033 /// one without a default implementation
1034 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1035 pub struct TypeMethod {
1037 pub attrs: Vec<Attribute>,
1038 pub unsafety: Unsafety,
1040 pub decl: P<FnDecl>,
1041 pub generics: Generics,
1042 pub explicit_self: ExplicitSelf,
1045 pub vis: Visibility,
1048 /// Represents a method declaration in a trait declaration, possibly including
1049 /// a default implementation A trait method is either required (meaning it
1050 /// doesn't have an implementation, just a signature) or provided (meaning it
1051 /// has a default implementation).
1052 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1053 pub enum TraitItem {
1054 RequiredMethod(TypeMethod),
1055 ProvidedMethod(P<Method>),
1056 TypeTraitItem(P<AssociatedType>),
1059 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1061 MethodImplItem(P<Method>),
1062 TypeImplItem(P<Typedef>),
1065 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1066 pub struct AssociatedType {
1067 pub attrs: Vec<Attribute>,
1068 pub ty_param: TyParam,
1071 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1072 pub struct Typedef {
1076 pub vis: Visibility,
1077 pub attrs: Vec<Attribute>,
1081 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1090 impl fmt::Show for IntTy {
1091 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1092 write!(f, "{}", ast_util::int_ty_to_string(*self, None))
1097 pub fn suffix_len(&self) -> uint {
1101 TyI16 | TyI32 | TyI64 => 3,
1106 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1116 pub fn suffix_len(&self) -> uint {
1120 TyU16 | TyU32 | TyU64 => 3,
1125 impl fmt::Show for UintTy {
1126 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1127 write!(f, "{}", ast_util::uint_ty_to_string(*self, None))
1131 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1137 impl fmt::Show for FloatTy {
1138 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1139 write!(f, "{}", ast_util::float_ty_to_string(*self))
1144 pub fn suffix_len(&self) -> uint {
1146 TyF32 | TyF64 => 3, // add F128 handling here
1151 // Bind a type to an associated type: `A=Foo`.
1152 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1153 pub struct TypeBinding {
1161 // NB PartialEq method appears below.
1162 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1169 /// Not represented directly in the AST, referred to by name through a ty_path.
1170 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1180 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
1186 impl fmt::Show for Onceness {
1187 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1189 Once => "once".fmt(f),
1190 Many => "many".fmt(f),
1195 /// Represents the type of a closure
1196 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1197 pub struct ClosureTy {
1198 pub lifetimes: Vec<LifetimeDef>,
1199 pub unsafety: Unsafety,
1200 pub onceness: Onceness,
1201 pub decl: P<FnDecl>,
1202 pub bounds: TyParamBounds,
1205 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1206 pub struct BareFnTy {
1207 pub unsafety: Unsafety,
1209 pub lifetimes: Vec<LifetimeDef>,
1213 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1214 /// The different kinds of types recognized by the compiler
1217 /// A fixed length array (`[T, ..n]`)
1218 TyFixedLengthVec(P<Ty>, P<Expr>),
1219 /// A raw pointer (`*const T` or `*mut T`)
1221 /// A reference (`&'a T` or `&'a mut T`)
1222 TyRptr(Option<Lifetime>, MutTy),
1223 /// A bare function (e.g. `fn(uint) -> bool`)
1224 TyBareFn(P<BareFnTy>),
1225 /// A tuple (`(A, B, C, D,...)`)
1227 /// A path (`module::module::...::Type`) or primitive
1229 /// Type parameters are stored in the Path itself
1230 TyPath(Path, NodeId),
1231 /// Something like `A+B`. Note that `B` must always be a path.
1232 TyObjectSum(P<Ty>, TyParamBounds),
1233 /// A type like `for<'a> Foo<&'a Bar>`
1234 TyPolyTraitRef(TyParamBounds),
1235 /// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
1237 /// No-op; kept solely so that we can pretty-print faithfully
1241 /// TyInfer means the type should be inferred instead of it having been
1242 /// specified. This can appear anywhere in a type.
1246 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1247 pub enum AsmDialect {
1252 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1253 pub struct InlineAsm {
1254 pub asm: InternedString,
1255 pub asm_str_style: StrStyle,
1256 pub outputs: Vec<(InternedString, P<Expr>, bool)>,
1257 pub inputs: Vec<(InternedString, P<Expr>)>,
1258 pub clobbers: Vec<InternedString>,
1260 pub alignstack: bool,
1261 pub dialect: AsmDialect,
1262 pub expn_id: ExpnId,
1265 /// represents an argument in a function header
1266 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1274 pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg {
1275 let path = Spanned{span:span,node:self_ident};
1277 // HACK(eddyb) fake type for the self argument.
1285 node: PatIdent(BindByValue(mutability), path, None),
1293 /// represents the header (not the body) of a function declaration
1294 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1296 pub inputs: Vec<Arg>,
1297 pub output: FunctionRetTy,
1301 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1307 impl fmt::Show for Unsafety {
1308 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1310 Unsafety::Normal => "normal".fmt(f),
1311 Unsafety::Unsafe => "unsafe".fmt(f),
1316 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1317 pub enum ImplPolarity {
1318 /// impl Trait for Type
1320 /// impl !Trait for Type
1324 impl fmt::Show for ImplPolarity {
1325 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1327 ImplPolarity::Positive => "positive".fmt(f),
1328 ImplPolarity::Negative => "negative".fmt(f),
1334 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1335 pub enum FunctionRetTy {
1336 /// Functions with return type ! that always
1337 /// raise an error or exit (i.e. never return to the caller)
1343 impl FunctionRetTy {
1344 pub fn span(&self) -> Span {
1346 NoReturn(span) => span,
1347 Return(ref ty) => ty.span
1352 /// Represents the kind of 'self' associated with a method
1353 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1354 pub enum ExplicitSelf_ {
1359 /// `&'lt self`, `&'lt mut self`
1360 SelfRegion(Option<Lifetime>, Mutability, Ident),
1362 SelfExplicit(P<Ty>, Ident),
1365 pub type ExplicitSelf = Spanned<ExplicitSelf_>;
1367 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1369 pub attrs: Vec<Attribute>,
1375 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1377 /// Represents a method declaration
1386 /// Represents a macro in method position
1390 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1392 /// A span from the first token past `{` to the last token until `}`.
1393 /// For `mod foo;`, the inner span ranges from the first token
1394 /// to the last token in the external file.
1396 pub view_items: Vec<ViewItem>,
1397 pub items: Vec<P<Item>>,
1400 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1401 pub struct ForeignMod {
1403 pub view_items: Vec<ViewItem>,
1404 pub items: Vec<P<ForeignItem>>,
1407 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1408 pub struct VariantArg {
1413 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1414 pub enum VariantKind {
1415 TupleVariantKind(Vec<VariantArg>),
1416 StructVariantKind(P<StructDef>),
1419 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1420 pub struct EnumDef {
1421 pub variants: Vec<P<Variant>>,
1424 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1425 pub struct Variant_ {
1427 pub attrs: Vec<Attribute>,
1428 pub kind: VariantKind,
1430 pub disr_expr: Option<P<Expr>>,
1431 pub vis: Visibility,
1434 pub type Variant = Spanned<Variant_>;
1436 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1437 pub enum PathListItem_ {
1438 PathListIdent { name: Ident, id: NodeId },
1439 PathListMod { id: NodeId }
1442 impl PathListItem_ {
1443 pub fn id(&self) -> NodeId {
1445 PathListIdent { id, .. } | PathListMod { id } => id
1450 pub type PathListItem = Spanned<PathListItem_>;
1452 pub type ViewPath = Spanned<ViewPath_>;
1454 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1455 pub enum ViewPath_ {
1457 /// `foo::bar::baz as quux`
1461 /// `foo::bar::baz` (with `as baz` implicitly on the right)
1462 ViewPathSimple(Ident, Path, NodeId),
1465 ViewPathGlob(Path, NodeId),
1467 /// `foo::bar::{a,b,c}`
1468 ViewPathList(Path, Vec<PathListItem> , NodeId)
1471 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1472 pub struct ViewItem {
1473 pub node: ViewItem_,
1474 pub attrs: Vec<Attribute>,
1475 pub vis: Visibility,
1479 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1480 pub enum ViewItem_ {
1481 /// Ident: name used to refer to this crate in the code
1482 /// optional (InternedString,StrStyle): if present, this is a location
1483 /// (containing arbitrary characters) from which to fetch the crate sources
1484 /// For example, extern crate whatever = "github.com/rust-lang/rust"
1485 ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
1486 ViewItemUse(P<ViewPath>),
1489 /// Meta-data associated with an item
1490 pub type Attribute = Spanned<Attribute_>;
1492 /// Distinguishes between Attributes that decorate items and Attributes that
1493 /// are contained as statements within items. These two cases need to be
1494 /// distinguished for pretty-printing.
1495 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1496 pub enum AttrStyle {
1501 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1502 pub struct AttrId(pub uint);
1504 /// Doc-comments are promoted to attributes that have is_sugared_doc = true
1505 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1506 pub struct Attribute_ {
1508 pub style: AttrStyle,
1509 pub value: P<MetaItem>,
1510 pub is_sugared_doc: bool,
1513 /// TraitRef's appear in impls.
1514 /// resolve maps each TraitRef's ref_id to its defining trait; that's all
1515 /// that the ref_id is for. The impl_id maps to the "self type" of this impl.
1516 /// If this impl is an ItemImpl, the impl_id is redundant (it could be the
1517 /// same as the impl's node id).
1518 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1519 pub struct TraitRef {
1524 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1525 pub struct PolyTraitRef {
1526 /// The `'a` in `<'a> Foo<&'a T>`
1527 pub bound_lifetimes: Vec<LifetimeDef>,
1529 /// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
1530 pub trait_ref: TraitRef,
1533 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1534 pub enum Visibility {
1540 pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
1542 &Inherited => parent_visibility,
1548 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1549 pub struct StructField_ {
1550 pub kind: StructFieldKind,
1553 pub attrs: Vec<Attribute>,
1557 pub fn ident(&self) -> Option<Ident> {
1559 NamedField(ref ident, _) => Some(ident.clone()),
1560 UnnamedField(_) => None
1565 pub type StructField = Spanned<StructField_>;
1567 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1568 pub enum StructFieldKind {
1569 NamedField(Ident, Visibility),
1570 /// Element of a tuple-like struct
1571 UnnamedField(Visibility),
1574 impl StructFieldKind {
1575 pub fn is_unnamed(&self) -> bool {
1577 UnnamedField(..) => true,
1578 NamedField(..) => false,
1583 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1584 pub struct StructDef {
1585 /// Fields, not including ctor
1586 pub fields: Vec<StructField>,
1587 /// ID of the constructor. This is only used for tuple- or enum-like
1589 pub ctor_id: Option<NodeId>,
1593 FIXME (#3300): Should allow items to be anonymous. Right now
1594 we just use dummy names for anon items.
1596 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1599 pub attrs: Vec<Attribute>,
1602 pub vis: Visibility,
1606 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1608 ItemStatic(P<Ty>, Mutability, P<Expr>),
1609 ItemConst(P<Ty>, P<Expr>),
1610 ItemFn(P<FnDecl>, Unsafety, Abi, Generics, P<Block>),
1612 ItemForeignMod(ForeignMod),
1613 ItemTy(P<Ty>, Generics),
1614 ItemEnum(EnumDef, Generics),
1615 ItemStruct(P<StructDef>, Generics),
1616 /// Represents a Trait Declaration
1624 Option<TraitRef>, // (optional) trait this impl implements
1627 /// A macro invocation (which includes macro definition)
1632 pub fn descriptive_variant(&self) -> &str {
1634 ItemStatic(..) => "static item",
1635 ItemConst(..) => "constant item",
1636 ItemFn(..) => "function",
1637 ItemMod(..) => "module",
1638 ItemForeignMod(..) => "foreign module",
1639 ItemTy(..) => "type alias",
1640 ItemEnum(..) => "enum",
1641 ItemStruct(..) => "struct",
1642 ItemTrait(..) => "trait",
1644 ItemImpl(..) => "item"
1649 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1650 pub struct ForeignItem {
1652 pub attrs: Vec<Attribute>,
1653 pub node: ForeignItem_,
1656 pub vis: Visibility,
1659 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1660 pub enum ForeignItem_ {
1661 ForeignItemFn(P<FnDecl>, Generics),
1662 ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
1666 pub fn descriptive_variant(&self) -> &str {
1668 ForeignItemFn(..) => "foreign function",
1669 ForeignItemStatic(..) => "foreign static item"
1674 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
1675 pub enum UnboxedClosureKind {
1676 FnUnboxedClosureKind,
1677 FnMutUnboxedClosureKind,
1678 FnOnceUnboxedClosureKind,
1681 /// The data we save and restore about an inlined item or method. This is not
1682 /// part of the AST that we parse from a file, but it becomes part of the tree
1684 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
1685 pub enum InlinedItem {
1687 IITraitItem(DefId /* impl id */, TraitItem),
1688 IIImplItem(DefId /* impl id */, ImplItem),
1689 IIForeign(P<ForeignItem>),
1694 use serialize::json;
1700 // are ASTs encodable?
1702 fn check_asts_encodable() {
1703 fn assert_encodable<T: serialize::Encodable>() {}
1704 assert_encodable::<Crate>();