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::Visibility::{Public, Inherited};
31 pub use self::PathParameters::*;
34 use hir::def_id::DefId;
35 use util::nodemap::{NodeMap, FxHashSet};
37 use syntax_pos::{mk_sp, Span, ExpnId, DUMMY_SP};
38 use syntax::codemap::{self, respan, Spanned};
40 use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
41 use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
43 use syntax::symbol::{Symbol, keywords};
44 use syntax::tokenstream::TokenTree;
45 use syntax::util::ThinVec;
47 use std::collections::BTreeMap;
50 /// HIR doesn't commit to a concrete storage type and have its own alias for a vector.
51 /// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar
52 /// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead
53 /// of `Vec` to avoid keeping extra capacity.
54 pub type HirVec<T> = P<[T]>;
56 macro_rules! hir_vec {
57 ($elem:expr; $n:expr) => (
58 $crate::hir::HirVec::from(vec![$elem; $n])
61 $crate::hir::HirVec::from(vec![$($x),*])
63 ($($x:expr,)*) => (hir_vec![$($x),*])
70 pub mod itemlikevisit;
77 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
84 impl fmt::Debug for Lifetime {
85 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 print::lifetime_to_string(self))
93 /// A lifetime definition, eg `'a: 'b+'c+'d`
94 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
95 pub struct LifetimeDef {
96 pub lifetime: Lifetime,
97 pub bounds: HirVec<Lifetime>,
98 pub pure_wrt_drop: bool,
101 /// A "Path" is essentially Rust's notion of a name; for instance:
102 /// std::cmp::PartialEq . It's represented as a sequence of identifiers,
103 /// along with a bunch of supporting information.
104 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
107 /// A `::foo` path, is relative to the crate root rather than current
108 /// module (like paths in an import).
110 /// The segments in the path: the things separated by `::`.
111 pub segments: HirVec<PathSegment>,
114 impl fmt::Debug for Path {
115 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
116 write!(f, "path({})", print::path_to_string(self))
120 impl fmt::Display for Path {
121 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
122 write!(f, "{}", print::path_to_string(self))
127 /// Convert a span and an identifier to the corresponding
129 pub fn from_name(s: Span, name: Name) -> Path {
133 segments: hir_vec![PathSegment {
135 parameters: PathParameters::none()
141 /// A segment of a path: an identifier, an optional lifetime, and a set of
143 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
144 pub struct PathSegment {
145 /// The identifier portion of this path segment.
148 /// Type/lifetime parameters attached to this path. They come in
149 /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
150 /// this is more than just simple syntactic sugar; the use of
151 /// parens affects the region binding rules, so we preserve the
153 pub parameters: PathParameters,
156 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
157 pub enum PathParameters {
158 /// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>`
159 AngleBracketedParameters(AngleBracketedParameterData),
160 /// The `(A,B)` and `C` in `Foo(A,B) -> C`
161 ParenthesizedParameters(ParenthesizedParameterData),
164 impl PathParameters {
165 pub fn none() -> PathParameters {
166 AngleBracketedParameters(AngleBracketedParameterData {
167 lifetimes: HirVec::new(),
168 types: HirVec::new(),
170 bindings: HirVec::new(),
174 pub fn is_empty(&self) -> bool {
176 AngleBracketedParameters(ref data) => data.is_empty(),
178 // Even if the user supplied no types, something like
179 // `X()` is equivalent to `X<(),()>`.
180 ParenthesizedParameters(..) => false,
184 pub fn has_lifetimes(&self) -> bool {
186 AngleBracketedParameters(ref data) => !data.lifetimes.is_empty(),
187 ParenthesizedParameters(_) => false,
191 pub fn has_types(&self) -> bool {
193 AngleBracketedParameters(ref data) => !data.types.is_empty(),
194 ParenthesizedParameters(..) => true,
198 /// Returns the types that the user wrote. Note that these do not necessarily map to the type
199 /// parameters in the parenthesized case.
200 pub fn types(&self) -> HirVec<&P<Ty>> {
202 AngleBracketedParameters(ref data) => {
203 data.types.iter().collect()
205 ParenthesizedParameters(ref data) => {
208 .chain(data.output.iter())
214 pub fn lifetimes(&self) -> HirVec<&Lifetime> {
216 AngleBracketedParameters(ref data) => {
217 data.lifetimes.iter().collect()
219 ParenthesizedParameters(_) => {
225 pub fn bindings(&self) -> HirVec<&TypeBinding> {
227 AngleBracketedParameters(ref data) => {
228 data.bindings.iter().collect()
230 ParenthesizedParameters(_) => {
237 /// A path like `Foo<'a, T>`
238 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
239 pub struct AngleBracketedParameterData {
240 /// The lifetime parameters for this path segment.
241 pub lifetimes: HirVec<Lifetime>,
242 /// The type parameters for this path segment, if present.
243 pub types: HirVec<P<Ty>>,
244 /// Whether to infer remaining type parameters, if any.
245 /// This only applies to expression and pattern paths, and
246 /// out of those only the segments with no type parameters
247 /// to begin with, e.g. `Vec::new` is `<Vec<..>>::new::<..>`.
248 pub infer_types: bool,
249 /// Bindings (equality constraints) on associated types, if present.
250 /// E.g., `Foo<A=Bar>`.
251 pub bindings: HirVec<TypeBinding>,
254 impl AngleBracketedParameterData {
255 fn is_empty(&self) -> bool {
256 self.lifetimes.is_empty() && self.types.is_empty() && self.bindings.is_empty()
260 /// A path like `Foo(A,B) -> C`
261 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
262 pub struct ParenthesizedParameterData {
267 pub inputs: HirVec<P<Ty>>,
270 pub output: Option<P<Ty>>,
273 /// The AST represents all type param bounds as types.
274 /// typeck::collect::compute_bounds matches these against
275 /// the "special" built-in traits (see middle::lang_items) and
276 /// detects Copy, Send and Sync.
277 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
278 pub enum TyParamBound {
279 TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
280 RegionTyParamBound(Lifetime),
283 /// A modifier on a bound, currently this is only used for `?Sized`, where the
284 /// modifier is `Maybe`. Negative bounds should also be handled here.
285 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
286 pub enum TraitBoundModifier {
291 pub type TyParamBounds = HirVec<TyParamBound>;
293 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
297 pub bounds: TyParamBounds,
298 pub default: Option<P<Ty>>,
300 pub pure_wrt_drop: bool,
303 /// Represents lifetimes and type parameters attached to a declaration
304 /// of a function, enum, trait, etc.
305 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
306 pub struct Generics {
307 pub lifetimes: HirVec<LifetimeDef>,
308 pub ty_params: HirVec<TyParam>,
309 pub where_clause: WhereClause,
314 pub fn empty() -> Generics {
316 lifetimes: HirVec::new(),
317 ty_params: HirVec::new(),
318 where_clause: WhereClause {
320 predicates: HirVec::new(),
326 pub fn is_lt_parameterized(&self) -> bool {
327 !self.lifetimes.is_empty()
330 pub fn is_type_parameterized(&self) -> bool {
331 !self.ty_params.is_empty()
334 pub fn is_parameterized(&self) -> bool {
335 self.is_lt_parameterized() || self.is_type_parameterized()
339 pub enum UnsafeGeneric {
340 Region(LifetimeDef, &'static str),
341 Type(TyParam, &'static str),
345 pub fn attr_name(&self) -> &'static str {
347 UnsafeGeneric::Region(_, s) => s,
348 UnsafeGeneric::Type(_, s) => s,
354 pub fn carries_unsafe_attr(&self) -> Option<UnsafeGeneric> {
355 for r in &self.lifetimes {
357 return Some(UnsafeGeneric::Region(r.clone(), "may_dangle"));
360 for t in &self.ty_params {
362 return Some(UnsafeGeneric::Type(t.clone(), "may_dangle"));
369 /// A `where` clause in a definition
370 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
371 pub struct WhereClause {
373 pub predicates: HirVec<WherePredicate>,
376 /// A single predicate in a `where` clause
377 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
378 pub enum WherePredicate {
379 /// A type binding, eg `for<'c> Foo: Send+Clone+'c`
380 BoundPredicate(WhereBoundPredicate),
381 /// A lifetime predicate, e.g. `'a: 'b+'c`
382 RegionPredicate(WhereRegionPredicate),
383 /// An equality predicate (unsupported)
384 EqPredicate(WhereEqPredicate),
387 /// A type bound, eg `for<'c> Foo: Send+Clone+'c`
388 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
389 pub struct WhereBoundPredicate {
391 /// Any lifetimes from a `for` binding
392 pub bound_lifetimes: HirVec<LifetimeDef>,
393 /// The type being bounded
394 pub bounded_ty: P<Ty>,
395 /// Trait and lifetime bounds (`Clone+Send+'static`)
396 pub bounds: TyParamBounds,
399 /// A lifetime predicate, e.g. `'a: 'b+'c`
400 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
401 pub struct WhereRegionPredicate {
403 pub lifetime: Lifetime,
404 pub bounds: HirVec<Lifetime>,
407 /// An equality predicate (unsupported), e.g. `T=int`
408 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
409 pub struct WhereEqPredicate {
416 pub type CrateConfig = HirVec<P<MetaItem>>;
418 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
421 pub attrs: HirVec<Attribute>,
423 pub exported_macros: HirVec<MacroDef>,
425 // NB: We use a BTreeMap here so that `visit_all_items` iterates
426 // over the ids in increasing order. In principle it should not
427 // matter what order we visit things in, but in *practice* it
428 // does, because it can affect the order in which errors are
429 // detected, which in turn can make compile-fail tests yield
430 // slightly different results.
431 pub items: BTreeMap<NodeId, Item>,
433 pub impl_items: BTreeMap<ImplItemId, ImplItem>,
437 pub fn item(&self, id: NodeId) -> &Item {
441 pub fn impl_item(&self, id: ImplItemId) -> &ImplItem {
442 &self.impl_items[&id]
445 /// Visits all items in the crate in some determinstic (but
446 /// unspecified) order. If you just need to process every item,
447 /// but don't care about nesting, this method is the best choice.
449 /// If you do care about nesting -- usually because your algorithm
450 /// follows lexical scoping rules -- then you want a different
451 /// approach. You should override `visit_nested_item` in your
452 /// visitor and then call `intravisit::walk_crate` instead.
453 pub fn visit_all_item_likes<'hir, V>(&'hir self, visitor: &mut V)
454 where V: itemlikevisit::ItemLikeVisitor<'hir>
456 for (_, item) in &self.items {
457 visitor.visit_item(item);
460 for (_, impl_item) in &self.impl_items {
461 visitor.visit_impl_item(impl_item);
466 /// A macro definition, in this crate or imported from another.
468 /// Not parsed directly, but created on macro import or `macro_rules!` expansion.
469 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
470 pub struct MacroDef {
472 pub attrs: HirVec<Attribute>,
475 pub imported_from: Option<Name>,
476 pub allow_internal_unstable: bool,
477 pub body: HirVec<TokenTree>,
480 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
482 /// Statements in a block
483 pub stmts: HirVec<Stmt>,
484 /// An expression at the end of the block
485 /// without a semicolon, if any
486 pub expr: Option<P<Expr>>,
488 /// Distinguishes between `unsafe { ... }` and `{ ... }`
489 pub rules: BlockCheckMode,
493 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
500 impl fmt::Debug for Pat {
501 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
502 write!(f, "pat({}: {})", self.id, print::pat_to_string(self))
507 // FIXME(#19596) this is a workaround, but there should be a better way
508 fn walk_<G>(&self, it: &mut G) -> bool
509 where G: FnMut(&Pat) -> bool
516 PatKind::Binding(.., Some(ref p)) => p.walk_(it),
517 PatKind::Struct(_, ref fields, _) => {
518 fields.iter().all(|field| field.node.pat.walk_(it))
520 PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
521 s.iter().all(|p| p.walk_(it))
523 PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
526 PatKind::Slice(ref before, ref slice, ref after) => {
527 before.iter().all(|p| p.walk_(it)) &&
528 slice.iter().all(|p| p.walk_(it)) &&
529 after.iter().all(|p| p.walk_(it))
534 PatKind::Binding(..) |
535 PatKind::Path(_) => {
541 pub fn walk<F>(&self, mut it: F) -> bool
542 where F: FnMut(&Pat) -> bool
548 /// A single field in a struct pattern
550 /// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
551 /// are treated the same as` x: x, y: ref y, z: ref mut z`,
552 /// except is_shorthand is true
553 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
554 pub struct FieldPat {
555 /// The identifier for the field
557 /// The pattern the field is destructured to
559 pub is_shorthand: bool,
562 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
563 pub enum BindingMode {
564 BindByRef(Mutability),
565 BindByValue(Mutability),
568 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
570 /// Represents a wildcard pattern (`_`)
573 /// A fresh binding `ref mut binding @ OPT_SUBPATTERN`.
574 Binding(BindingMode, Spanned<Name>, Option<P<Pat>>),
576 /// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`.
577 /// The `bool` is `true` in the presence of a `..`.
578 Struct(QPath, HirVec<Spanned<FieldPat>>, bool),
580 /// A tuple struct/variant pattern `Variant(x, y, .., z)`.
581 /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
582 /// 0 <= position <= subpats.len()
583 TupleStruct(QPath, HirVec<P<Pat>>, Option<usize>),
585 /// A path pattern for an unit struct/variant or a (maybe-associated) constant.
588 /// A tuple pattern `(a, b)`.
589 /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
590 /// 0 <= position <= subpats.len()
591 Tuple(HirVec<P<Pat>>, Option<usize>),
594 /// A reference pattern, e.g. `&mut (a, b)`
595 Ref(P<Pat>, Mutability),
598 /// A range pattern, e.g. `1...2`
599 Range(P<Expr>, P<Expr>),
600 /// `[a, b, ..i, y, z]` is represented as:
601 /// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
602 Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
605 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
606 pub enum Mutability {
611 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
613 /// The `+` operator (addition)
615 /// The `-` operator (subtraction)
617 /// The `*` operator (multiplication)
619 /// The `/` operator (division)
621 /// The `%` operator (modulus)
623 /// The `&&` operator (logical and)
625 /// The `||` operator (logical or)
627 /// The `^` operator (bitwise xor)
629 /// The `&` operator (bitwise and)
631 /// The `|` operator (bitwise or)
633 /// The `<<` operator (shift left)
635 /// The `>>` operator (shift right)
637 /// The `==` operator (equality)
639 /// The `<` operator (less than)
641 /// The `<=` operator (less than or equal to)
643 /// The `!=` operator (not equal to)
645 /// The `>=` operator (greater than or equal to)
647 /// The `>` operator (greater than)
652 pub fn as_str(self) -> &'static str {
675 pub fn is_lazy(self) -> bool {
677 BiAnd | BiOr => true,
682 pub fn is_shift(self) -> bool {
684 BiShl | BiShr => true,
689 pub fn is_comparison(self) -> bool {
691 BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
707 /// Returns `true` if the binary operator takes its arguments by value
708 pub fn is_by_value(self) -> bool {
709 !self.is_comparison()
713 pub type BinOp = Spanned<BinOp_>;
715 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
717 /// The `*` operator for dereferencing
719 /// The `!` operator for logical inversion
721 /// The `-` operator for negation
726 pub fn as_str(self) -> &'static str {
734 /// Returns `true` if the unary operator takes its argument by value
735 pub fn is_by_value(self) -> bool {
737 UnNeg | UnNot => true,
744 pub type Stmt = Spanned<Stmt_>;
746 impl fmt::Debug for Stmt_ {
747 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
749 let spanned = codemap::dummy_spanned(self.clone());
753 print::stmt_to_string(&spanned))
757 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
759 /// Could be an item or a local (let) binding:
760 StmtDecl(P<Decl>, NodeId),
762 /// Expr without trailing semi-colon (must have unit type):
763 StmtExpr(P<Expr>, NodeId),
765 /// Expr with trailing semi-colon (may have any type):
766 StmtSemi(P<Expr>, NodeId),
770 pub fn attrs(&self) -> &[Attribute] {
772 StmtDecl(ref d, _) => d.node.attrs(),
774 StmtSemi(ref e, _) => &e.attrs,
778 pub fn id(&self) -> NodeId {
780 StmtDecl(_, id) => id,
781 StmtExpr(_, id) => id,
782 StmtSemi(_, id) => id,
787 // FIXME (pending discussion of #1697, #2178...): local should really be
788 // a refinement on pat.
789 /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
790 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
793 pub ty: Option<P<Ty>>,
794 /// Initializer expression to set the value, if any
795 pub init: Option<P<Expr>>,
798 pub attrs: ThinVec<Attribute>,
801 pub type Decl = Spanned<Decl_>;
803 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
805 /// A local (let) binding:
812 pub fn attrs(&self) -> &[Attribute] {
814 DeclLocal(ref l) => &l.attrs,
820 /// represents one arm of a 'match'
821 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
823 pub attrs: HirVec<Attribute>,
824 pub pats: HirVec<P<Pat>>,
825 pub guard: Option<P<Expr>>,
829 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
831 pub name: Spanned<Name>,
834 pub is_shorthand: bool,
837 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
838 pub enum BlockCheckMode {
840 UnsafeBlock(UnsafeSource),
841 PushUnsafeBlock(UnsafeSource),
842 PopUnsafeBlock(UnsafeSource),
843 // Within this block (but outside a PopUnstableBlock), we suspend checking of stability.
848 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
849 pub enum UnsafeSource {
855 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
860 pub attrs: ThinVec<Attribute>,
863 impl fmt::Debug for Expr {
864 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
865 write!(f, "expr({}: {})", self.id, print::expr_to_string(self))
869 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
871 /// A `box x` expression.
873 /// An array (`[a, b, c, d]`)
874 ExprArray(HirVec<Expr>),
877 /// The first field resolves to the function itself (usually an `ExprPath`),
878 /// and the second field is the list of arguments
879 ExprCall(P<Expr>, HirVec<Expr>),
880 /// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
882 /// The `Spanned<Name>` is the identifier for the method name.
883 /// The vector of `Ty`s are the ascripted type parameters for the method
884 /// (within the angle brackets).
886 /// The first element of the vector of `Expr`s is the expression that
887 /// evaluates to the object on which the method is being called on (the
888 /// receiver), and the remaining elements are the rest of the arguments.
890 /// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
891 /// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
892 ExprMethodCall(Spanned<Name>, HirVec<P<Ty>>, HirVec<Expr>),
893 /// A tuple (`(a, b, c ,d)`)
894 ExprTup(HirVec<Expr>),
895 /// A binary operation (For example: `a + b`, `a * b`)
896 ExprBinary(BinOp, P<Expr>, P<Expr>),
897 /// A unary operation (For example: `!x`, `*x`)
898 ExprUnary(UnOp, P<Expr>),
899 /// A literal (For example: `1`, `"foo"`)
901 /// A cast (`foo as f64`)
902 ExprCast(P<Expr>, P<Ty>),
903 ExprType(P<Expr>, P<Ty>),
904 /// An `if` block, with an optional else block
906 /// `if expr { block } else { expr }`
907 ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
908 /// A while loop, with an optional label
910 /// `'label: while expr { block }`
911 ExprWhile(P<Expr>, P<Block>, Option<Spanned<Name>>),
912 /// Conditionless loop (can be exited with break, continue, or return)
914 /// `'label: loop { block }`
915 ExprLoop(P<Block>, Option<Spanned<Name>>, LoopSource),
916 /// A `match` block, with a source that indicates whether or not it is
917 /// the result of a desugaring, and if so, which kind.
918 ExprMatch(P<Expr>, HirVec<Arm>, MatchSource),
919 /// A closure (for example, `move |a, b, c| {a + b + c}`).
921 /// The final span is the span of the argument block `|...|`
922 ExprClosure(CaptureClause, P<FnDecl>, P<Expr>, Span),
923 /// A block (`{ ... }`)
926 /// An assignment (`a = foo()`)
927 ExprAssign(P<Expr>, P<Expr>),
928 /// An assignment with an operator
930 /// For example, `a += 1`.
931 ExprAssignOp(BinOp, P<Expr>, P<Expr>),
932 /// Access of a named struct field (`obj.foo`)
933 ExprField(P<Expr>, Spanned<Name>),
934 /// Access of an unnamed field of a struct or tuple-struct
936 /// For example, `foo.0`.
937 ExprTupField(P<Expr>, Spanned<usize>),
938 /// An indexing operation (`foo[2]`)
939 ExprIndex(P<Expr>, P<Expr>),
941 /// Path to a definition, possibly containing lifetime or type parameters.
944 /// A referencing operation (`&a` or `&mut a`)
945 ExprAddrOf(Mutability, P<Expr>),
946 /// A `break`, with an optional label to break
947 ExprBreak(Option<Spanned<Name>>, Option<P<Expr>>),
948 /// A `continue`, with an optional label
949 ExprAgain(Option<Spanned<Name>>),
950 /// A `return`, with an optional value to be returned
951 ExprRet(Option<P<Expr>>),
953 /// Inline assembly (from `asm!`), with its outputs and inputs.
954 ExprInlineAsm(P<InlineAsm>, HirVec<Expr>, HirVec<Expr>),
956 /// A struct or struct-like variant literal expression.
958 /// For example, `Foo {x: 1, y: 2}`, or
959 /// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`.
960 ExprStruct(QPath, HirVec<Field>, Option<P<Expr>>),
962 /// An array literal constructed from one repeated element.
964 /// For example, `[1; 5]`. The first expression is the element
965 /// to be repeated; the second is the number of times to repeat it.
966 ExprRepeat(P<Expr>, P<Expr>),
969 /// Optionally `Self`-qualified value/type path or associated extension.
970 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
972 /// Path to a definition, optionally "fully-qualified" with a `Self`
973 /// type, if the path points to an associated item in a trait.
975 /// E.g. an unqualified path like `Clone::clone` has `None` for `Self`,
976 /// while `<Vec<T> as Clone>::clone` has `Some(Vec<T>)` for `Self`,
977 /// even though they both have the same two-segment `Clone::clone` `Path`.
978 Resolved(Option<P<Ty>>, P<Path>),
980 /// Type-related paths, e.g. `<T>::default` or `<T>::Output`.
981 /// Will be resolved by type-checking to an associated item.
983 /// UFCS source paths can desugar into this, with `Vec::new` turning into
984 /// `<Vec>::new`, and `T::X::Y::method` into `<<<T>::X>::Y>::method`,
985 /// the `X` and `Y` nodes being each a `TyPath(QPath::TypeRelative(..))`.
986 TypeRelative(P<Ty>, P<PathSegment>)
989 impl fmt::Display for QPath {
990 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
991 write!(f, "{}", print::qpath_to_string(self))
995 /// Hints at the original code for a `match _ { .. }`
996 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
997 pub enum MatchSource {
998 /// A `match _ { .. }`
1000 /// An `if let _ = _ { .. }` (optionally with `else { .. }`)
1002 contains_else_clause: bool,
1004 /// A `while let _ = _ { .. }` (which was desugared to a
1005 /// `loop { match _ { .. } }`)
1007 /// A desugared `for _ in _ { .. }` loop
1009 /// A desugared `?` operator
1013 /// The loop type that yielded an ExprLoop
1014 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1015 pub enum LoopSource {
1016 /// A `loop { .. }` loop
1018 /// A `while let _ = _ { .. }` loop
1020 /// A `for _ in _ { .. }` loop
1025 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1026 pub enum CaptureClause {
1031 // NB: If you change this, you'll probably want to change the corresponding
1032 // type structure in middle/ty.rs as well.
1033 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1036 pub mutbl: Mutability,
1039 /// Represents a method's signature in a trait declaration or implementation.
1040 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1041 pub struct MethodSig {
1042 pub unsafety: Unsafety,
1043 pub constness: Constness,
1045 pub decl: P<FnDecl>,
1046 pub generics: Generics,
1049 /// Represents an item declaration within a trait declaration,
1050 /// possibly including a default implementation. A trait item is
1051 /// either required (meaning it doesn't have an implementation, just a
1052 /// signature) or provided (meaning it has a default implementation).
1053 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1054 pub struct TraitItem {
1057 pub attrs: HirVec<Attribute>,
1058 pub node: TraitItem_,
1062 /// Represents a trait method or associated constant or type
1063 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1064 pub enum TraitItem_ {
1065 /// An associated constant with an optional value (otherwise `impl`s
1066 /// must contain a value)
1067 ConstTraitItem(P<Ty>, Option<P<Expr>>),
1068 /// A method with an optional body
1069 MethodTraitItem(MethodSig, Option<P<Expr>>),
1070 /// An associated type with (possibly empty) bounds and optional concrete
1072 TypeTraitItem(TyParamBounds, Option<P<Ty>>),
1075 // The bodies for items are stored "out of line", in a separate
1076 // hashmap in the `Crate`. Here we just record the node-id of the item
1077 // so it can fetched later.
1078 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)]
1079 pub struct ImplItemId {
1080 pub node_id: NodeId,
1083 /// Represents anything within an `impl` block
1084 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1085 pub struct ImplItem {
1088 pub vis: Visibility,
1089 pub defaultness: Defaultness,
1090 pub attrs: HirVec<Attribute>,
1091 pub node: ImplItemKind,
1095 /// Represents different contents within `impl`s
1096 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1097 pub enum ImplItemKind {
1098 /// An associated constant of the given type, set to the constant result
1099 /// of the expression
1100 Const(P<Ty>, P<Expr>),
1101 /// A method implementation with the given signature and body
1102 Method(MethodSig, P<Expr>),
1103 /// An associated type
1107 // Bind a type to an associated type: `A=Foo`.
1108 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1109 pub struct TypeBinding {
1117 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1124 impl fmt::Debug for Ty {
1125 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1126 write!(f, "type({})", print::ty_to_string(self))
1130 /// Not represented directly in the AST, referred to by name through a ty_path.
1131 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1141 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1142 pub struct BareFnTy {
1143 pub unsafety: Unsafety,
1145 pub lifetimes: HirVec<LifetimeDef>,
1146 pub decl: P<FnDecl>,
1149 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1150 /// The different kinds of types recognized by the compiler
1152 /// A variable length slice (`[T]`)
1154 /// A fixed length array (`[T; n]`)
1155 TyArray(P<Ty>, P<Expr>),
1156 /// A raw pointer (`*const T` or `*mut T`)
1158 /// A reference (`&'a T` or `&'a mut T`)
1159 TyRptr(Option<Lifetime>, MutTy),
1160 /// A bare function (e.g. `fn(usize) -> bool`)
1161 TyBareFn(P<BareFnTy>),
1162 /// The never type (`!`)
1164 /// A tuple (`(A, B, C, D,...)`)
1165 TyTup(HirVec<P<Ty>>),
1166 /// A path to a type definition (`module::module::...::Type`), or an
1167 /// associated type, e.g. `<Vec<T> as Trait>::Type` or `<T>::Target`.
1169 /// Type parameters may be stored in each `PathSegment`.
1172 /// Something like `A+B`. Note that `B` must always be a path.
1173 TyObjectSum(P<Ty>, TyParamBounds),
1174 /// A type like `for<'a> Foo<&'a Bar>`
1175 TyPolyTraitRef(TyParamBounds),
1176 /// An `impl TraitA+TraitB` type.
1177 TyImplTrait(TyParamBounds),
1180 /// TyInfer means the type should be inferred instead of it having been
1181 /// specified. This can appear anywhere in a type.
1185 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1186 pub struct InlineAsmOutput {
1187 pub constraint: Symbol,
1189 pub is_indirect: bool,
1192 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1193 pub struct InlineAsm {
1195 pub asm_str_style: StrStyle,
1196 pub outputs: HirVec<InlineAsmOutput>,
1197 pub inputs: HirVec<Symbol>,
1198 pub clobbers: HirVec<Symbol>,
1200 pub alignstack: bool,
1201 pub dialect: AsmDialect,
1202 pub expn_id: ExpnId,
1205 /// represents an argument in a function header
1206 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1213 /// Alternative representation for `Arg`s describing `self` parameter of methods.
1214 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1216 /// `self`, `mut self`
1218 /// `&'lt self`, `&'lt mut self`
1219 Region(Option<Lifetime>, Mutability),
1220 /// `self: TYPE`, `mut self: TYPE`
1221 Explicit(P<Ty>, Mutability),
1224 pub type ExplicitSelf = Spanned<SelfKind>;
1227 pub fn to_self(&self) -> Option<ExplicitSelf> {
1228 if let PatKind::Binding(BindByValue(mutbl), name, _) = self.pat.node {
1229 if name.node == keywords::SelfValue.name() {
1230 return match self.ty.node {
1231 TyInfer => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
1232 TyRptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyInfer => {
1233 Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
1235 _ => Some(respan(mk_sp(self.pat.span.lo, self.ty.span.hi),
1236 SelfKind::Explicit(self.ty.clone(), mutbl)))
1243 pub fn is_self(&self) -> bool {
1244 if let PatKind::Binding(_, name, _) = self.pat.node {
1245 name.node == keywords::SelfValue.name()
1252 /// Represents the header (not the body) of a function declaration
1253 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1255 pub inputs: HirVec<Arg>,
1256 pub output: FunctionRetTy,
1261 pub fn get_self(&self) -> Option<ExplicitSelf> {
1262 self.inputs.get(0).and_then(Arg::to_self)
1264 pub fn has_self(&self) -> bool {
1265 self.inputs.get(0).map(Arg::is_self).unwrap_or(false)
1269 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1275 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1276 pub enum Constness {
1281 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1282 pub enum Defaultness {
1283 Default { has_value: bool },
1288 pub fn has_value(&self) -> bool {
1290 Defaultness::Default { has_value, .. } => has_value,
1291 Defaultness::Final => true,
1295 pub fn is_final(&self) -> bool {
1296 *self == Defaultness::Final
1299 pub fn is_default(&self) -> bool {
1301 Defaultness::Default { .. } => true,
1307 impl fmt::Display for Unsafety {
1308 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1309 fmt::Display::fmt(match *self {
1310 Unsafety::Normal => "normal",
1311 Unsafety::Unsafe => "unsafe",
1317 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
1318 pub enum ImplPolarity {
1319 /// `impl Trait for Type`
1321 /// `impl !Trait for Type`
1325 impl fmt::Debug for ImplPolarity {
1326 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1328 ImplPolarity::Positive => "positive".fmt(f),
1329 ImplPolarity::Negative => "negative".fmt(f),
1335 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1336 pub enum FunctionRetTy {
1337 /// Return type is not specified.
1339 /// Functions default to `()` and
1340 /// closures default to inference. Span points to where return
1341 /// type would be inserted.
1342 DefaultReturn(Span),
1347 impl FunctionRetTy {
1348 pub fn span(&self) -> Span {
1350 DefaultReturn(span) => span,
1351 Return(ref ty) => ty.span,
1356 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1358 /// A span from the first token past `{` to the last token until `}`.
1359 /// For `mod foo;`, the inner span ranges from the first token
1360 /// to the last token in the external file.
1362 pub item_ids: HirVec<ItemId>,
1365 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1366 pub struct ForeignMod {
1368 pub items: HirVec<ForeignItem>,
1371 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1372 pub struct EnumDef {
1373 pub variants: HirVec<Variant>,
1376 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1377 pub struct Variant_ {
1379 pub attrs: HirVec<Attribute>,
1380 pub data: VariantData,
1381 /// Explicit discriminant, eg `Foo = 1`
1382 pub disr_expr: Option<P<Expr>>,
1385 pub type Variant = Spanned<Variant_>;
1387 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1389 /// One import, e.g. `use foo::bar` or `use foo::bar as baz`.
1390 /// Also produced for each element of a list `use`, e.g.
1391 // `use foo::{a, b}` lowers to `use foo::a; use foo::b;`.
1394 /// Glob import, e.g. `use foo::*`.
1397 /// Degenerate list import, e.g. `use foo::{a, b}` produces
1398 /// an additional `use foo::{}` for performing checks such as
1399 /// unstable feature gating. May be removed in the future.
1403 /// TraitRef's appear in impls.
1405 /// resolve maps each TraitRef's ref_id to its defining trait; that's all
1406 /// that the ref_id is for. Note that ref_id's value is not the NodeId of the
1407 /// trait being referred to but just a unique NodeId that serves as a key
1408 /// within the DefMap.
1409 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1410 pub struct TraitRef {
1415 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1416 pub struct PolyTraitRef {
1417 /// The `'a` in `<'a> Foo<&'a T>`
1418 pub bound_lifetimes: HirVec<LifetimeDef>,
1420 /// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
1421 pub trait_ref: TraitRef,
1426 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1427 pub enum Visibility {
1430 Restricted { path: P<Path>, id: NodeId },
1434 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1435 pub struct StructField {
1438 pub vis: Visibility,
1441 pub attrs: HirVec<Attribute>,
1445 // Still necessary in couple of places
1446 pub fn is_positional(&self) -> bool {
1447 let first = self.name.as_str().as_bytes()[0];
1448 first >= b'0' && first <= b'9'
1452 /// Fields and Ids of enum variants and structs
1454 /// For enum variants: `NodeId` represents both an Id of the variant itself (relevant for all
1455 /// variant kinds) and an Id of the variant's constructor (not relevant for `Struct`-variants).
1456 /// One shared Id can be successfully used for these two purposes.
1457 /// Id of the whole enum lives in `Item`.
1459 /// For structs: `NodeId` represents an Id of the structure's constructor, so it is not actually
1460 /// used for `Struct`-structs (but still presents). Structures don't have an analogue of "Id of
1461 /// the variant itself" from enum variants.
1462 /// Id of the whole struct lives in `Item`.
1463 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1464 pub enum VariantData {
1465 Struct(HirVec<StructField>, NodeId),
1466 Tuple(HirVec<StructField>, NodeId),
1471 pub fn fields(&self) -> &[StructField] {
1473 VariantData::Struct(ref fields, _) | VariantData::Tuple(ref fields, _) => fields,
1477 pub fn id(&self) -> NodeId {
1479 VariantData::Struct(_, id) | VariantData::Tuple(_, id) | VariantData::Unit(id) => id,
1482 pub fn is_struct(&self) -> bool {
1483 if let VariantData::Struct(..) = *self {
1489 pub fn is_tuple(&self) -> bool {
1490 if let VariantData::Tuple(..) = *self {
1496 pub fn is_unit(&self) -> bool {
1497 if let VariantData::Unit(..) = *self {
1505 // The bodies for items are stored "out of line", in a separate
1506 // hashmap in the `Crate`. Here we just record the node-id of the item
1507 // so it can fetched later.
1508 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1513 // FIXME (#3300): Should allow items to be anonymous. Right now
1514 // we just use dummy names for anon items.
1517 /// The name might be a dummy name in case of anonymous items
1518 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1521 pub attrs: HirVec<Attribute>,
1524 pub vis: Visibility,
1528 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1530 /// An`extern crate` item, with optional original crate name,
1532 /// e.g. `extern crate foo` or `extern crate foo_bar as foo`
1533 ItemExternCrate(Option<Name>),
1535 /// `use foo::bar::*;` or `use foo::bar::baz as quux;`
1539 /// `use foo::bar::baz;` (with `as baz` implicitly on the right)
1540 ItemUse(P<Path>, UseKind),
1543 ItemStatic(P<Ty>, Mutability, P<Expr>),
1545 ItemConst(P<Ty>, P<Expr>),
1546 /// A function declaration
1547 ItemFn(P<FnDecl>, Unsafety, Constness, Abi, Generics, P<Expr>),
1550 /// An external module
1551 ItemForeignMod(ForeignMod),
1552 /// A type alias, e.g. `type Foo = Bar<u8>`
1553 ItemTy(P<Ty>, Generics),
1554 /// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
1555 ItemEnum(EnumDef, Generics),
1556 /// A struct definition, e.g. `struct Foo<A> {x: A}`
1557 ItemStruct(VariantData, Generics),
1558 /// A union definition, e.g. `union Foo<A, B> {x: A, y: B}`
1559 ItemUnion(VariantData, Generics),
1560 /// Represents a Trait Declaration
1561 ItemTrait(Unsafety, Generics, TyParamBounds, HirVec<TraitItem>),
1563 // Default trait implementations
1565 /// `impl Trait for .. {}`
1566 ItemDefaultImpl(Unsafety, TraitRef),
1567 /// An implementation, eg `impl<A> Trait for Foo { .. }`
1571 Option<TraitRef>, // (optional) trait this impl implements
1573 HirVec<ImplItemRef>),
1577 pub fn descriptive_variant(&self) -> &str {
1579 ItemExternCrate(..) => "extern crate",
1580 ItemUse(..) => "use",
1581 ItemStatic(..) => "static item",
1582 ItemConst(..) => "constant item",
1583 ItemFn(..) => "function",
1584 ItemMod(..) => "module",
1585 ItemForeignMod(..) => "foreign module",
1586 ItemTy(..) => "type alias",
1587 ItemEnum(..) => "enum",
1588 ItemStruct(..) => "struct",
1589 ItemUnion(..) => "union",
1590 ItemTrait(..) => "trait",
1592 ItemDefaultImpl(..) => "item",
1597 /// A reference from an impl to one of its associated items. This
1598 /// contains the item's id, naturally, but also the item's name and
1599 /// some other high-level details (like whether it is an associated
1600 /// type or method, and whether it is public). This allows other
1601 /// passes to find the impl they want without loading the id (which
1602 /// means fewer edges in the incremental compilation graph).
1603 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1604 pub struct ImplItemRef {
1607 pub kind: AssociatedItemKind,
1609 pub vis: Visibility,
1610 pub defaultness: Defaultness,
1613 #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1614 pub enum AssociatedItemKind {
1616 Method { has_self: bool },
1620 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1621 pub struct ForeignItem {
1623 pub attrs: HirVec<Attribute>,
1624 pub node: ForeignItem_,
1627 pub vis: Visibility,
1630 /// An item within an `extern` block
1631 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1632 pub enum ForeignItem_ {
1633 /// A foreign function
1634 ForeignItemFn(P<FnDecl>, Generics),
1635 /// A foreign static item (`static ext: u8`), with optional mutability
1636 /// (the boolean is true when mutable)
1637 ForeignItemStatic(P<Ty>, bool),
1641 pub fn descriptive_variant(&self) -> &str {
1643 ForeignItemFn(..) => "foreign function",
1644 ForeignItemStatic(..) => "foreign static item",
1649 /// A free variable referred to in a function.
1650 #[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
1651 pub struct Freevar {
1652 /// The variable being accessed free.
1655 // First span where it is accessed (there can be multiple).
1659 pub type FreevarMap = NodeMap<Vec<Freevar>>;
1661 pub type CaptureModeMap = NodeMap<CaptureClause>;
1663 #[derive(Clone, Debug)]
1664 pub struct TraitCandidate {
1666 pub import_id: Option<NodeId>,
1669 // Trait method resolution
1670 pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
1672 // Map from the NodeId of a glob import to a list of items which are actually
1674 pub type GlobMap = NodeMap<FxHashSet<Name>>;