1 // Copyright 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 use middle::subst::ParamSpace;
13 use syntax::ast_util::local_def;
17 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
19 DefFn(ast::DefId, ast::FnStyle),
20 DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
21 DefSelfTy(/* trait id */ ast::NodeId),
23 DefForeignMod(ast::DefId),
24 DefStatic(ast::DefId, bool /* is_mutbl */),
25 DefArg(ast::NodeId, ast::BindingMode),
26 DefLocal(ast::NodeId, ast::BindingMode),
27 DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
28 DefTy(ast::DefId, bool /* is_enum */),
30 DefPrimTy(ast::PrimTy),
31 DefTyParam(ParamSpace, ast::DefId, uint),
32 DefBinding(ast::NodeId, ast::BindingMode),
34 DefUpvar(ast::NodeId, // id of closed over var
35 Gc<Def>, // closed over def
36 ast::NodeId, // expr node that creates the closure
37 ast::NodeId), // id for the block/body of the closure expr
39 /// Note that if it's a tuple struct's definition, the node id of the ast::DefId
40 /// may either refer to the item definition's id or the StructDef.ctor_id.
42 /// The cases that I have encountered so far are (this is not exhaustive):
43 /// - If it's a ty_path referring to some tuple struct, then DefMap maps
44 /// it to a def whose id is the item definition's id.
45 /// - If it's an ExprPath referring to some tuple struct, then DefMap maps
46 /// it to a def whose id is the StructDef.ctor_id.
47 DefStruct(ast::DefId),
48 DefTyParamBinder(ast::NodeId), /* struct, impl or trait with ty params */
49 DefRegion(ast::NodeId),
50 DefLabel(ast::NodeId),
51 DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */),
54 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
55 pub enum MethodProvenance {
56 FromTrait(ast::DefId),
61 pub fn def_id(&self) -> ast::DefId {
63 DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) |
64 DefForeignMod(id) | DefStatic(id, _) |
65 DefVariant(_, id, _) | DefTy(id, _) | DefTyParam(_, id, _) |
66 DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => {
72 DefUpvar(id, _, _, _) |
75 DefTyParamBinder(id) |
80 DefPrimTy(_) => fail!()
84 pub fn variant_def_ids(&self) -> Option<(ast::DefId, ast::DefId)> {
86 DefVariant(enum_id, var_id, _) => {
87 Some((enum_id, var_id))