1 // Copyright 2015 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.
13 pub use self::BindingMode::*;
14 pub use self::BinOp_::*;
15 pub use self::BlockCheckMode::*;
16 pub use self::CaptureClause::*;
17 pub use self::Decl_::*;
18 pub use self::Expr_::*;
19 pub use self::FunctionRetTy::*;
20 pub use self::ForeignItem_::*;
21 pub use self::Item_::*;
22 pub use self::Mutability::*;
23 pub use self::PrimTy::*;
24 pub use self::Stmt_::*;
25 pub use self::TraitItem_::*;
27 pub use self::TyParamBound::*;
28 pub use self::UnOp::*;
29 pub use self::UnsafeSource::*;
30 pub use self::ViewPath_::*;
31 pub use self::Visibility::{Public, Inherited};
32 pub use self::PathParameters::*;
35 use hir::def_id::DefId;
36 use util::nodemap::{NodeMap, FxHashSet};
38 use syntax_pos::{mk_sp, Span, ExpnId, DUMMY_SP};
39 use syntax::codemap::{self, respan, Spanned};
41 use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
42 use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
44 use syntax::symbol::{Symbol, keywords};
45 use syntax::tokenstream::TokenTree;
46 use syntax::util::ThinVec;
48 use std::collections::BTreeMap;
51 /// HIR doesn't commit to a concrete storage type and have its own alias for a vector.
52 /// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar
53 /// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead
54 /// of `Vec` to avoid keeping extra capacity.
55 pub type HirVec<T> = P<[T]>;
57 macro_rules! hir_vec {
58 ($elem:expr; $n:expr) => (
59 $crate::hir::HirVec::from(vec![$elem; $n])
62 $crate::hir::HirVec::from(vec![$($x),*])
64 ($($x:expr,)*) => (hir_vec![$($x),*])
71 pub mod itemlikevisit;
78 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
85 impl fmt::Debug for Lifetime {
86 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90 print::lifetime_to_string(self))
94 /// A lifetime definition, eg `'a: 'b+'c+'d`
95 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
96 pub struct LifetimeDef {
97 pub lifetime: Lifetime,
98 pub bounds: HirVec<Lifetime>,
99 pub pure_wrt_drop: bool,
102 /// A "Path" is essentially Rust's notion of a name; for instance:
103 /// std::cmp::PartialEq . It's represented as a sequence of identifiers,
104 /// along with a bunch of supporting information.
105 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
108 /// A `::foo` path, is relative to the crate root rather than current
109 /// module (like paths in an import).
111 /// The segments in the path: the things separated by `::`.
112 pub segments: HirVec<PathSegment>,
115 impl fmt::Debug for Path {
116 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
117 write!(f, "path({})", print::path_to_string(self))
121 impl fmt::Display for Path {
122 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
123 write!(f, "{}", print::path_to_string(self))
128 /// Convert a span and an identifier to the corresponding
130 pub fn from_name(s: Span, name: Name) -> Path {
134 segments: hir_vec![PathSegment {
136 parameters: PathParameters::none()
142 /// A segment of a path: an identifier, an optional lifetime, and a set of
144 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
145 pub struct PathSegment {
146 /// The identifier portion of this path segment.
149 /// Type/lifetime parameters attached to this path. They come in
150 /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
151 /// this is more than just simple syntactic sugar; the use of
152 /// parens affects the region binding rules, so we preserve the
154 pub parameters: PathParameters,
157 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
158 pub enum PathParameters {
159 /// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>`
160 AngleBracketedParameters(AngleBracketedParameterData),
161 /// The `(A,B)` and `C` in `Foo(A,B) -> C`
162 ParenthesizedParameters(ParenthesizedParameterData),
165 impl PathParameters {
166 pub fn none() -> PathParameters {
167 AngleBracketedParameters(AngleBracketedParameterData {
168 lifetimes: HirVec::new(),
169 types: HirVec::new(),
171 bindings: HirVec::new(),
175 pub fn is_empty(&self) -> bool {
177 AngleBracketedParameters(ref data) => data.is_empty(),
179 // Even if the user supplied no types, something like
180 // `X()` is equivalent to `X<(),()>`.
181 ParenthesizedParameters(..) => false,
185 pub fn has_lifetimes(&self) -> bool {
187 AngleBracketedParameters(ref data) => !data.lifetimes.is_empty(),
188 ParenthesizedParameters(_) => false,
192 pub fn has_types(&self) -> bool {
194 AngleBracketedParameters(ref data) => !data.types.is_empty(),
195 ParenthesizedParameters(..) => true,
199 /// Returns the types that the user wrote. Note that these do not necessarily map to the type
200 /// parameters in the parenthesized case.
201 pub fn types(&self) -> HirVec<&P<Ty>> {
203 AngleBracketedParameters(ref data) => {
204 data.types.iter().collect()
206 ParenthesizedParameters(ref data) => {
209 .chain(data.output.iter())
215 pub fn lifetimes(&self) -> HirVec<&Lifetime> {
217 AngleBracketedParameters(ref data) => {
218 data.lifetimes.iter().collect()
220 ParenthesizedParameters(_) => {
226 pub fn bindings(&self) -> HirVec<&TypeBinding> {
228 AngleBracketedParameters(ref data) => {
229 data.bindings.iter().collect()
231 ParenthesizedParameters(_) => {
238 /// A path like `Foo<'a, T>`
239 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
240 pub struct AngleBracketedParameterData {
241 /// The lifetime parameters for this path segment.
242 pub lifetimes: HirVec<Lifetime>,
243 /// The type parameters for this path segment, if present.
244 pub types: HirVec<P<Ty>>,
245 /// Whether to infer remaining type parameters, if any.
246 /// This only applies to expression and pattern paths, and
247 /// out of those only the segments with no type parameters
248 /// to begin with, e.g. `Vec::new` is `<Vec<..>>::new::<..>`.
249 pub infer_types: bool,
250 /// Bindings (equality constraints) on associated types, if present.
251 /// E.g., `Foo<A=Bar>`.
252 pub bindings: HirVec<TypeBinding>,
255 impl AngleBracketedParameterData {
256 fn is_empty(&self) -> bool {
257 self.lifetimes.is_empty() && self.types.is_empty() && self.bindings.is_empty()
261 /// A path like `Foo(A,B) -> C`
262 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
263 pub struct ParenthesizedParameterData {
268 pub inputs: HirVec<P<Ty>>,
271 pub output: Option<P<Ty>>,
274 /// The AST represents all type param bounds as types.
275 /// typeck::collect::compute_bounds matches these against
276 /// the "special" built-in traits (see middle::lang_items) and
277 /// detects Copy, Send and Sync.
278 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
279 pub enum TyParamBound {
280 TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
281 RegionTyParamBound(Lifetime),
284 /// A modifier on a bound, currently this is only used for `?Sized`, where the
285 /// modifier is `Maybe`. Negative bounds should also be handled here.
286 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
287 pub enum TraitBoundModifier {
292 pub type TyParamBounds = HirVec<TyParamBound>;
294 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
298 pub bounds: TyParamBounds,
299 pub default: Option<P<Ty>>,
301 pub pure_wrt_drop: bool,
304 /// Represents lifetimes and type parameters attached to a declaration
305 /// of a function, enum, trait, etc.
306 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
307 pub struct Generics {
308 pub lifetimes: HirVec<LifetimeDef>,
309 pub ty_params: HirVec<TyParam>,
310 pub where_clause: WhereClause,
315 pub fn empty() -> Generics {
317 lifetimes: HirVec::new(),
318 ty_params: HirVec::new(),
319 where_clause: WhereClause {
321 predicates: HirVec::new(),
327 pub fn is_lt_parameterized(&self) -> bool {
328 !self.lifetimes.is_empty()
331 pub fn is_type_parameterized(&self) -> bool {
332 !self.ty_params.is_empty()
335 pub fn is_parameterized(&self) -> bool {
336 self.is_lt_parameterized() || self.is_type_parameterized()
340 pub enum UnsafeGeneric {
341 Region(LifetimeDef, &'static str),
342 Type(TyParam, &'static str),
346 pub fn attr_name(&self) -> &'static str {
348 UnsafeGeneric::Region(_, s) => s,
349 UnsafeGeneric::Type(_, s) => s,
355 pub fn carries_unsafe_attr(&self) -> Option<UnsafeGeneric> {
356 for r in &self.lifetimes {
358 return Some(UnsafeGeneric::Region(r.clone(), "may_dangle"));
361 for t in &self.ty_params {
363 return Some(UnsafeGeneric::Type(t.clone(), "may_dangle"));
370 /// A `where` clause in a definition
371 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
372 pub struct WhereClause {
374 pub predicates: HirVec<WherePredicate>,
377 /// A single predicate in a `where` clause
378 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
379 pub enum WherePredicate {
380 /// A type binding, eg `for<'c> Foo: Send+Clone+'c`
381 BoundPredicate(WhereBoundPredicate),
382 /// A lifetime predicate, e.g. `'a: 'b+'c`
383 RegionPredicate(WhereRegionPredicate),
384 /// An equality predicate (unsupported)
385 EqPredicate(WhereEqPredicate),
388 /// A type bound, eg `for<'c> Foo: Send+Clone+'c`
389 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
390 pub struct WhereBoundPredicate {
392 /// Any lifetimes from a `for` binding
393 pub bound_lifetimes: HirVec<LifetimeDef>,
394 /// The type being bounded
395 pub bounded_ty: P<Ty>,
396 /// Trait and lifetime bounds (`Clone+Send+'static`)
397 pub bounds: TyParamBounds,
400 /// A lifetime predicate, e.g. `'a: 'b+'c`
401 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
402 pub struct WhereRegionPredicate {
404 pub lifetime: Lifetime,
405 pub bounds: HirVec<Lifetime>,
408 /// An equality predicate (unsupported), e.g. `T=int`
409 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
410 pub struct WhereEqPredicate {
417 pub type CrateConfig = HirVec<P<MetaItem>>;
419 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
422 pub attrs: HirVec<Attribute>,
424 pub exported_macros: HirVec<MacroDef>,
426 // NB: We use a BTreeMap here so that `visit_all_items` iterates
427 // over the ids in increasing order. In principle it should not
428 // matter what order we visit things in, but in *practice* it
429 // does, because it can affect the order in which errors are
430 // detected, which in turn can make compile-fail tests yield
431 // slightly different results.
432 pub items: BTreeMap<NodeId, Item>,
434 pub impl_items: BTreeMap<ImplItemId, ImplItem>,
438 pub fn item(&self, id: NodeId) -> &Item {
442 pub fn impl_item(&self, id: ImplItemId) -> &ImplItem {
443 &self.impl_items[&id]
446 /// Visits all items in the crate in some determinstic (but
447 /// unspecified) order. If you just need to process every item,
448 /// but don't care about nesting, this method is the best choice.
450 /// If you do care about nesting -- usually because your algorithm
451 /// follows lexical scoping rules -- then you want a different
452 /// approach. You should override `visit_nested_item` in your
453 /// visitor and then call `intravisit::walk_crate` instead.
454 pub fn visit_all_item_likes<'hir, V>(&'hir self, visitor: &mut V)
455 where V: itemlikevisit::ItemLikeVisitor<'hir>
457 for (_, item) in &self.items {
458 visitor.visit_item(item);
461 for (_, impl_item) in &self.impl_items {
462 visitor.visit_impl_item(impl_item);
467 /// A macro definition, in this crate or imported from another.
469 /// Not parsed directly, but created on macro import or `macro_rules!` expansion.
470 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
471 pub struct MacroDef {
473 pub attrs: HirVec<Attribute>,
476 pub imported_from: Option<Name>,
477 pub allow_internal_unstable: bool,
478 pub body: HirVec<TokenTree>,
481 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
483 /// Statements in a block
484 pub stmts: HirVec<Stmt>,
485 /// An expression at the end of the block
486 /// without a semicolon, if any
487 pub expr: Option<P<Expr>>,
489 /// Distinguishes between `unsafe { ... }` and `{ ... }`
490 pub rules: BlockCheckMode,
494 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
501 impl fmt::Debug for Pat {
502 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
503 write!(f, "pat({}: {})", self.id, print::pat_to_string(self))
508 // FIXME(#19596) this is a workaround, but there should be a better way
509 fn walk_<G>(&self, it: &mut G) -> bool
510 where G: FnMut(&Pat) -> bool
517 PatKind::Binding(.., Some(ref p)) => p.walk_(it),
518 PatKind::Struct(_, ref fields, _) => {
519 fields.iter().all(|field| field.node.pat.walk_(it))
521 PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
522 s.iter().all(|p| p.walk_(it))
524 PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
527 PatKind::Slice(ref before, ref slice, ref after) => {
528 before.iter().all(|p| p.walk_(it)) &&
529 slice.iter().all(|p| p.walk_(it)) &&
530 after.iter().all(|p| p.walk_(it))
535 PatKind::Binding(..) |
536 PatKind::Path(_) => {
542 pub fn walk<F>(&self, mut it: F) -> bool
543 where F: FnMut(&Pat) -> bool
549 /// A single field in a struct pattern
551 /// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
552 /// are treated the same as` x: x, y: ref y, z: ref mut z`,
553 /// except is_shorthand is true
554 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
555 pub struct FieldPat {
556 /// The identifier for the field
558 /// The pattern the field is destructured to
560 pub is_shorthand: bool,
563 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
564 pub enum BindingMode {
565 BindByRef(Mutability),
566 BindByValue(Mutability),
569 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
571 /// Represents a wildcard pattern (`_`)
574 /// A fresh binding `ref mut binding @ OPT_SUBPATTERN`.
575 Binding(BindingMode, Spanned<Name>, Option<P<Pat>>),
577 /// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`.
578 /// The `bool` is `true` in the presence of a `..`.
579 Struct(QPath, HirVec<Spanned<FieldPat>>, bool),
581 /// A tuple struct/variant pattern `Variant(x, y, .., z)`.
582 /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
583 /// 0 <= position <= subpats.len()
584 TupleStruct(QPath, HirVec<P<Pat>>, Option<usize>),
586 /// A path pattern for an unit struct/variant or a (maybe-associated) constant.
589 /// A tuple pattern `(a, b)`.
590 /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
591 /// 0 <= position <= subpats.len()
592 Tuple(HirVec<P<Pat>>, Option<usize>),
595 /// A reference pattern, e.g. `&mut (a, b)`
596 Ref(P<Pat>, Mutability),
599 /// A range pattern, e.g. `1...2`
600 Range(P<Expr>, P<Expr>),
601 /// `[a, b, ..i, y, z]` is represented as:
602 /// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
603 Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
606 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
607 pub enum Mutability {
612 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
614 /// The `+` operator (addition)
616 /// The `-` operator (subtraction)
618 /// The `*` operator (multiplication)
620 /// The `/` operator (division)
622 /// The `%` operator (modulus)
624 /// The `&&` operator (logical and)
626 /// The `||` operator (logical or)
628 /// The `^` operator (bitwise xor)
630 /// The `&` operator (bitwise and)
632 /// The `|` operator (bitwise or)
634 /// The `<<` operator (shift left)
636 /// The `>>` operator (shift right)
638 /// The `==` operator (equality)
640 /// The `<` operator (less than)
642 /// The `<=` operator (less than or equal to)
644 /// The `!=` operator (not equal to)
646 /// The `>=` operator (greater than or equal to)
648 /// The `>` operator (greater than)
653 pub fn as_str(self) -> &'static str {
676 pub fn is_lazy(self) -> bool {
678 BiAnd | BiOr => true,
683 pub fn is_shift(self) -> bool {
685 BiShl | BiShr => true,
690 pub fn is_comparison(self) -> bool {
692 BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
708 /// Returns `true` if the binary operator takes its arguments by value
709 pub fn is_by_value(self) -> bool {
710 !self.is_comparison()
714 pub type BinOp = Spanned<BinOp_>;
716 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
718 /// The `*` operator for dereferencing
720 /// The `!` operator for logical inversion
722 /// The `-` operator for negation
727 pub fn as_str(self) -> &'static str {
735 /// Returns `true` if the unary operator takes its argument by value
736 pub fn is_by_value(self) -> bool {
738 UnNeg | UnNot => true,
745 pub type Stmt = Spanned<Stmt_>;
747 impl fmt::Debug for Stmt_ {
748 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
750 let spanned = codemap::dummy_spanned(self.clone());
754 print::stmt_to_string(&spanned))
758 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
760 /// Could be an item or a local (let) binding:
761 StmtDecl(P<Decl>, NodeId),
763 /// Expr without trailing semi-colon (must have unit type):
764 StmtExpr(P<Expr>, NodeId),
766 /// Expr with trailing semi-colon (may have any type):
767 StmtSemi(P<Expr>, NodeId),
771 pub fn attrs(&self) -> &[Attribute] {
773 StmtDecl(ref d, _) => d.node.attrs(),
775 StmtSemi(ref e, _) => &e.attrs,
779 pub fn id(&self) -> NodeId {
781 StmtDecl(_, id) => id,
782 StmtExpr(_, id) => id,
783 StmtSemi(_, id) => id,
788 // FIXME (pending discussion of #1697, #2178...): local should really be
789 // a refinement on pat.
790 /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
791 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
794 pub ty: Option<P<Ty>>,
795 /// Initializer expression to set the value, if any
796 pub init: Option<P<Expr>>,
799 pub attrs: ThinVec<Attribute>,
802 pub type Decl = Spanned<Decl_>;
804 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
806 /// A local (let) binding:
813 pub fn attrs(&self) -> &[Attribute] {
815 DeclLocal(ref l) => &l.attrs,
821 /// represents one arm of a 'match'
822 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
824 pub attrs: HirVec<Attribute>,
825 pub pats: HirVec<P<Pat>>,
826 pub guard: Option<P<Expr>>,
830 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
832 pub name: Spanned<Name>,
835 pub is_shorthand: bool,
838 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
839 pub enum BlockCheckMode {
841 UnsafeBlock(UnsafeSource),
842 PushUnsafeBlock(UnsafeSource),
843 PopUnsafeBlock(UnsafeSource),
844 // Within this block (but outside a PopUnstableBlock), we suspend checking of stability.
849 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
850 pub enum UnsafeSource {
856 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
861 pub attrs: ThinVec<Attribute>,
864 impl fmt::Debug for Expr {
865 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
866 write!(f, "expr({}: {})", self.id, print::expr_to_string(self))
870 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
872 /// A `box x` expression.
874 /// An array (`[a, b, c, d]`)
875 ExprArray(HirVec<Expr>),
878 /// The first field resolves to the function itself (usually an `ExprPath`),
879 /// and the second field is the list of arguments
880 ExprCall(P<Expr>, HirVec<Expr>),
881 /// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
883 /// The `Spanned<Name>` is the identifier for the method name.
884 /// The vector of `Ty`s are the ascripted type parameters for the method
885 /// (within the angle brackets).
887 /// The first element of the vector of `Expr`s is the expression that
888 /// evaluates to the object on which the method is being called on (the
889 /// receiver), and the remaining elements are the rest of the arguments.
891 /// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
892 /// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
893 ExprMethodCall(Spanned<Name>, HirVec<P<Ty>>, HirVec<Expr>),
894 /// A tuple (`(a, b, c ,d)`)
895 ExprTup(HirVec<Expr>),
896 /// A binary operation (For example: `a + b`, `a * b`)
897 ExprBinary(BinOp, P<Expr>, P<Expr>),
898 /// A unary operation (For example: `!x`, `*x`)
899 ExprUnary(UnOp, P<Expr>),
900 /// A literal (For example: `1`, `"foo"`)
902 /// A cast (`foo as f64`)
903 ExprCast(P<Expr>, P<Ty>),
904 ExprType(P<Expr>, P<Ty>),
905 /// An `if` block, with an optional else block
907 /// `if expr { block } else { expr }`
908 ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
909 /// A while loop, with an optional label
911 /// `'label: while expr { block }`
912 ExprWhile(P<Expr>, P<Block>, Option<Spanned<Name>>),
913 /// Conditionless loop (can be exited with break, continue, or return)
915 /// `'label: loop { block }`
916 ExprLoop(P<Block>, Option<Spanned<Name>>, LoopSource),
917 /// A `match` block, with a source that indicates whether or not it is
918 /// the result of a desugaring, and if so, which kind.
919 ExprMatch(P<Expr>, HirVec<Arm>, MatchSource),
920 /// A closure (for example, `move |a, b, c| {a + b + c}`).
922 /// The final span is the span of the argument block `|...|`
923 ExprClosure(CaptureClause, P<FnDecl>, P<Expr>, Span),
924 /// A block (`{ ... }`)
927 /// An assignment (`a = foo()`)
928 ExprAssign(P<Expr>, P<Expr>),
929 /// An assignment with an operator
931 /// For example, `a += 1`.
932 ExprAssignOp(BinOp, P<Expr>, P<Expr>),
933 /// Access of a named struct field (`obj.foo`)
934 ExprField(P<Expr>, Spanned<Name>),
935 /// Access of an unnamed field of a struct or tuple-struct
937 /// For example, `foo.0`.
938 ExprTupField(P<Expr>, Spanned<usize>),
939 /// An indexing operation (`foo[2]`)
940 ExprIndex(P<Expr>, P<Expr>),
942 /// Path to a definition, possibly containing lifetime or type parameters.
945 /// A referencing operation (`&a` or `&mut a`)
946 ExprAddrOf(Mutability, P<Expr>),
947 /// A `break`, with an optional label to break
948 ExprBreak(Option<Spanned<Name>>, Option<P<Expr>>),
949 /// A `continue`, with an optional label
950 ExprAgain(Option<Spanned<Name>>),
951 /// A `return`, with an optional value to be returned
952 ExprRet(Option<P<Expr>>),
954 /// Inline assembly (from `asm!`), with its outputs and inputs.
955 ExprInlineAsm(P<InlineAsm>, HirVec<Expr>, HirVec<Expr>),
957 /// A struct or struct-like variant literal expression.
959 /// For example, `Foo {x: 1, y: 2}`, or
960 /// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`.
961 ExprStruct(QPath, HirVec<Field>, Option<P<Expr>>),
963 /// An array literal constructed from one repeated element.
965 /// For example, `[1; 5]`. The first expression is the element
966 /// to be repeated; the second is the number of times to repeat it.
967 ExprRepeat(P<Expr>, P<Expr>),
970 /// Optionally `Self`-qualified value/type path or associated extension.
971 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
973 /// Path to a definition, optionally "fully-qualified" with a `Self`
974 /// type, if the path points to an associated item in a trait.
976 /// E.g. an unqualified path like `Clone::clone` has `None` for `Self`,
977 /// while `<Vec<T> as Clone>::clone` has `Some(Vec<T>)` for `Self`,
978 /// even though they both have the same two-segment `Clone::clone` `Path`.
979 Resolved(Option<P<Ty>>, P<Path>),
981 /// Type-related paths, e.g. `<T>::default` or `<T>::Output`.
982 /// Will be resolved by type-checking to an associated item.
984 /// UFCS source paths can desugar into this, with `Vec::new` turning into
985 /// `<Vec>::new`, and `T::X::Y::method` into `<<<T>::X>::Y>::method`,
986 /// the `X` and `Y` nodes being each a `TyPath(QPath::TypeRelative(..))`.
987 TypeRelative(P<Ty>, P<PathSegment>)
990 impl fmt::Display for QPath {
991 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
992 write!(f, "{}", print::qpath_to_string(self))
996 /// Hints at the original code for a `match _ { .. }`
997 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
998 pub enum MatchSource {
999 /// A `match _ { .. }`
1001 /// An `if let _ = _ { .. }` (optionally with `else { .. }`)
1003 contains_else_clause: bool,
1005 /// A `while let _ = _ { .. }` (which was desugared to a
1006 /// `loop { match _ { .. } }`)
1008 /// A desugared `for _ in _ { .. }` loop
1010 /// A desugared `?` operator
1014 /// The loop type that yielded an ExprLoop
1015 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1016 pub enum LoopSource {
1017 /// A `loop { .. }` loop
1019 /// A `while let _ = _ { .. }` loop
1021 /// A `for _ in _ { .. }` loop
1026 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1027 pub enum CaptureClause {
1032 // NB: If you change this, you'll probably want to change the corresponding
1033 // type structure in middle/ty.rs as well.
1034 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1037 pub mutbl: Mutability,
1040 /// Represents a method's signature in a trait declaration or implementation.
1041 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1042 pub struct MethodSig {
1043 pub unsafety: Unsafety,
1044 pub constness: Constness,
1046 pub decl: P<FnDecl>,
1047 pub generics: Generics,
1050 /// Represents an item declaration within a trait declaration,
1051 /// possibly including a default implementation. A trait item is
1052 /// either required (meaning it doesn't have an implementation, just a
1053 /// signature) or provided (meaning it has a default implementation).
1054 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1055 pub struct TraitItem {
1058 pub attrs: HirVec<Attribute>,
1059 pub node: TraitItem_,
1063 /// Represents a trait method or associated constant or type
1064 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1065 pub enum TraitItem_ {
1066 /// An associated constant with an optional value (otherwise `impl`s
1067 /// must contain a value)
1068 ConstTraitItem(P<Ty>, Option<P<Expr>>),
1069 /// A method with an optional body
1070 MethodTraitItem(MethodSig, Option<P<Expr>>),
1071 /// An associated type with (possibly empty) bounds and optional concrete
1073 TypeTraitItem(TyParamBounds, Option<P<Ty>>),
1076 // The bodies for items are stored "out of line", in a separate
1077 // hashmap in the `Crate`. Here we just record the node-id of the item
1078 // so it can fetched later.
1079 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)]
1080 pub struct ImplItemId {
1081 pub node_id: NodeId,
1084 /// Represents anything within an `impl` block
1085 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1086 pub struct ImplItem {
1089 pub vis: Visibility,
1090 pub defaultness: Defaultness,
1091 pub attrs: HirVec<Attribute>,
1092 pub node: ImplItemKind,
1096 /// Represents different contents within `impl`s
1097 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1098 pub enum ImplItemKind {
1099 /// An associated constant of the given type, set to the constant result
1100 /// of the expression
1101 Const(P<Ty>, P<Expr>),
1102 /// A method implementation with the given signature and body
1103 Method(MethodSig, P<Expr>),
1104 /// An associated type
1108 // Bind a type to an associated type: `A=Foo`.
1109 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1110 pub struct TypeBinding {
1118 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1125 impl fmt::Debug for Ty {
1126 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1127 write!(f, "type({})", print::ty_to_string(self))
1131 /// Not represented directly in the AST, referred to by name through a ty_path.
1132 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1142 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1143 pub struct BareFnTy {
1144 pub unsafety: Unsafety,
1146 pub lifetimes: HirVec<LifetimeDef>,
1147 pub decl: P<FnDecl>,
1150 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1151 /// The different kinds of types recognized by the compiler
1153 /// A variable length slice (`[T]`)
1155 /// A fixed length array (`[T; n]`)
1156 TyArray(P<Ty>, P<Expr>),
1157 /// A raw pointer (`*const T` or `*mut T`)
1159 /// A reference (`&'a T` or `&'a mut T`)
1160 TyRptr(Option<Lifetime>, MutTy),
1161 /// A bare function (e.g. `fn(usize) -> bool`)
1162 TyBareFn(P<BareFnTy>),
1163 /// The never type (`!`)
1165 /// A tuple (`(A, B, C, D,...)`)
1166 TyTup(HirVec<P<Ty>>),
1167 /// A path to a type definition (`module::module::...::Type`), or an
1168 /// associated type, e.g. `<Vec<T> as Trait>::Type` or `<T>::Target`.
1170 /// Type parameters may be stored in each `PathSegment`.
1173 /// Something like `A+B`. Note that `B` must always be a path.
1174 TyObjectSum(P<Ty>, TyParamBounds),
1175 /// A type like `for<'a> Foo<&'a Bar>`
1176 TyPolyTraitRef(TyParamBounds),
1177 /// An `impl TraitA+TraitB` type.
1178 TyImplTrait(TyParamBounds),
1181 /// TyInfer means the type should be inferred instead of it having been
1182 /// specified. This can appear anywhere in a type.
1186 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1187 pub struct InlineAsmOutput {
1188 pub constraint: Symbol,
1190 pub is_indirect: bool,
1193 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1194 pub struct InlineAsm {
1196 pub asm_str_style: StrStyle,
1197 pub outputs: HirVec<InlineAsmOutput>,
1198 pub inputs: HirVec<Symbol>,
1199 pub clobbers: HirVec<Symbol>,
1201 pub alignstack: bool,
1202 pub dialect: AsmDialect,
1203 pub expn_id: ExpnId,
1206 /// represents an argument in a function header
1207 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1214 /// Alternative representation for `Arg`s describing `self` parameter of methods.
1215 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1217 /// `self`, `mut self`
1219 /// `&'lt self`, `&'lt mut self`
1220 Region(Option<Lifetime>, Mutability),
1221 /// `self: TYPE`, `mut self: TYPE`
1222 Explicit(P<Ty>, Mutability),
1225 pub type ExplicitSelf = Spanned<SelfKind>;
1228 pub fn to_self(&self) -> Option<ExplicitSelf> {
1229 if let PatKind::Binding(BindByValue(mutbl), name, _) = self.pat.node {
1230 if name.node == keywords::SelfValue.name() {
1231 return match self.ty.node {
1232 TyInfer => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
1233 TyRptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyInfer => {
1234 Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
1236 _ => Some(respan(mk_sp(self.pat.span.lo, self.ty.span.hi),
1237 SelfKind::Explicit(self.ty.clone(), mutbl)))
1244 pub fn is_self(&self) -> bool {
1245 if let PatKind::Binding(_, name, _) = self.pat.node {
1246 name.node == keywords::SelfValue.name()
1253 /// Represents the header (not the body) of a function declaration
1254 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1256 pub inputs: HirVec<Arg>,
1257 pub output: FunctionRetTy,
1262 pub fn get_self(&self) -> Option<ExplicitSelf> {
1263 self.inputs.get(0).and_then(Arg::to_self)
1265 pub fn has_self(&self) -> bool {
1266 self.inputs.get(0).map(Arg::is_self).unwrap_or(false)
1270 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1276 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1277 pub enum Constness {
1282 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1283 pub enum Defaultness {
1284 Default { has_value: bool },
1289 pub fn has_value(&self) -> bool {
1291 Defaultness::Default { has_value, .. } => has_value,
1292 Defaultness::Final => true,
1296 pub fn is_final(&self) -> bool {
1297 *self == Defaultness::Final
1300 pub fn is_default(&self) -> bool {
1302 Defaultness::Default { .. } => true,
1308 impl fmt::Display for Unsafety {
1309 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1310 fmt::Display::fmt(match *self {
1311 Unsafety::Normal => "normal",
1312 Unsafety::Unsafe => "unsafe",
1318 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1319 pub enum ImplPolarity {
1320 /// `impl Trait for Type`
1322 /// `impl !Trait for Type`
1326 impl fmt::Debug for ImplPolarity {
1327 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1329 ImplPolarity::Positive => "positive".fmt(f),
1330 ImplPolarity::Negative => "negative".fmt(f),
1336 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1337 pub enum FunctionRetTy {
1338 /// Return type is not specified.
1340 /// Functions default to `()` and
1341 /// closures default to inference. Span points to where return
1342 /// type would be inserted.
1343 DefaultReturn(Span),
1348 impl FunctionRetTy {
1349 pub fn span(&self) -> Span {
1351 DefaultReturn(span) => span,
1352 Return(ref ty) => ty.span,
1357 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1359 /// A span from the first token past `{` to the last token until `}`.
1360 /// For `mod foo;`, the inner span ranges from the first token
1361 /// to the last token in the external file.
1363 pub item_ids: HirVec<ItemId>,
1366 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1367 pub struct ForeignMod {
1369 pub items: HirVec<ForeignItem>,
1372 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1373 pub struct EnumDef {
1374 pub variants: HirVec<Variant>,
1377 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1378 pub struct Variant_ {
1380 pub attrs: HirVec<Attribute>,
1381 pub data: VariantData,
1382 /// Explicit discriminant, eg `Foo = 1`
1383 pub disr_expr: Option<P<Expr>>,
1386 pub type Variant = Spanned<Variant_>;
1388 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1389 pub struct PathListItem_ {
1391 /// renamed in list, eg `use foo::{bar as baz};`
1392 pub rename: Option<Name>,
1396 pub type PathListItem = Spanned<PathListItem_>;
1398 pub type ViewPath = Spanned<ViewPath_>;
1400 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1401 pub enum ViewPath_ {
1402 /// `foo::bar::baz as quux`
1406 /// `foo::bar::baz` (with `as baz` implicitly on the right)
1407 ViewPathSimple(Name, Path),
1412 /// `foo::bar::{a,b,c}`
1413 ViewPathList(Path, HirVec<PathListItem>),
1416 /// TraitRef's appear in impls.
1418 /// resolve maps each TraitRef's ref_id to its defining trait; that's all
1419 /// that the ref_id is for. Note that ref_id's value is not the NodeId of the
1420 /// trait being referred to but just a unique NodeId that serves as a key
1421 /// within the DefMap.
1422 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1423 pub struct TraitRef {
1428 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1429 pub struct PolyTraitRef {
1430 /// The `'a` in `<'a> Foo<&'a T>`
1431 pub bound_lifetimes: HirVec<LifetimeDef>,
1433 /// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
1434 pub trait_ref: TraitRef,
1439 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1440 pub enum Visibility {
1443 Restricted { path: P<Path>, id: NodeId },
1447 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1448 pub struct StructField {
1451 pub vis: Visibility,
1454 pub attrs: HirVec<Attribute>,
1458 // Still necessary in couple of places
1459 pub fn is_positional(&self) -> bool {
1460 let first = self.name.as_str().as_bytes()[0];
1461 first >= b'0' && first <= b'9'
1465 /// Fields and Ids of enum variants and structs
1467 /// For enum variants: `NodeId` represents both an Id of the variant itself (relevant for all
1468 /// variant kinds) and an Id of the variant's constructor (not relevant for `Struct`-variants).
1469 /// One shared Id can be successfully used for these two purposes.
1470 /// Id of the whole enum lives in `Item`.
1472 /// For structs: `NodeId` represents an Id of the structure's constructor, so it is not actually
1473 /// used for `Struct`-structs (but still presents). Structures don't have an analogue of "Id of
1474 /// the variant itself" from enum variants.
1475 /// Id of the whole struct lives in `Item`.
1476 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1477 pub enum VariantData {
1478 Struct(HirVec<StructField>, NodeId),
1479 Tuple(HirVec<StructField>, NodeId),
1484 pub fn fields(&self) -> &[StructField] {
1486 VariantData::Struct(ref fields, _) | VariantData::Tuple(ref fields, _) => fields,
1490 pub fn id(&self) -> NodeId {
1492 VariantData::Struct(_, id) | VariantData::Tuple(_, id) | VariantData::Unit(id) => id,
1495 pub fn is_struct(&self) -> bool {
1496 if let VariantData::Struct(..) = *self {
1502 pub fn is_tuple(&self) -> bool {
1503 if let VariantData::Tuple(..) = *self {
1509 pub fn is_unit(&self) -> bool {
1510 if let VariantData::Unit(..) = *self {
1518 // The bodies for items are stored "out of line", in a separate
1519 // hashmap in the `Crate`. Here we just record the node-id of the item
1520 // so it can fetched later.
1521 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1526 // FIXME (#3300): Should allow items to be anonymous. Right now
1527 // we just use dummy names for anon items.
1530 /// The name might be a dummy name in case of anonymous items
1531 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1534 pub attrs: HirVec<Attribute>,
1537 pub vis: Visibility,
1541 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1543 /// An`extern crate` item, with optional original crate name,
1545 /// e.g. `extern crate foo` or `extern crate foo_bar as foo`
1546 ItemExternCrate(Option<Name>),
1547 /// A `use` or `pub use` item
1548 ItemUse(P<ViewPath>),
1551 ItemStatic(P<Ty>, Mutability, P<Expr>),
1553 ItemConst(P<Ty>, P<Expr>),
1554 /// A function declaration
1555 ItemFn(P<FnDecl>, Unsafety, Constness, Abi, Generics, P<Expr>),
1558 /// An external module
1559 ItemForeignMod(ForeignMod),
1560 /// A type alias, e.g. `type Foo = Bar<u8>`
1561 ItemTy(P<Ty>, Generics),
1562 /// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
1563 ItemEnum(EnumDef, Generics),
1564 /// A struct definition, e.g. `struct Foo<A> {x: A}`
1565 ItemStruct(VariantData, Generics),
1566 /// A union definition, e.g. `union Foo<A, B> {x: A, y: B}`
1567 ItemUnion(VariantData, Generics),
1568 /// Represents a Trait Declaration
1569 ItemTrait(Unsafety, Generics, TyParamBounds, HirVec<TraitItem>),
1571 // Default trait implementations
1573 /// `impl Trait for .. {}`
1574 ItemDefaultImpl(Unsafety, TraitRef),
1575 /// An implementation, eg `impl<A> Trait for Foo { .. }`
1579 Option<TraitRef>, // (optional) trait this impl implements
1581 HirVec<ImplItemRef>),
1585 pub fn descriptive_variant(&self) -> &str {
1587 ItemExternCrate(..) => "extern crate",
1588 ItemUse(..) => "use",
1589 ItemStatic(..) => "static item",
1590 ItemConst(..) => "constant item",
1591 ItemFn(..) => "function",
1592 ItemMod(..) => "module",
1593 ItemForeignMod(..) => "foreign module",
1594 ItemTy(..) => "type alias",
1595 ItemEnum(..) => "enum",
1596 ItemStruct(..) => "struct",
1597 ItemUnion(..) => "union",
1598 ItemTrait(..) => "trait",
1600 ItemDefaultImpl(..) => "item",
1605 /// A reference from an impl to one of its associated items. This
1606 /// contains the item's id, naturally, but also the item's name and
1607 /// some other high-level details (like whether it is an associated
1608 /// type or method, and whether it is public). This allows other
1609 /// passes to find the impl they want without loading the id (which
1610 /// means fewer edges in the incremental compilation graph).
1611 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1612 pub struct ImplItemRef {
1615 pub kind: AssociatedItemKind,
1617 pub vis: Visibility,
1618 pub defaultness: Defaultness,
1621 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1622 pub enum AssociatedItemKind {
1624 Method { has_self: bool },
1628 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1629 pub struct ForeignItem {
1631 pub attrs: HirVec<Attribute>,
1632 pub node: ForeignItem_,
1635 pub vis: Visibility,
1638 /// An item within an `extern` block
1639 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1640 pub enum ForeignItem_ {
1641 /// A foreign function
1642 ForeignItemFn(P<FnDecl>, Generics),
1643 /// A foreign static item (`static ext: u8`), with optional mutability
1644 /// (the boolean is true when mutable)
1645 ForeignItemStatic(P<Ty>, bool),
1649 pub fn descriptive_variant(&self) -> &str {
1651 ForeignItemFn(..) => "foreign function",
1652 ForeignItemStatic(..) => "foreign static item",
1657 /// A free variable referred to in a function.
1658 #[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
1659 pub struct Freevar {
1660 /// The variable being accessed free.
1663 // First span where it is accessed (there can be multiple).
1667 pub type FreevarMap = NodeMap<Vec<Freevar>>;
1669 pub type CaptureModeMap = NodeMap<CaptureClause>;
1671 #[derive(Clone, Debug)]
1672 pub struct TraitCandidate {
1674 pub import_id: Option<NodeId>,
1677 // Trait method resolution
1678 pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
1680 // Map from the NodeId of a glob import to a list of items which are actually
1682 pub type GlobMap = NodeMap<FxHashSet<Name>>;