]> git.lizzy.rs Git - rust.git/commitdiff
Move Def out of syntax crate, where it does not belong
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 14 May 2014 19:31:30 +0000 (15:31 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Fri, 6 Jun 2014 23:51:23 +0000 (19:51 -0400)
47 files changed:
src/librustc/lib.rs
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/astencode.rs
src/librustc/middle/borrowck/mod.rs
src/librustc/middle/cfg/construct.rs
src/librustc/middle/check_const.rs
src/librustc/middle/check_match.rs
src/librustc/middle/const_eval.rs
src/librustc/middle/dataflow.rs
src/librustc/middle/dead.rs
src/librustc/middle/def.rs [new file with mode: 0644]
src/librustc/middle/effect.rs
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/freevars.rs
src/librustc/middle/kind.rs
src/librustc/middle/lint.rs
src/librustc/middle/liveness.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/pat_util.rs
src/librustc/middle/privacy.rs
src/librustc/middle/reachable.rs
src/librustc/middle/resolve.rs
src/librustc/middle/subst.rs
src/librustc/middle/trans/_match.rs
src/librustc/middle/trans/callee.rs
src/librustc/middle/trans/closure.rs
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/consts.rs
src/librustc/middle/trans/controlflow.rs
src/librustc/middle/trans/expr.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/_match.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/regionck.rs
src/librustc/middle/typeck/check/vtable.rs
src/librustc/middle/typeck/check/writeback.rs
src/librustc/middle/typeck/coherence.rs
src/librustc/middle/typeck/collect.rs
src/librustc/middle/typeck/infer/error_reporting.rs
src/librustc/middle/typeck/mod.rs
src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/visit_ast.rs
src/libsyntax/ast.rs
src/libsyntax/ast_util.rs

index 17e659e53912f7e13a66ce9b1eead8272a4eb281..1b17cfb1bae01dd8b038ea644fb8a82812330e1c 100644 (file)
@@ -46,6 +46,7 @@
 extern crate log;
 
 pub mod middle {
+    pub mod def;
     pub mod trans;
     pub mod ty;
     pub mod ty_fold;
index 30b40369c105aae70f8a4624c8ddf2847510c453..6469462734e553190560e6e43937c9b3185f8434 100644 (file)
@@ -22,6 +22,7 @@
                          parse_type_param_def_data,
                          parse_bare_fn_ty_data, parse_trait_ref_data};
 use middle::lang_items;
+use middle::def;
 use middle::ty::{ImplContainer, TraitContainer};
 use middle::ty;
 use middle::typeck;
@@ -333,11 +334,11 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
     -> DefLike {
     let fam = item_family(item);
     match fam {
-        ImmStatic => DlDef(ast::DefStatic(did, false)),
-        MutStatic => DlDef(ast::DefStatic(did, true)),
-        Struct    => DlDef(ast::DefStruct(did)),
-        UnsafeFn  => DlDef(ast::DefFn(did, ast::UnsafeFn)),
-        Fn        => DlDef(ast::DefFn(did, ast::NormalFn)),
+        ImmStatic => DlDef(def::DefStatic(did, false)),
+        MutStatic => DlDef(def::DefStatic(did, true)),
+        Struct    => DlDef(def::DefStruct(did)),
+        UnsafeFn  => DlDef(def::DefFn(did, ast::UnsafeFn)),
+        Fn        => DlDef(def::DefFn(did, ast::NormalFn)),
         StaticMethod | UnsafeStaticMethod => {
             let fn_style = if fam == UnsafeStaticMethod { ast::UnsafeFn } else
                 { ast::NormalFn };
@@ -348,27 +349,27 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
             // a trait_method_sort.
             let provenance = if reader::maybe_get_doc(
                   item, tag_item_trait_method_sort).is_some() {
-                ast::FromTrait(item_reqd_and_translated_parent_item(cnum,
+                def::FromTrait(item_reqd_and_translated_parent_item(cnum,
                                                                     item))
             } else {
-                ast::FromImpl(item_reqd_and_translated_parent_item(cnum,
+                def::FromImpl(item_reqd_and_translated_parent_item(cnum,
                                                                    item))
             };
-            DlDef(ast::DefStaticMethod(did, provenance, fn_style))
+            DlDef(def::DefStaticMethod(did, provenance, fn_style))
         }
-        Type | ForeignType => DlDef(ast::DefTy(did)),
-        Mod => DlDef(ast::DefMod(did)),
-        ForeignMod => DlDef(ast::DefForeignMod(did)),
+        Type | ForeignType => DlDef(def::DefTy(did)),
+        Mod => DlDef(def::DefMod(did)),
+        ForeignMod => DlDef(def::DefForeignMod(did)),
         StructVariant => {
             let enum_did = item_reqd_and_translated_parent_item(cnum, item);
-            DlDef(ast::DefVariant(enum_did, did, true))
+            DlDef(def::DefVariant(enum_did, did, true))
         }
         TupleVariant => {
             let enum_did = item_reqd_and_translated_parent_item(cnum, item);
-            DlDef(ast::DefVariant(enum_did, did, false))
+            DlDef(def::DefVariant(enum_did, did, false))
         }
-        Trait => DlDef(ast::DefTrait(did)),
-        Enum => DlDef(ast::DefTy(did)),
+        Trait => DlDef(def::DefTrait(did)),
+        Enum => DlDef(def::DefTy(did)),
         Impl => DlImpl(did),
         PublicField | InheritedField => DlField,
     }
@@ -459,7 +460,7 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
 // Something that a name can resolve to.
 #[deriving(Clone)]
 pub enum DefLike {
-    DlDef(ast::Def),
+    DlDef(def::Def),
     DlImpl(ast::DefId),
     DlField
 }
index 61dfde38c28a4514686a70a2c12b9cf8a60b7299..2cc06f7a32dde70ab2a39971709739dcfab26778 100644 (file)
@@ -1631,7 +1631,7 @@ fn visit_item(&mut self, item: &Item, _: ()) {
             ItemImpl(_, Some(ref trait_ref), _, _) => {
                 let def_map = &self.ecx.tcx.def_map;
                 let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
-                let def_id = ast_util::def_id_of_def(trait_def);
+                let def_id = trait_def.def_id();
 
                 // Load eagerly if this is an implementation of the Drop trait
                 // or if the trait is not defined in this crate.
index 9706ca578f78dcb5a0b8b5ddf33ff1a9cbc64b29..f0caf0e7fe83248c403e6fa2eea54335b203ad82 100644 (file)
@@ -16,6 +16,7 @@
 use cstore = metadata::cstore;
 use driver::session::Session;
 use metadata::decoder;
+use middle::def;
 use e = metadata::encoder;
 use middle::freevars::freevar_entry;
 use middle::region;
@@ -395,58 +396,58 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
 // ______________________________________________________________________
 // Encoding and decoding of ast::def
 
-fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> ast::Def {
+fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> def::Def {
     let mut dsr = reader::Decoder::new(doc);
-    let def: ast::Def = Decodable::decode(&mut dsr).unwrap();
+    let def: def::Def = Decodable::decode(&mut dsr).unwrap();
     def.tr(xcx)
 }
 
-impl tr for ast::Def {
-    fn tr(&self, xcx: &ExtendedDecodeContext) -> ast::Def {
+impl tr for def::Def {
+    fn tr(&self, xcx: &ExtendedDecodeContext) -> def::Def {
         match *self {
-          ast::DefFn(did, p) => ast::DefFn(did.tr(xcx), p),
-          ast::DefStaticMethod(did, wrapped_did2, p) => {
-            ast::DefStaticMethod(did.tr(xcx),
+          def::DefFn(did, p) => def::DefFn(did.tr(xcx), p),
+          def::DefStaticMethod(did, wrapped_did2, p) => {
+            def::DefStaticMethod(did.tr(xcx),
                                    match wrapped_did2 {
-                                    ast::FromTrait(did2) => {
-                                        ast::FromTrait(did2.tr(xcx))
+                                    def::FromTrait(did2) => {
+                                        def::FromTrait(did2.tr(xcx))
                                     }
-                                    ast::FromImpl(did2) => {
-                                        ast::FromImpl(did2.tr(xcx))
+                                    def::FromImpl(did2) => {
+                                        def::FromImpl(did2.tr(xcx))
                                     }
                                    },
                                    p)
           }
-          ast::DefMethod(did0, did1) => {
-            ast::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
+          def::DefMethod(did0, did1) => {
+            def::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
           }
-          ast::DefSelfTy(nid) => { ast::DefSelfTy(xcx.tr_id(nid)) }
-          ast::DefMod(did) => { ast::DefMod(did.tr(xcx)) }
-          ast::DefForeignMod(did) => { ast::DefForeignMod(did.tr(xcx)) }
-          ast::DefStatic(did, m) => { ast::DefStatic(did.tr(xcx), m) }
-          ast::DefArg(nid, b) => { ast::DefArg(xcx.tr_id(nid), b) }
-          ast::DefLocal(nid, b) => { ast::DefLocal(xcx.tr_id(nid), b) }
-          ast::DefVariant(e_did, v_did, is_s) => {
-            ast::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
+          def::DefSelfTy(nid) => { def::DefSelfTy(xcx.tr_id(nid)) }
+          def::DefMod(did) => { def::DefMod(did.tr(xcx)) }
+          def::DefForeignMod(did) => { def::DefForeignMod(did.tr(xcx)) }
+          def::DefStatic(did, m) => { def::DefStatic(did.tr(xcx), m) }
+          def::DefArg(nid, b) => { def::DefArg(xcx.tr_id(nid), b) }
+          def::DefLocal(nid, b) => { def::DefLocal(xcx.tr_id(nid), b) }
+          def::DefVariant(e_did, v_did, is_s) => {
+            def::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
           },
-          ast::DefTrait(did) => ast::DefTrait(did.tr(xcx)),
-          ast::DefTy(did) => ast::DefTy(did.tr(xcx)),
-          ast::DefPrimTy(p) => ast::DefPrimTy(p),
-          ast::DefTyParam(did, v) => ast::DefTyParam(did.tr(xcx), v),
-          ast::DefBinding(nid, bm) => ast::DefBinding(xcx.tr_id(nid), bm),
-          ast::DefUse(did) => ast::DefUse(did.tr(xcx)),
-          ast::DefUpvar(nid1, def, nid2, nid3) => {
-            ast::DefUpvar(xcx.tr_id(nid1),
+          def::DefTrait(did) => def::DefTrait(did.tr(xcx)),
+          def::DefTy(did) => def::DefTy(did.tr(xcx)),
+          def::DefPrimTy(p) => def::DefPrimTy(p),
+          def::DefTyParam(did, v) => def::DefTyParam(did.tr(xcx), v),
+          def::DefBinding(nid, bm) => def::DefBinding(xcx.tr_id(nid), bm),
+          def::DefUse(did) => def::DefUse(did.tr(xcx)),
+          def::DefUpvar(nid1, def, nid2, nid3) => {
+            def::DefUpvar(xcx.tr_id(nid1),
                            @(*def).tr(xcx),
                            xcx.tr_id(nid2),
                            xcx.tr_id(nid3))
           }
-          ast::DefStruct(did) => ast::DefStruct(did.tr(xcx)),
-          ast::DefRegion(nid) => ast::DefRegion(xcx.tr_id(nid)),
-          ast::DefTyParamBinder(nid) => {
-            ast::DefTyParamBinder(xcx.tr_id(nid))
+          def::DefStruct(did) => def::DefStruct(did.tr(xcx)),
+          def::DefRegion(nid) => def::DefRegion(xcx.tr_id(nid)),
+          def::DefTyParamBinder(nid) => {
+            def::DefTyParamBinder(xcx.tr_id(nid))
           }
-          ast::DefLabel(nid) => ast::DefLabel(xcx.tr_id(nid))
+          def::DefLabel(nid) => def::DefLabel(xcx.tr_id(nid))
         }
     }
 }
index 0fbcf157dacad562721144b91a3680cb448fce46..5706d249c46dabd98f12e670462b468dff96c1f1 100644 (file)
@@ -14,6 +14,7 @@
 
 use middle::dataflow::DataFlowContext;
 use middle::dataflow::DataFlowOperator;
+use middle::def;
 use euv = middle::expr_use_visitor;
 use mc = middle::mem_categorization;
 use middle::ty;
@@ -399,7 +400,7 @@ pub fn cat_def(&self,
                    id: ast::NodeId,
                    span: Span,
                    ty: ty::t,
-                   def: ast::Def)
+                   def: def::Def)
                    -> mc::cmt {
         match self.mc().cat_def(id, span, ty, def) {
             Ok(c) => c,
@@ -412,11 +413,11 @@ pub fn cat_def(&self,
     pub fn cat_captured_var(&self,
                             closure_id: ast::NodeId,
                             closure_span: Span,
-                            upvar_def: ast::Def)
+                            upvar_def: def::Def)
                             -> mc::cmt {
         // Create the cmt for the variable being borrowed, from the
         // caller's perspective
-        let var_id = ast_util::def_id_of_def(upvar_def).node;
+        let var_id = upvar_def.def_id().node;
         let var_ty = ty::node_id_to_type(self.tcx, var_id);
         self.cat_def(closure_id, closure_span, var_ty, upvar_def)
     }
index e2b4dde577a060486eede62ed5302964382deb0f..4a36e84fbe56e0663ca28d9a7bb0de1aed3736ce 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 use middle::cfg::*;
+use middle::def;
 use middle::graph;
 use middle::typeck;
 use middle::ty;
@@ -531,7 +532,7 @@ fn find_scope(&self,
 
             Some(_) => {
                 match self.tcx.def_map.borrow().find(&expr.id) {
-                    Some(&ast::DefLabel(loop_id)) => {
+                    Some(&def::DefLabel(loop_id)) => {
                         for l in self.loop_scopes.iter() {
                             if l.loop_id == loop_id {
                                 return *l;
index 64b7977c2351ed71430661b6bba57804e70df3da..2bb7d0bc5c8d471a3b8e9b58026d42ea251cb5f4 100644 (file)
@@ -10,6 +10,7 @@
 
 
 use driver::session::Session;
+use middle::def::*;
 use middle::resolve;
 use middle::ty;
 use middle::typeck;
index 26bc845a15aa97b9f5dcad1c5e94db64760b6362..39a35e3adfab62ca899cb2a7adbb986657164c01 100644 (file)
@@ -12,6 +12,7 @@
 
 use middle::const_eval::{compare_const_vals, lookup_const_by_id};
 use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float};
+use middle::def::*;
 use middle::pat_util::*;
 use middle::ty::*;
 use middle::ty;
index e7ad08d4eb2a5c4c7e7d2a894187a3e18dad55d6..ca94cf2485038a93f5bd16269692108748334d8b 100644 (file)
@@ -14,6 +14,7 @@
 use metadata::csearch;
 use middle::astencode;
 
+use middle::def;
 use middle::ty;
 use middle::typeck::astconv;
 use util::nodemap::{DefIdMap};
@@ -83,10 +84,10 @@ pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
 pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<@Expr> {
     let opt_def = tcx.def_map.borrow().find_copy(&e.id);
     match opt_def {
-        Some(ast::DefStatic(def_id, false)) => {
+        Some(def::DefStatic(def_id, false)) => {
             lookup_const_by_id(tcx, def_id)
         }
-        Some(ast::DefVariant(enum_def, variant_def, _)) => {
+        Some(def::DefVariant(enum_def, variant_def, _)) => {
             lookup_variant_by_id(tcx, enum_def, variant_def)
         }
         _ => None
index 30792da84e05308919180b5dd321a4babcd7e609..3eec3c7e8811aa5a34e7f60f1d2914ddc68c038d 100644 (file)
@@ -17,6 +17,9 @@
  */
 
 
+use middle::def;
+use middle::ty;
+use middle::typeck;
 use std::io;
 use std::string::String;
 use std::uint;
@@ -24,8 +27,6 @@
 use syntax::ast_util;
 use syntax::ast_util::IdRange;
 use syntax::print::{pp, pprust};
-use middle::ty;
-use middle::typeck;
 use util::ppaux::Repr;
 use util::nodemap::NodeMap;
 
@@ -757,7 +758,7 @@ fn find_scope<'a,'b>(
 
             Some(_) => {
                 match self.tcx().def_map.borrow().find(&expr.id) {
-                    Some(&ast::DefLabel(loop_id)) => {
+                    Some(&def::DefLabel(loop_id)) => {
                         match loop_scopes.iter().position(|l| l.loop_id == loop_id) {
                             Some(i) => i,
                             None => {
index d3d5eb3f8fd8299fcc8c49c8a8599583849c9315..fb19fbd70c69e117c0159c6454bbc6bcc956b179 100644 (file)
@@ -12,6 +12,7 @@
 // closely. The idea is that all reachable symbols are live, codes called
 // from live codes are live, and everything else is dead.
 
+use middle::def;
 use middle::lint::{Allow, contains_lint, DeadCode};
 use middle::privacy;
 use middle::ty;
@@ -21,7 +22,7 @@
 use std::collections::HashSet;
 use syntax::ast;
 use syntax::ast_map;
-use syntax::ast_util::{local_def, def_id_of_def, is_local};
+use syntax::ast_util::{local_def, is_local};
 use syntax::attr;
 use syntax::codemap;
 use syntax::parse::token;
@@ -77,9 +78,9 @@ fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
             None => return
         };
         let def_id = match def {
-            ast::DefVariant(enum_id, _, _) => Some(enum_id),
-            ast::DefPrimTy(_) => None,
-            _ => Some(def_id_of_def(def)),
+            def::DefVariant(enum_id, _, _) => Some(enum_id),
+            def::DefPrimTy(_) => None,
+            _ => Some(def.def_id())
         };
         match def_id {
             Some(def_id) => self.check_def_id(def_id),
diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs
new file mode 100644 (file)
index 0000000..ca89439
--- /dev/null
@@ -0,0 +1,89 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use syntax::ast;
+use syntax::ast_util::local_def;
+
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+pub enum Def {
+    DefFn(ast::DefId, ast::FnStyle),
+    DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
+    DefSelfTy(/* trait id */ ast::NodeId),
+    DefMod(ast::DefId),
+    DefForeignMod(ast::DefId),
+    DefStatic(ast::DefId, bool /* is_mutbl */),
+    DefArg(ast::NodeId, ast::BindingMode),
+    DefLocal(ast::NodeId, ast::BindingMode),
+    DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
+    DefTy(ast::DefId),
+    DefTrait(ast::DefId),
+    DefPrimTy(ast::PrimTy),
+    DefTyParam(ast::DefId, uint),
+    DefBinding(ast::NodeId, ast::BindingMode),
+    DefUse(ast::DefId),
+    DefUpvar(ast::NodeId,  // id of closed over var
+             @Def,     // closed over def
+             ast::NodeId,  // expr node that creates the closure
+             ast::NodeId), // id for the block/body of the closure expr
+
+    /// Note that if it's a tuple struct's definition, the node id of the ast::DefId
+    /// may either refer to the item definition's id or the StructDef.ctor_id.
+    ///
+    /// The cases that I have encountered so far are (this is not exhaustive):
+    /// - If it's a ty_path referring to some tuple struct, then DefMap maps
+    ///   it to a def whose id is the item definition's id.
+    /// - If it's an ExprPath referring to some tuple struct, then DefMap maps
+    ///   it to a def whose id is the StructDef.ctor_id.
+    DefStruct(ast::DefId),
+    DefTyParamBinder(ast::NodeId), /* struct, impl or trait with ty params */
+    DefRegion(ast::NodeId),
+    DefLabel(ast::NodeId),
+    DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */),
+}
+
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+pub enum MethodProvenance {
+    FromTrait(ast::DefId),
+    FromImpl(ast::DefId),
+}
+
+impl Def {
+    pub fn def_id(&self) -> ast::DefId {
+        match *self {
+            DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) |
+            DefForeignMod(id) | DefStatic(id, _) |
+            DefVariant(_, id, _) | DefTy(id) | DefTyParam(id, _) |
+            DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => {
+                id
+            }
+            DefArg(id, _) |
+            DefLocal(id, _) |
+            DefSelfTy(id) |
+            DefUpvar(id, _, _, _) |
+            DefBinding(id, _) |
+            DefRegion(id) |
+            DefTyParamBinder(id) |
+            DefLabel(id) => {
+                local_def(id)
+            }
+
+            DefPrimTy(_) => fail!()
+        }
+    }
+
+    pub fn variant_def_ids(&self) -> Option<(ast::DefId, ast::DefId)> {
+        match *self {
+            DefVariant(enum_id, var_id, _) => {
+                Some((enum_id, var_id))
+            }
+            _ => None
+        }
+    }
+}
index bc9a1c9b5fc653934b3daeea5c41ae81b93312cb..c75d793cba637c355d2bfa5c243f90da1974536a 100644 (file)
@@ -11,6 +11,7 @@
 //! Enforces the Rust effect system. Currently there is just one effect,
 /// `unsafe`.
 
+use middle::def;
 use middle::ty;
 use middle::typeck::MethodCall;
 use util::ppaux;
@@ -183,7 +184,7 @@ fn visit_expr(&mut self, expr: &ast::Expr, _:()) {
             }
             ast::ExprPath(..) => {
                 match ty::resolve_expr(self.tcx, expr) {
-                    ast::DefStatic(_, true) => {
+                    def::DefStatic(_, true) => {
                         self.require_unsafe(expr.span, "use of mutable static")
                     }
                     _ => {}
index cd71d95bee9481f5744f1f604397a1f4ecc7c839..c44ea0ae78b10a9765fbc466a8a1b70672f041ce 100644 (file)
  */
 
 use mc = middle::mem_categorization;
+use middle::def;
 use middle::freevars;
 use middle::pat_util;
 use middle::ty;
 use middle::typeck;
 use syntax::ast;
-use syntax::ast_util;
 use syntax::codemap::{Span};
 use util::ppaux::Repr;
 
@@ -814,7 +814,7 @@ fn walk_by_ref_captures(&mut self,
                             closure_expr: &ast::Expr,
                             freevars: &[freevars::freevar_entry]) {
         for freevar in freevars.iter() {
-            let id_var = ast_util::def_id_of_def(freevar.def).node;
+            let id_var = freevar.def.def_id().node;
             let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
                                                                closure_expr.span,
                                                                freevar.def));
@@ -850,11 +850,11 @@ fn walk_by_value_captures(&mut self,
     fn cat_captured_var(&mut self,
                         closure_id: ast::NodeId,
                         closure_span: Span,
-                        upvar_def: ast::Def)
+                        upvar_def: def::Def)
                         -> mc::McResult<mc::cmt> {
         // Create the cmt for the variable being borrowed, from the
         // caller's perspective
-        let var_id = ast_util::def_id_of_def(upvar_def).node;
+        let var_id = upvar_def.def_id().node;
         let var_ty = ty::node_id_to_type(self.tcx(), var_id);
         self.mc.cat_def(closure_id, closure_span, var_ty, upvar_def)
     }
index 47523f4f750c11bf59308cc67e7c00fcb32069ef..614972f3d5776dbd3ed6349b0ff690f66e9be3a9 100644 (file)
 
 #![allow(non_camel_case_types)]
 
+use middle::def;
 use middle::resolve;
 use middle::ty;
 use util::nodemap::{NodeMap, NodeSet};
 
 use syntax::codemap::Span;
-use syntax::{ast, ast_util};
+use syntax::{ast};
 use syntax::visit;
 use syntax::visit::Visitor;
 
@@ -35,7 +36,7 @@ pub enum CaptureMode {
 // (The def_upvar will already have been stripped).
 #[deriving(Encodable, Decodable)]
 pub struct freevar_entry {
-    pub def: ast::Def, //< The variable being accessed free.
+    pub def: def::Def, //< The variable being accessed free.
     pub span: Span     //< First span where it is accessed (there can be multiple)
 }
 pub type freevar_map = NodeMap<Vec<freevar_entry>>;
@@ -64,13 +65,13 @@ fn visit_expr(&mut self, expr: &ast::Expr, depth: int) {
                         let mut def = df;
                         while i < depth {
                             match def {
-                                ast::DefUpvar(_, inner, _, _) => { def = *inner; }
+                                def::DefUpvar(_, inner, _, _) => { def = *inner; }
                                 _ => break
                             }
                             i += 1;
                         }
                         if i == depth { // Made it to end of loop
-                            let dnum = ast_util::def_id_of_def(def).node;
+                            let dnum = def.def_id().node;
                             if !self.seen.contains(&dnum) {
                                 self.refs.push(freevar_entry {
                                     def: def,
index fe57e54c77875db65e34b330b26daf71483f38fe..39f2e8425833c1e065c6a84cd479914638c29b2a 100644 (file)
@@ -21,7 +21,7 @@
 use syntax::attr;
 use syntax::codemap::Span;
 use syntax::print::pprust::{expr_to_str,path_to_str};
-use syntax::{visit,ast_util};
+use syntax::{visit};
 use syntax::visit::Visitor;
 
 // Kind analysis pass.
@@ -116,7 +116,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
     let ast_trait_def = *cx.tcx.def_map.borrow()
                               .find(&trait_ref.ref_id)
                               .expect("trait ref not in def map!");
-    let trait_def_id = ast_util::def_id_of_def(ast_trait_def);
+    let trait_def_id = ast_trait_def.def_id();
     let trait_def = cx.tcx.trait_defs.borrow()
                           .find_copy(&trait_def_id)
                           .expect("trait def not in trait-defs map!");
@@ -141,7 +141,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
             TyPath(_, ref bounds, path_node_id) => {
                 assert!(bounds.is_none());
                 let struct_def = cx.tcx.def_map.borrow().get_copy(&path_node_id);
-                let struct_did = ast_util::def_id_of_def(struct_def);
+                let struct_did = struct_def.def_id();
                 check_struct_safe_for_destructor(cx, self_type.span, struct_did);
             }
             _ => {
@@ -174,7 +174,7 @@ fn with_appropriate_checker(cx: &Context,
     fn check_for_uniq(cx: &Context, fv: &freevar_entry, bounds: ty::BuiltinBounds) {
         // all captured data must be owned, regardless of whether it is
         // moved in or copied in.
-        let id = ast_util::def_id_of_def(fv.def).node;
+        let id = fv.def.def_id().node;
         let var_t = ty::node_id_to_type(cx.tcx, id);
 
         check_freevar_bounds(cx, fv.span, var_t, bounds, None);
@@ -182,7 +182,7 @@ fn check_for_uniq(cx: &Context, fv: &freevar_entry, bounds: ty::BuiltinBounds) {
 
     fn check_for_block(cx: &Context, fv: &freevar_entry,
                        bounds: ty::BuiltinBounds, region: ty::Region) {
-        let id = ast_util::def_id_of_def(fv.def).node;
+        let id = fv.def.def_id().node;
         let var_t = ty::node_id_to_type(cx.tcx, id);
         // FIXME(#3569): Figure out whether the implicit borrow is actually
         // mutable. Currently we assume all upvars are referenced mutably.
@@ -257,7 +257,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
             let def_map = cx.tcx.def_map.borrow();
             let type_param_defs = match e.node {
               ExprPath(_) => {
-                let did = ast_util::def_id_of_def(def_map.get_copy(&e.id));
+                let did = def_map.get_copy(&e.id).def_id();
                 ty::lookup_item_type(cx.tcx, did).generics.type_param_defs.clone()
               }
               _ => {
@@ -348,7 +348,7 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
                 None => { }
                 Some(ref item_substs) => {
                     let def_map = cx.tcx.def_map.borrow();
-                    let did = ast_util::def_id_of_def(def_map.get_copy(&id));
+                    let did = def_map.get_copy(&id).def_id();
                     let generics = ty::lookup_item_type(cx.tcx, did).generics;
                     let type_param_defs = generics.type_param_defs();
                     for (&ty, type_param_def) in
index 871a336479df19c939405c5d37b43f6cce6a8061..cae8436d6df7079a240dc9bfbaa9689b1f1ca591 100644 (file)
@@ -38,6 +38,8 @@
 use driver::session;
 use metadata::csearch;
 use middle::dead::DEAD_CODE_LINT_STR;
+use middle::def;
+use middle::def::*;
 use middle::pat_util;
 use middle::privacy;
 use middle::trans::adt; // for `adt::is_ffi_safe`
@@ -935,17 +937,17 @@ fn check_ty(cx: &Context, ty: &ast::Ty) {
         match ty.node {
             ast::TyPath(_, _, id) => {
                 match cx.tcx.def_map.borrow().get_copy(&id) {
-                    ast::DefPrimTy(ast::TyInt(ast::TyI)) => {
+                    def::DefPrimTy(ast::TyInt(ast::TyI)) => {
                         cx.span_lint(CTypes, ty.span,
                                 "found rust type `int` in foreign module, while \
                                 libc::c_int or libc::c_long should be used");
                     }
-                    ast::DefPrimTy(ast::TyUint(ast::TyU)) => {
+                    def::DefPrimTy(ast::TyUint(ast::TyU)) => {
                         cx.span_lint(CTypes, ty.span,
                                 "found rust type `uint` in foreign module, while \
                                 libc::c_uint or libc::c_ulong should be used");
                     }
-                    ast::DefTy(def_id) => {
+                    def::DefTy(def_id) => {
                         if !adt::is_ffi_safe(cx.tcx, def_id) {
                             cx.span_lint(CTypes, ty.span,
                                          "found enum type without foreign-function-safe \
@@ -1394,7 +1396,7 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::Item) {
 fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
     // Lint for constants that look like binding identifiers (#7526)
     match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) {
-        (&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => {
+        (&ast::PatIdent(_, ref path, _), Some(&def::DefStatic(_, false))) => {
             // last identifier alone is right choice for this lint.
             let ident = path.segments.last().unwrap().identifier;
             let s = token::get_ident(ident);
@@ -1411,8 +1413,8 @@ fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
     match &p.node {
         &ast::PatIdent(_, ref path, _) => {
             match cx.tcx.def_map.borrow().find(&p.id) {
-                Some(&ast::DefLocal(_, _)) | Some(&ast::DefBinding(_, _)) |
-                        Some(&ast::DefArg(_, _)) => {
+                Some(&def::DefLocal(_, _)) | Some(&def::DefBinding(_, _)) |
+                        Some(&def::DefArg(_, _)) => {
                     // last identifier alone is right choice for this lint.
                     let ident = path.segments.last().unwrap().identifier;
                     let s = token::get_ident(ident);
@@ -1726,7 +1728,7 @@ fn check_stability(cx: &Context, e: &ast::Expr) {
     let id = match e.node {
         ast::ExprPath(..) | ast::ExprStruct(..) => {
             match cx.tcx.def_map.borrow().find(&e.id) {
-                Some(&def) => ast_util::def_id_of_def(def),
+                Some(&def) => def.def_id(),
                 None => return
             }
         }
index b5cb0f8e5aac8b12b47e4d7075695ffcd4790f94..8b1de130053ee15f944f3640a9a87769df2784b8 100644 (file)
  *   to return explicitly.
  */
 
-
+use middle::def::*;
 use middle::freevars;
 use middle::lint::{UnusedVariable, DeadAssignment};
 use middle::pat_util;
@@ -486,7 +486,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
                 match moved_variable_node_id_from_def(fv.def) {
                     Some(rv) => {
                         let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
-                        let fv_id = ast_util::def_id_of_def(fv.def).node;
+                        let fv_id = fv.def.def_id().node;
                         let fv_ty = ty::node_id_to_type(ir.tcx, fv_id);
                         let is_move = match fv_mode {
                             // var must be dead afterwards
index 240212699e4de314cc36063faae2f48c1061b448..06e0a12577270b359dc87e012d29db6ddeca3474 100644 (file)
@@ -62,6 +62,7 @@
 
 #![allow(non_camel_case_types)]
 
+use middle::def;
 use middle::ty;
 use middle::typeck;
 use util::nodemap::NodeMap;
@@ -489,20 +490,20 @@ pub fn cat_def(&self,
                    id: ast::NodeId,
                    span: Span,
                    expr_ty: ty::t,
-                   def: ast::Def)
+                   def: def::Def)
                    -> McResult<cmt> {
         debug!("cat_def: id={} expr={} def={:?}",
                id, expr_ty.repr(self.tcx()), def);
 
         match def {
-          ast::DefStruct(..) | ast::DefVariant(..) => {
+          def::DefStruct(..) | def::DefVariant(..) => {
                 Ok(self.cat_rvalue_node(id, span, expr_ty))
           }
-          ast::DefFn(..) | ast::DefStaticMethod(..) | ast::DefMod(_) |
-          ast::DefForeignMod(_) | ast::DefStatic(_, false) |
-          ast::DefUse(_) | ast::DefTrait(_) | ast::DefTy(_) | ast::DefPrimTy(_) |
-          ast::DefTyParam(..) | ast::DefTyParamBinder(..) | ast::DefRegion(_) |
-          ast::DefLabel(_) | ast::DefSelfTy(..) | ast::DefMethod(..) => {
+          def::DefFn(..) | def::DefStaticMethod(..) | def::DefMod(_) |
+          def::DefForeignMod(_) | def::DefStatic(_, false) |
+          def::DefUse(_) | def::DefTrait(_) | def::DefTy(_) | def::DefPrimTy(_) |
+          def::DefTyParam(..) | def::DefTyParamBinder(..) | def::DefRegion(_) |
+          def::DefLabel(_) | def::DefSelfTy(..) | def::DefMethod(..) => {
               Ok(Rc::new(cmt_ {
                   id:id,
                   span:span,
@@ -512,7 +513,7 @@ pub fn cat_def(&self,
               }))
           }
 
-          ast::DefStatic(_, true) => {
+          def::DefStatic(_, true) => {
               Ok(Rc::new(cmt_ {
                   id:id,
                   span:span,
@@ -522,7 +523,7 @@ pub fn cat_def(&self,
               }))
           }
 
-          ast::DefArg(vid, binding_mode) => {
+          def::DefArg(vid, binding_mode) => {
             // Idea: make this could be rewritten to model by-ref
             // stuff as `&const` and `&mut`?
 
@@ -540,7 +541,7 @@ pub fn cat_def(&self,
             }))
           }
 
-          ast::DefUpvar(var_id, _, fn_node_id, _) => {
+          def::DefUpvar(var_id, _, fn_node_id, _) => {
               let ty = if_ok!(self.node_ty(fn_node_id));
               match ty::get(ty).sty {
                   ty::ty_closure(ref closure_ty) => {
@@ -582,8 +583,8 @@ pub fn cat_def(&self,
               }
           }
 
-          ast::DefLocal(vid, binding_mode) |
-          ast::DefBinding(vid, binding_mode) => {
+          def::DefLocal(vid, binding_mode) |
+          def::DefBinding(vid, binding_mode) => {
             // by-value/by-ref bindings are local variables
             let m = match binding_mode {
                 ast::BindByValue(ast::MutMutable) => McDeclared,
@@ -987,7 +988,7 @@ pub fn cat_pattern(&self,
           }
           ast::PatEnum(_, Some(ref subpats)) => {
             match self.tcx().def_map.borrow().find(&pat.id) {
-                Some(&ast::DefVariant(enum_did, _, _)) => {
+                Some(&def::DefVariant(enum_did, _, _)) => {
                     // variant(x, y, z)
 
                     let downcast_cmt = {
@@ -1009,8 +1010,8 @@ pub fn cat_pattern(&self,
                         if_ok!(self.cat_pattern(subcmt, subpat, |x,y,z| op(x,y,z)));
                     }
                 }
-                Some(&ast::DefFn(..)) |
-                Some(&ast::DefStruct(..)) => {
+                Some(&def::DefFn(..)) |
+                Some(&def::DefStruct(..)) => {
                     for (i, &subpat) in subpats.iter().enumerate() {
                         let subpat_ty = if_ok!(self.pat_ty(subpat)); // see (*2)
                         let cmt_field =
@@ -1020,7 +1021,7 @@ pub fn cat_pattern(&self,
                         if_ok!(self.cat_pattern(cmt_field, subpat, |x,y,z| op(x,y,z)));
                     }
                 }
-                Some(&ast::DefStatic(..)) => {
+                Some(&def::DefStatic(..)) => {
                     for &subpat in subpats.iter() {
                         if_ok!(self.cat_pattern(cmt.clone(), subpat, |x,y,z| op(x,y,z)));
                     }
index 49437a90e3f8403f7fb4d8ebf5625aec2c23778d..44ed0192d1d27601d809613ca6d7967db6ec615c 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
+use middle::def::*;
 use middle::resolve;
 
 use std::collections::HashMap;
index 5b47336efe5e8ef2181e8f844a5af457444f7858..fcd6d4246592ba54bba18f4cadcaa4047252a363 100644 (file)
@@ -15,6 +15,7 @@
 use std::mem::replace;
 
 use metadata::csearch;
+use middle::def;
 use middle::lint;
 use middle::resolve;
 use middle::ty;
@@ -24,7 +25,7 @@
 
 use syntax::ast;
 use syntax::ast_map;
-use syntax::ast_util::{is_local, def_id_of_def, local_def};
+use syntax::ast_util::{is_local, local_def};
 use syntax::attr;
 use syntax::codemap::Span;
 use syntax::parse::token;
@@ -243,9 +244,9 @@ fn visit_item(&mut self, item: &ast::Item, _: ()) {
                 let public_ty = match ty.node {
                     ast::TyPath(_, _, id) => {
                         match self.tcx.def_map.borrow().get_copy(&id) {
-                            ast::DefPrimTy(..) => true,
+                            def::DefPrimTy(..) => true,
                             def => {
-                                let did = def_id_of_def(def);
+                                let did = def.def_id();
                                 !is_local(did) ||
                                  self.exported_items.contains(&did.node)
                             }
@@ -301,9 +302,9 @@ fn visit_item(&mut self, item: &ast::Item, _: ()) {
                 match ty.node {
                     ast::TyPath(_, _, id) => {
                         match self.tcx.def_map.borrow().get_copy(&id) {
-                            ast::DefPrimTy(..) => {},
+                            def::DefPrimTy(..) => {},
                             def => {
-                                let did = def_id_of_def(def);
+                                let did = def.def_id();
                                 if is_local(did) {
                                     self.exported_items.insert(did.node);
                                 }
@@ -576,7 +577,7 @@ fn ensure_public(&self, span: Span, to_check: ast::DefId,
                             _ => return Some((err_span, err_msg, None)),
                         };
                         let def = self.tcx.def_map.borrow().get_copy(&id);
-                        let did = def_id_of_def(def);
+                        let did = def.def_id();
                         assert!(is_local(did));
                         match self.tcx.map.get(did.node) {
                             ast_map::NodeItem(item) => item,
@@ -673,7 +674,7 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
                                                 .last()
                                                 .unwrap()
                                                 .identifier);
-                let origdid = def_id_of_def(orig_def);
+                let origdid = orig_def.def_id();
                 self.ensure_public(span,
                                    def,
                                    Some(origdid),
@@ -750,16 +751,16 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
         // be accurate and we can get slightly wonky error messages (but type
         // checking is always correct).
         match self.tcx.def_map.borrow().get_copy(&path_id) {
-            ast::DefStaticMethod(..) => ck("static method"),
-            ast::DefFn(..) => ck("function"),
-            ast::DefStatic(..) => ck("static"),
-            ast::DefVariant(..) => ck("variant"),
-            ast::DefTy(..) => ck("type"),
-            ast::DefTrait(..) => ck("trait"),
-            ast::DefStruct(..) => ck("struct"),
-            ast::DefMethod(_, Some(..)) => ck("trait method"),
-            ast::DefMethod(..) => ck("method"),
-            ast::DefMod(..) => ck("module"),
+            def::DefStaticMethod(..) => ck("static method"),
+            def::DefFn(..) => ck("function"),
+            def::DefStatic(..) => ck("static"),
+            def::DefVariant(..) => ck("variant"),
+            def::DefTy(..) => ck("type"),
+            def::DefTrait(..) => ck("trait"),
+            def::DefStruct(..) => ck("struct"),
+            def::DefMethod(_, Some(..)) => ck("trait method"),
+            def::DefMethod(..) => ck("method"),
+            def::DefMod(..) => ck("module"),
             _ => {}
         }
     }
@@ -829,7 +830,7 @@ fn visit_expr(&mut self, expr: &ast::Expr, _: ()) {
                     }
                     ty::ty_enum(_, _) => {
                         match self.tcx.def_map.borrow().get_copy(&expr.id) {
-                            ast::DefVariant(_, variant_id, _) => {
+                            def::DefVariant(_, variant_id, _) => {
                                 for field in fields.iter() {
                                     self.check_field(expr.span, variant_id,
                                                      NamedField(field.ident.node));
@@ -862,7 +863,7 @@ struct type?!"),
                     }
                 };
                 match self.tcx.def_map.borrow().find(&expr.id) {
-                    Some(&ast::DefStruct(did)) => {
+                    Some(&def::DefStruct(did)) => {
                         guard(if is_local(did) {
                             local_def(self.tcx.map.get_parent(did.node))
                         } else {
@@ -877,7 +878,7 @@ struct type?!"),
                     }
                     // Tuple struct constructors across crates are identified as
                     // DefFn types, so we explicitly handle that case here.
-                    Some(&ast::DefFn(did, _)) if !is_local(did) => {
+                    Some(&def::DefFn(did, _)) if !is_local(did) => {
                         match csearch::get_tuple_struct_definition_if_ctor(
                                     &self.tcx.sess.cstore, did) {
                             Some(did) => guard(did),
@@ -940,7 +941,7 @@ fn visit_pat(&mut self, pattern: &ast::Pat, _: ()) {
                     }
                     ty::ty_enum(_, _) => {
                         match self.tcx.def_map.borrow().find(&pattern.id) {
-                            Some(&ast::DefVariant(_, variant_id, _)) => {
+                            Some(&def::DefVariant(_, variant_id, _)) => {
                                 for field in fields.iter() {
                                     self.check_field(pattern.span, variant_id,
                                                      NamedField(field.ident));
@@ -1205,8 +1206,8 @@ impl<'a> VisiblePrivateTypesVisitor<'a> {
     fn path_is_private_type(&self, path_id: ast::NodeId) -> bool {
         let did = match self.tcx.def_map.borrow().find_copy(&path_id) {
             // `int` etc. (None doesn't seem to occur.)
-            None | Some(ast::DefPrimTy(..)) => return false,
-            Some(def) => def_id_of_def(def)
+            None | Some(def::DefPrimTy(..)) => return false,
+            Some(def) => def.def_id()
         };
         // A path can only be private if:
         // it's in this crate...
index a725ac960f838a1586d2d241ef81ba54b3d23def..ef2f78de8f975d0f59efa16db74b871e4cf3eaa4 100644 (file)
@@ -16,6 +16,7 @@
 // reachable as well.
 
 use driver::config;
+use middle::def;
 use middle::ty;
 use middle::typeck;
 use middle::privacy;
@@ -25,7 +26,7 @@
 use syntax::abi;
 use syntax::ast;
 use syntax::ast_map;
-use syntax::ast_util::{def_id_of_def, is_local};
+use syntax::ast_util::{is_local};
 use syntax::attr;
 use syntax::visit::Visitor;
 use syntax::visit;
@@ -109,7 +110,7 @@ fn visit_expr(&mut self, expr: &ast::Expr, _: ()) {
                     }
                 };
 
-                let def_id = def_id_of_def(def);
+                let def_id = def.def_id();
                 if is_local(def_id) {
                     if self.def_id_represents_local_inlined_item(def_id) {
                         self.worklist.push(def_id.node)
@@ -119,7 +120,7 @@ fn visit_expr(&mut self, expr: &ast::Expr, _: ()) {
                             // to do some work to figure out whether the static
                             // is indeed reachable (address_insignificant
                             // statics are *never* reachable).
-                            ast::DefStatic(..) => {
+                            def::DefStatic(..) => {
                                 self.worklist.push(def_id.node);
                             }
 
index 2228c21b2391751b98a64f3fda57aa7a5f6ffeea..f4962c9083aff1d0dbeee2554aab1563587bf605 100644 (file)
@@ -13,6 +13,7 @@
 use driver::session::Session;
 use metadata::csearch;
 use metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
+use middle::def::*;
 use middle::lang_items::LanguageItems;
 use middle::lint::{UnnecessaryQualification, UnusedImports};
 use middle::pat_util::pat_bindings;
@@ -20,7 +21,7 @@
 
 use syntax::ast::*;
 use syntax::ast;
-use syntax::ast_util::{def_id_of_def, local_def};
+use syntax::ast_util::{local_def};
 use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
 use syntax::ext::mtwt;
 use syntax::parse::token::special_idents;
@@ -1599,7 +1600,7 @@ fn handle_external_def(&mut self,
             }
         };
         if is_exported {
-            self.external_exports.insert(def_id_of_def(def));
+            self.external_exports.insert(def.def_id());
         }
         match def {
           DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
@@ -2438,7 +2439,7 @@ fn get_binding(this: &mut Resolver,
             Some(ref target) => {
                 let def = target.bindings.def_for_namespace(ValueNS).unwrap();
                 self.def_map.borrow_mut().insert(directive.id, def);
-                let did = def_id_of_def(def);
+                let did = def.def_id();
                 if value_used_public {Some(lp)} else {Some(DependsOn(did))}
             },
             // AllPublic here and below is a dummy value, it should never be used because
@@ -2449,7 +2450,7 @@ fn get_binding(this: &mut Resolver,
             Some(ref target) => {
                 let def = target.bindings.def_for_namespace(TypeNS).unwrap();
                 self.def_map.borrow_mut().insert(directive.id, def);
-                let did = def_id_of_def(def);
+                let did = def.def_id();
                 if type_used_public {Some(lp)} else {Some(DependsOn(did))}
             },
             None => None,
@@ -3307,10 +3308,10 @@ fn add_exports_of_namebindings(&mut self,
             Some(d) => {
                 let name = token::get_name(name);
                 debug!("(computing exports) YES: export '{}' => {:?}",
-                       name, def_id_of_def(d));
+                       name, d.def_id());
                 exports2.push(Export2 {
                     name: name.get().to_string(),
-                    def_id: def_id_of_def(d)
+                    def_id: d.def_id()
                 });
             }
             d_opt => {
@@ -3434,10 +3435,10 @@ fn upvarify(&self,
                 }
                 FunctionRibKind(function_id, body_id) => {
                     if !is_ty_param {
-                        def = DefUpvar(def_id_of_def(def).node,
-                                        @def,
-                                        function_id,
-                                        body_id);
+                        def = DefUpvar(def.def_id().node,
+                                       @def,
+                                       function_id,
+                                       body_id);
                     }
                 }
                 MethodRibKind(item_id, _) => {
@@ -3967,7 +3968,7 @@ fn with_optional_trait_ref<T>(&mut self, id: NodeId,
 
                 match self.def_map.borrow().find(&trait_ref.ref_id) {
                     Some(def) => {
-                        let did = def_id_of_def(*def);
+                        let did = def.def_id();
                         Some((did, trait_ref.clone()))
                     }
                     None => None
@@ -4638,7 +4639,7 @@ fn resolve_definition_of_name_in_module(&mut self,
                         let p = child_name_bindings.defined_in_public_namespace(
                                         namespace);
                         let lp = if p {LastMod(AllPublic)} else {
-                            LastMod(DependsOn(def_id_of_def(def)))
+                            LastMod(DependsOn(def.def_id()))
                         };
                         return ChildNameDefinition(def, lp);
                     }
index a34fb0a99e132d939b34f9af564e93bf6b464b49..c581dda3164a769c3db612dce72e3ce045417b5d 100644 (file)
@@ -24,7 +24,7 @@
  * Represents the values to use when substituting lifetime parameters.
  * If the value is `ErasedRegions`, then this subst is occurring during
  * trans, and all region parameters will be replaced with `ty::ReStatic`. */
-#[deriving(Clone, Eq, TotalEq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash)]
 pub enum RegionSubsts {
     ErasedRegions,
     NonerasedRegions(Vec<ty::Region>)
@@ -47,7 +47,7 @@ pub enum RegionSubsts {
  * - `self_ty` is the type to which `self` should be remapped, if any.  The
  *   `self` type is rather funny in that it can only appear on traits and is
  *   always substituted away to the implementing type for a trait. */
-#[deriving(Clone, Eq, TotalEq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash)]
 pub struct Substs {
     pub self_ty: Option<ty::t>,
     pub tps: Vec<ty::t>,
index 1cf8a301d804e5e7f5a740396cf5df03f56255bd..2a3ec63e995ef3b089211fe9313339ca81acbc07 100644 (file)
 use driver::config::FullDebugInfo;
 use lib::llvm::{llvm, ValueRef, BasicBlockRef};
 use middle::const_eval;
+use middle::def;
 use middle::lang_items::{UniqStrEqFnLangItem, StrEqFnLangItem};
 use middle::pat_util::*;
 use middle::resolve::DefMap;
@@ -336,7 +337,7 @@ fn variant_opt(bcx: &Block, pat_id: ast::NodeId) -> Opt {
     let ccx = bcx.ccx();
     let def = ccx.tcx.def_map.borrow().get_copy(&pat_id);
     match def {
-        ast::DefVariant(enum_id, var_id, _) => {
+        def::DefVariant(enum_id, var_id, _) => {
             let variants = ty::enum_variants(ccx.tcx(), enum_id);
             for v in (*variants).iter() {
                 if var_id == v.id {
@@ -346,8 +347,8 @@ fn variant_opt(bcx: &Block, pat_id: ast::NodeId) -> Opt {
             }
             unreachable!();
         }
-        ast::DefFn(..) |
-        ast::DefStruct(_) => {
+        def::DefFn(..) |
+        def::DefStruct(_) => {
             return lit(UnitLikeStructLit(pat_id));
         }
         _ => {
@@ -603,7 +604,7 @@ fn enter_opt<'a, 'b>(
             ast::PatEnum(..) |
             ast::PatIdent(_, _, None) if pat_is_const(&tcx.def_map, p) => {
                 let const_def = tcx.def_map.borrow().get_copy(&p.id);
-                let const_def_id = ast_util::def_id_of_def(const_def);
+                let const_def_id = const_def.def_id();
                 if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
                     Some(Vec::new())
                 } else {
@@ -644,7 +645,7 @@ fn enter_opt<'a, 'b>(
                     // Look up the struct variant ID.
                     let struct_id;
                     match tcx.def_map.borrow().get_copy(&p.id) {
-                        ast::DefVariant(_, found_struct_id, _) => {
+                        def::DefVariant(_, found_struct_id, _) => {
                             struct_id = found_struct_id;
                         }
                         _ => {
@@ -918,15 +919,15 @@ fn add_veclen_to_set(set: &mut Vec<Opt> , i: uint,
                 // variable binding.
                 let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
                 match opt_def {
-                    Some(ast::DefVariant(..)) => {
+                    Some(def::DefVariant(..)) => {
                         add_to_set(ccx.tcx(), &mut found,
                                    variant_opt(bcx, cur.id));
                     }
-                    Some(ast::DefStruct(..)) => {
+                    Some(def::DefStruct(..)) => {
                         add_to_set(ccx.tcx(), &mut found,
                                    lit(UnitLikeStructLit(cur.id)));
                     }
-                    Some(ast::DefStatic(const_did, false)) => {
+                    Some(def::DefStatic(const_did, false)) => {
                         add_to_set(ccx.tcx(), &mut found,
                                    lit(ConstLit(const_did)));
                     }
@@ -938,12 +939,12 @@ fn add_veclen_to_set(set: &mut Vec<Opt> , i: uint,
                 // struct-like enum variant, or a struct.
                 let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
                 match opt_def {
-                    Some(ast::DefFn(..)) |
-                    Some(ast::DefVariant(..)) => {
+                    Some(def::DefFn(..)) |
+                    Some(def::DefVariant(..)) => {
                         add_to_set(ccx.tcx(), &mut found,
                                    variant_opt(bcx, cur.id));
                     }
-                    Some(ast::DefStatic(const_did, false)) => {
+                    Some(def::DefStatic(const_did, false)) => {
                         add_to_set(ccx.tcx(), &mut found,
                                    lit(ConstLit(const_did)));
                     }
@@ -1122,8 +1123,8 @@ fn any_tuple_struct_pat(bcx: &Block, m: &[Match], col: uint) -> bool {
         match pat.node {
             ast::PatEnum(_, _) => {
                 match bcx.tcx().def_map.borrow().find(&pat.id) {
-                    Some(&ast::DefFn(..)) |
-                    Some(&ast::DefStruct(..)) => true,
+                    Some(&def::DefFn(..)) |
+                    Some(&def::DefStruct(..)) => true,
                     _ => false
                 }
             }
@@ -2205,7 +2206,7 @@ fn bind_irrefutable_pat<'a>(
         ast::PatEnum(_, ref sub_pats) => {
             let opt_def = bcx.tcx().def_map.borrow().find_copy(&pat.id);
             match opt_def {
-                Some(ast::DefVariant(enum_id, var_id, _)) => {
+                Some(def::DefVariant(enum_id, var_id, _)) => {
                     let repr = adt::represent_node(bcx, pat.id);
                     let vinfo = ty::enum_variant_with_id(ccx.tcx(),
                                                          enum_id,
@@ -2222,8 +2223,8 @@ fn bind_irrefutable_pat<'a>(
                         }
                     }
                 }
-                Some(ast::DefFn(..)) |
-                Some(ast::DefStruct(..)) => {
+                Some(def::DefFn(..)) |
+                Some(def::DefStruct(..)) => {
                     match *sub_pats {
                         None => {
                             // This is a unit-like struct. Nothing to do here.
@@ -2241,7 +2242,7 @@ fn bind_irrefutable_pat<'a>(
                         }
                     }
                 }
-                Some(ast::DefStatic(_, false)) => {
+                Some(def::DefStatic(_, false)) => {
                 }
                 _ => {
                     // Nothing to do here.
index a488770689d3db353f6c0e6b64888f45fc56dd29..005fc446888a771ca28efe606fea2feae3dc5006 100644 (file)
@@ -21,6 +21,7 @@
 use lib::llvm::ValueRef;
 use lib::llvm::llvm;
 use metadata::csearch;
+use middle::def;
 use middle::subst;
 use middle::subst::Subst;
 use middle::trans::base;
@@ -114,42 +115,42 @@ fn fn_callee<'a>(bcx: &'a Block<'a>, llfn: ValueRef) -> Callee<'a> {
         return Callee {bcx: bcx, data: Fn(llfn)};
     }
 
-    fn trans_def<'a>(bcx: &'a Block<'a>, def: ast::Def, ref_expr: &ast::Expr)
+    fn trans_def<'a>(bcx: &'a Block<'a>, def: def::Def, ref_expr: &ast::Expr)
                  -> Callee<'a> {
         match def {
-            ast::DefFn(did, _) |
-            ast::DefStaticMethod(did, ast::FromImpl(_), _) => {
+            def::DefFn(did, _) |
+            def::DefStaticMethod(did, def::FromImpl(_), _) => {
                 fn_callee(bcx, trans_fn_ref(bcx, did, ExprId(ref_expr.id)))
             }
-            ast::DefStaticMethod(impl_did,
-                                   ast::FromTrait(trait_did),
-                                   _) => {
+            def::DefStaticMethod(impl_did,
+                                 def::FromTrait(trait_did),
+                                 _) => {
                 fn_callee(bcx, meth::trans_static_method_callee(bcx, impl_did,
                                                                 trait_did,
                                                                 ref_expr.id))
             }
-            ast::DefVariant(tid, vid, _) => {
+            def::DefVariant(tid, vid, _) => {
                 // nullary variants are not callable
                 assert!(ty::enum_variant_with_id(bcx.tcx(),
                                                       tid,
                                                       vid).args.len() > 0u);
                 fn_callee(bcx, trans_fn_ref(bcx, vid, ExprId(ref_expr.id)))
             }
-            ast::DefStruct(def_id) => {
+            def::DefStruct(def_id) => {
                 fn_callee(bcx, trans_fn_ref(bcx, def_id, ExprId(ref_expr.id)))
             }
-            ast::DefStatic(..) |
-            ast::DefArg(..) |
-            ast::DefLocal(..) |
-            ast::DefBinding(..) |
-            ast::DefUpvar(..) => {
+            def::DefStatic(..) |
+            def::DefArg(..) |
+            def::DefLocal(..) |
+            def::DefBinding(..) |
+            def::DefUpvar(..) => {
                 datum_callee(bcx, ref_expr)
             }
-            ast::DefMod(..) | ast::DefForeignMod(..) | ast::DefTrait(..) |
-            ast::DefTy(..) | ast::DefPrimTy(..) |
-            ast::DefUse(..) | ast::DefTyParamBinder(..) |
-            ast::DefRegion(..) | ast::DefLabel(..) | ast::DefTyParam(..) |
-            ast::DefSelfTy(..) | ast::DefMethod(..) => {
+            def::DefMod(..) | def::DefForeignMod(..) | def::DefTrait(..) |
+            def::DefTy(..) | def::DefPrimTy(..) |
+            def::DefUse(..) | def::DefTyParamBinder(..) |
+            def::DefRegion(..) | def::DefLabel(..) | def::DefTyParam(..) |
+            def::DefSelfTy(..) | def::DefMethod(..) => {
                 bcx.tcx().sess.span_bug(
                     ref_expr.span,
                     format!("cannot translate def {:?} \
index 9ca66f4c3b05663661159010af4ce3958d3b5a9c..b5fd37d815fba78163bb8c0052c490b01141b969 100644 (file)
@@ -13,6 +13,7 @@
 use back::link::mangle_internal_name_by_path_and_seq;
 use driver::config::FullDebugInfo;
 use lib::llvm::ValueRef;
+use middle::def;
 use middle::freevars;
 use middle::lang_items::ClosureExchangeMallocFnLangItem;
 use middle::trans::base::*;
@@ -30,7 +31,6 @@
 
 use arena::TypedArena;
 use syntax::ast;
-use syntax::ast_util;
 
 // ___Good to know (tm)__________________________________________________
 //
@@ -282,7 +282,7 @@ fn load_environment<'a>(bcx: &'a Block<'a>,
             ty::RegionTraitStore(..) => { upvarptr = Load(bcx, upvarptr); }
             ty::UniqTraitStore => {}
         }
-        let def_id = ast_util::def_id_of_def(freevar.def);
+        let def_id = freevar.def.def_id();
 
         bcx.fcx.llupvars.borrow_mut().insert(def_id.node, upvarptr);
 
@@ -368,13 +368,13 @@ pub fn trans_expr_fn<'a>(
 
 pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
                                closure_ty: ty::t,
-                               def: ast::Def,
+                               def: def::Def,
                                fn_ptr: ValueRef,
                                is_local: bool) -> ValueRef {
 
     let def_id = match def {
-        ast::DefFn(did, _) | ast::DefStaticMethod(did, _, _) |
-        ast::DefVariant(_, did, _) | ast::DefStruct(did) => did,
+        def::DefFn(did, _) | def::DefStaticMethod(did, _, _) |
+        def::DefVariant(_, did, _) | def::DefStruct(did) => did,
         _ => {
             ccx.sess().bug(format!("get_wrapper_for_bare_fn: \
                                     expected a statically resolved fn, got \
@@ -453,7 +453,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
 
 pub fn make_closure_from_bare_fn<'a>(bcx: &'a Block<'a>,
                                      closure_ty: ty::t,
-                                     def: ast::Def,
+                                     def: def::Def,
                                      fn_ptr: ValueRef)
                                      -> DatumBlock<'a, Expr>  {
     let scratch = rvalue_scratch_datum(bcx, closure_ty, "__adjust");
index 46c5edf5f5b419e71843f7c7f7a25571ff9e7039..dbb6f3fe1cfb10d02d73b3b645d4df4c07a30209 100644 (file)
@@ -17,6 +17,7 @@
 use lib::llvm::{True, False, Bool};
 use lib::llvm::llvm;
 use lib;
+use middle::def;
 use middle::lang_items::LangItem;
 use middle::subst;
 use middle::subst::Subst;
@@ -454,7 +455,7 @@ pub fn expr_to_str(&self, e: &ast::Expr) -> String {
         e.repr(self.tcx())
     }
 
-    pub fn def(&self, nid: ast::NodeId) -> ast::Def {
+    pub fn def(&self, nid: ast::NodeId) -> def::Def {
         match self.tcx().def_map.borrow().find(&nid) {
             Some(&v) => v,
             None => {
index 8b43e99b6ac6d47c1eac313bef993ecaadce291d..ac6e9ca6c645ef68e041f782386b6ca8dc2b13bc 100644 (file)
@@ -17,6 +17,7 @@
 
 use metadata::csearch;
 use middle::const_eval;
+use middle::def;
 use middle::trans::adt;
 use middle::trans::base;
 use middle::trans::base::push_ctxt;
@@ -617,7 +618,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
 
             let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
             match opt_def {
-                Some(ast::DefFn(def_id, _fn_style)) => {
+                Some(def::DefFn(def_id, _fn_style)) => {
                     if !ast_util::is_local(def_id) {
                         let ty = csearch::get_type(cx.tcx(), def_id).ty;
                         (base::trans_external_path(cx, def_id, ty), true)
@@ -626,10 +627,10 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
                         (base::get_item_val(cx, def_id.node), true)
                     }
                 }
-                Some(ast::DefStatic(def_id, false)) => {
+                Some(def::DefStatic(def_id, false)) => {
                     get_const_val(cx, def_id)
                 }
-                Some(ast::DefVariant(enum_did, variant_did, _)) => {
+                Some(def::DefVariant(enum_did, variant_did, _)) => {
                     let ety = ty::expr_ty(cx.tcx(), e);
                     let repr = adt::represent_type(cx, ety);
                     let vinfo = ty::enum_variant_with_id(cx.tcx(),
@@ -637,7 +638,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
                                                          variant_did);
                     (adt::trans_const(cx, &*repr, vinfo.disr_val, []), true)
                 }
-                Some(ast::DefStruct(_)) => {
+                Some(def::DefStruct(_)) => {
                     let ety = ty::expr_ty(cx.tcx(), e);
                     let llty = type_of::type_of(cx, ety);
                     (C_null(llty), true)
@@ -650,14 +651,14 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
           ast::ExprCall(callee, ref args) => {
               let opt_def = cx.tcx().def_map.borrow().find_copy(&callee.id);
               match opt_def {
-                  Some(ast::DefStruct(_)) => {
+                  Some(def::DefStruct(_)) => {
                       let ety = ty::expr_ty(cx.tcx(), e);
                       let repr = adt::represent_type(cx, ety);
                       let (arg_vals, inlineable) = map_list(args.as_slice());
                       (adt::trans_const(cx, &*repr, 0, arg_vals.as_slice()),
                        inlineable)
                   }
-                  Some(ast::DefVariant(enum_did, variant_did, _)) => {
+                  Some(def::DefVariant(enum_did, variant_did, _)) => {
                       let ety = ty::expr_ty(cx.tcx(), e);
                       let repr = adt::represent_type(cx, ety);
                       let vinfo = ty::enum_variant_with_id(cx.tcx(),
index eac7af56ed4c00bd371c181273500e4c30fa0e54..ea152c348087c4052d05682e862909f16f775464 100644 (file)
@@ -10,6 +10,7 @@
 
 use lib::llvm::*;
 use driver::config::FullDebugInfo;
+use middle::def;
 use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
 use middle::trans::base::*;
 use middle::trans::build::*;
@@ -288,7 +289,7 @@ pub fn trans_break_cont<'a>(bcx: &'a Block<'a>,
         None => fcx.top_loop_scope(),
         Some(_) => {
             match bcx.tcx().def_map.borrow().find(&expr_id) {
-                Some(&ast::DefLabel(loop_id)) => loop_id,
+                Some(&def::DefLabel(loop_id)) => loop_id,
                 ref r => {
                     bcx.tcx().sess.bug(format!("{:?} in def-map for label",
                                                r).as_slice())
index 6241c1222f9c3f611820620e39875202b46ab0ef..d9ae9b08381708fc6cbdeb71983becba468b17e0 100644 (file)
@@ -37,6 +37,7 @@
 use lib::llvm::{ValueRef, llvm};
 use lib;
 use metadata::csearch;
+use middle::def;
 use middle::lang_items::MallocFnLangItem;
 use middle::trans::_match;
 use middle::trans::adt;
@@ -499,18 +500,18 @@ fn trans_index<'a>(bcx: &'a Block<'a>,
 
 fn trans_def<'a>(bcx: &'a Block<'a>,
                  ref_expr: &ast::Expr,
-                 def: ast::Def)
+                 def: def::Def)
                  -> DatumBlock<'a, Expr>
 {
     //! Translates a reference to a path.
 
     let _icx = push_ctxt("trans_def_lvalue");
     match def {
-        ast::DefFn(..) | ast::DefStaticMethod(..) |
-        ast::DefStruct(_) | ast::DefVariant(..) => {
+        def::DefFn(..) | def::DefStaticMethod(..) |
+        def::DefStruct(_) | def::DefVariant(..) => {
             trans_def_fn_unadjusted(bcx, ref_expr, def)
         }
-        ast::DefStatic(did, _) => {
+        def::DefStatic(did, _) => {
             let const_ty = expr_ty(bcx, ref_expr);
 
             fn get_did(ccx: &CrateContext, did: ast::DefId)
@@ -775,7 +776,7 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
 fn trans_def_dps_unadjusted<'a>(
                             bcx: &'a Block<'a>,
                             ref_expr: &ast::Expr,
-                            def: ast::Def,
+                            def: def::Def,
                             dest: Dest)
                             -> &'a Block<'a> {
     let _icx = push_ctxt("trans_def_dps_unadjusted");
@@ -786,7 +787,7 @@ fn trans_def_dps_unadjusted<'a>(
     };
 
     match def {
-        ast::DefVariant(tid, vid, _) => {
+        def::DefVariant(tid, vid, _) => {
             let variant_info = ty::enum_variant_with_id(bcx.tcx(), tid, vid);
             if variant_info.args.len() > 0u {
                 // N-ary variant.
@@ -802,7 +803,7 @@ fn trans_def_dps_unadjusted<'a>(
                 return bcx;
             }
         }
-        ast::DefStruct(_) => {
+        def::DefStruct(_) => {
             let ty = expr_ty(bcx, ref_expr);
             match ty::get(ty).sty {
                 ty::ty_struct(did, _) if ty::has_dtor(bcx.tcx(), did) => {
@@ -823,16 +824,16 @@ fn trans_def_dps_unadjusted<'a>(
 
 fn trans_def_fn_unadjusted<'a>(bcx: &'a Block<'a>,
                                ref_expr: &ast::Expr,
-                               def: ast::Def) -> DatumBlock<'a, Expr> {
+                               def: def::Def) -> DatumBlock<'a, Expr> {
     let _icx = push_ctxt("trans_def_datum_unadjusted");
 
     let llfn = match def {
-        ast::DefFn(did, _) |
-        ast::DefStruct(did) | ast::DefVariant(_, did, _) |
-        ast::DefStaticMethod(did, ast::FromImpl(_), _) => {
+        def::DefFn(did, _) |
+        def::DefStruct(did) | def::DefVariant(_, did, _) |
+        def::DefStaticMethod(did, def::FromImpl(_), _) => {
             callee::trans_fn_ref(bcx, did, ExprId(ref_expr.id))
         }
-        ast::DefStaticMethod(impl_did, ast::FromTrait(trait_did), _) => {
+        def::DefStaticMethod(impl_did, def::FromTrait(trait_did), _) => {
             meth::trans_static_method_callee(bcx, impl_did,
                                              trait_did, ref_expr.id)
         }
@@ -849,7 +850,7 @@ fn trans_def_fn_unadjusted<'a>(bcx: &'a Block<'a>,
 }
 
 pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
-                           def: ast::Def)
+                           def: def::Def)
                            -> Datum<Lvalue> {
     /*!
      * Translates a reference to a local variable or argument.
@@ -859,7 +860,7 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
     let _icx = push_ctxt("trans_local_var");
 
     return match def {
-        ast::DefUpvar(nid, _, _, _) => {
+        def::DefUpvar(nid, _, _, _) => {
             // Can't move upvars, so this is never a ZeroMemLastUse.
             let local_ty = node_id_type(bcx, nid);
             match bcx.fcx.llupvars.borrow().find(&nid) {
@@ -871,10 +872,10 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>,
                 }
             }
         }
-        ast::DefArg(nid, _) => {
+        def::DefArg(nid, _) => {
             take_local(bcx, &*bcx.fcx.llargs.borrow(), nid)
         }
-        ast::DefLocal(nid, _) | ast::DefBinding(nid, _) => {
+        def::DefLocal(nid, _) | def::DefBinding(nid, _) => {
             take_local(bcx, &*bcx.fcx.lllocals.borrow(), nid)
         }
         _ => {
@@ -931,7 +932,7 @@ pub fn with_field_tys<R>(tcx: &ty::ctxt,
                 Some(node_id) => {
                     let def = tcx.def_map.borrow().get_copy(&node_id);
                     match def {
-                        ast::DefVariant(enum_id, variant_id, _) => {
+                        def::DefVariant(enum_id, variant_id, _) => {
                             let variant_info = ty::enum_variant_with_id(
                                 tcx, enum_id, variant_id);
                             op(variant_info.disr_val,
index c47abf5fb7391f53e80b9fd7d72cd07a32920e6d..6275abdc8ab209a893742e8a0dd017833e535b75 100644 (file)
@@ -16,6 +16,7 @@
 use mc = middle::mem_categorization;
 use middle::lint;
 use middle::const_eval;
+use middle::def;
 use middle::dependency_format;
 use middle::lang_items::{ExchangeHeapLangItem, OpaqueStructLangItem};
 use middle::lang_items::{TyDescStructLangItem, TyVisitorTraitLangItem};
@@ -2945,7 +2946,7 @@ pub fn method_call_type_param_defs(tcx: &ctxt, origin: typeck::MethodOrigin)
     }
 }
 
-pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> ast::Def {
+pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> def::Def {
     match tcx.def_map.borrow().find(&expr.id) {
         Some(&def) => def,
         None => {
@@ -2993,7 +2994,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
     match expr.node {
         ast::ExprPath(..) => {
             match resolve_expr(tcx, expr) {
-                ast::DefVariant(tid, vid, _) => {
+                def::DefVariant(tid, vid, _) => {
                     let variant_info = enum_variant_with_id(tcx, tid, vid);
                     if variant_info.args.len() > 0u {
                         // N-ary variant.
@@ -3004,7 +3005,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
                     }
                 }
 
-                ast::DefStruct(_) => {
+                def::DefStruct(_) => {
                     match get(expr_ty(tcx, expr)).sty {
                         ty_bare_fn(..) => RvalueDatumExpr,
                         _ => RvalueDpsExpr
@@ -3012,16 +3013,16 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
                 }
 
                 // Fn pointers are just scalar values.
-                ast::DefFn(..) | ast::DefStaticMethod(..) => RvalueDatumExpr,
+                def::DefFn(..) | def::DefStaticMethod(..) => RvalueDatumExpr,
 
                 // Note: there is actually a good case to be made that
                 // DefArg's, particularly those of immediate type, ought to
                 // considered rvalues.
-                ast::DefStatic(..) |
-                ast::DefBinding(..) |
-                ast::DefUpvar(..) |
-                ast::DefArg(..) |
-                ast::DefLocal(..) => LvalueExpr,
+                def::DefStatic(..) |
+                def::DefBinding(..) |
+                def::DefUpvar(..) |
+                def::DefArg(..) |
+                def::DefLocal(..) => LvalueExpr,
 
                 def => {
                     tcx.sess.span_bug(
@@ -3112,7 +3113,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
                 Some(&def) => def,
                 None => fail!("no def for place"),
             };
-            let def_id = ast_util::def_id_of_def(definition);
+            let def_id = definition.def_id();
             match tcx.lang_items.items.get(ExchangeHeapLangItem as uint) {
                 &Some(item_def_id) if def_id == item_def_id => {
                     RvalueDatumExpr
@@ -3534,7 +3535,7 @@ pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId {
     let def = *tcx.def_map.borrow()
                      .find(&tr.ref_id)
                      .expect("no def-map entry for trait");
-    ast_util::def_id_of_def(def)
+    def.def_id()
 }
 
 pub fn try_add_builtin_trait(tcx: &ctxt,
index 35cfbdeb344e040186cded120ddefe6764384056..f8821a86e717770d56cfa39cc6c851c2c672da92 100644 (file)
@@ -49,8 +49,8 @@
  * an rptr (`&r.T`) use the region `r` that appears in the rptr.
  */
 
-
 use middle::const_eval;
+use middle::def;
 use middle::subst;
 use middle::subst::{Subst, Substs};
 use middle::ty::{ty_param_substs_and_ty};
@@ -329,7 +329,7 @@ pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option<ty::t> {
                 Some(&d) => d
             };
             match a_def {
-                ast::DefPrimTy(nty) => {
+                def::DefPrimTy(nty) => {
                     match nty {
                         ast::TyBool => {
                             check_path_args(tcx, path, NO_TPS | NO_REGIONS);
@@ -402,7 +402,7 @@ pub fn ast_ty_to_builtin_ty<AC:AstConv,
             // FIXME(#12938): This is a hack until we have full support for
             // DST.
             match a_def {
-                ast::DefTy(did) | ast::DefStruct(did)
+                def::DefTy(did) | def::DefStruct(did)
                         if Some(did) == this.tcx().lang_items.owned_box() => {
                     if path.segments
                            .iter()
@@ -496,7 +496,7 @@ fn mk_pointer<AC:AstConv,
             // restriction is enforced in the below case for ty_path, which
             // will run after this as long as the path isn't a trait.
             match tcx.def_map.borrow().find(&id) {
-                Some(&ast::DefPrimTy(ast::TyStr)) => {
+                Some(&def::DefPrimTy(ast::TyStr)) => {
                     check_path_args(tcx, path, NO_TPS | NO_REGIONS);
                     match ptr_ty {
                         Uniq => {
@@ -512,7 +512,7 @@ fn mk_pointer<AC:AstConv,
                         }
                     }
                 }
-                Some(&ast::DefTrait(trait_def_id)) => {
+                Some(&def::DefTrait(trait_def_id)) => {
                     let result = ast_path_to_trait_ref(
                         this, rscope, trait_def_id, None, path);
                     let trait_store = match ptr_ty {
@@ -661,14 +661,14 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
                 // Kind bounds on path types are only supported for traits.
                 match a_def {
                     // But don't emit the error if the user meant to do a trait anyway.
-                    ast::DefTrait(..) => { },
+                    def::DefTrait(..) => { },
                     _ if bounds.is_some() =>
                         tcx.sess.span_err(ast_ty.span,
                                           "kind bounds can only be used on trait types"),
                     _ => { },
                 }
                 match a_def {
-                    ast::DefTrait(_) => {
+                    def::DefTrait(_) => {
                         let path_str = path_to_str(path);
                         tcx.sess.span_err(
                             ast_ty.span,
@@ -678,14 +678,14 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
                                     name=path_str).as_slice());
                         ty::mk_err()
                     }
-                    ast::DefTy(did) | ast::DefStruct(did) => {
+                    def::DefTy(did) | def::DefStruct(did) => {
                         ast_path_to_ty(this, rscope, did, path).ty
                     }
-                    ast::DefTyParam(id, n) => {
+                    def::DefTyParam(id, n) => {
                         check_path_args(tcx, path, NO_TPS | NO_REGIONS);
                         ty::mk_param(tcx, n, id)
                     }
-                    ast::DefSelfTy(id) => {
+                    def::DefSelfTy(id) => {
                         // n.b.: resolve guarantees that the this type only appears in a
                         // trait, which we rely upon in various places when creating
                         // substs
@@ -693,12 +693,12 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
                         let did = ast_util::local_def(id);
                         ty::mk_self(tcx, did)
                     }
-                    ast::DefMod(id) => {
+                    def::DefMod(id) => {
                         tcx.sess.span_fatal(ast_ty.span,
                             format!("found module name used as a type: {}",
                                     tcx.map.node_to_str(id.node)).as_slice());
                     }
-                    ast::DefPrimTy(_) => {
+                    def::DefPrimTy(_) => {
                         fail!("DefPrimTy arm missed in previous ast_ty_to_prim_ty call");
                     }
                     _ => {
@@ -912,7 +912,7 @@ fn conv_builtin_bounds(tcx: &ty::ctxt, ast_bounds: &Option<OwnedSlice<ast::TyPar
                 match *ast_bound {
                     ast::TraitTyParamBound(ref b) => {
                         match lookup_def_tcx(tcx, b.path.span, b.ref_id) {
-                            ast::DefTrait(trait_did) => {
+                            def::DefTrait(trait_did) => {
                                 if ty::try_add_builtin_trait(tcx, trait_did,
                                                              &mut builtin_bounds) {
                                     continue; // success
index cccb40be5ae52c951a0f41ba10e5e18c775a1088..df774b215042b6cccd73a6740b4797873643ccf4 100644 (file)
@@ -10,6 +10,7 @@
 
 #![allow(non_camel_case_types)]
 
+use middle::def;
 use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding, pat_is_const};
 use middle::subst;
 use middle::subst::Subst;
@@ -128,7 +129,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
         ty::ty_enum(_, ref expected_substs) => {
             // Lookup the enum and variant def ids:
             let v_def = lookup_def(pcx.fcx, pat.span, pat.id);
-            match ast_util::variant_def_ids(v_def) {
+            match v_def.variant_def_ids() {
                 Some((enm, var)) => {
                     // Assign the pattern the type of the *enum*, not the variant.
                     let enum_tpt = ty::lookup_item_type(tcx, enm);
@@ -188,7 +189,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
         ty::ty_struct(struct_def_id, ref expected_substs) => {
             // Lookup the struct ctor def id
             let s_def = lookup_def(pcx.fcx, pat.span, pat.id);
-            let s_def_id = ast_util::def_id_of_def(s_def);
+            let s_def_id = s_def.def_id();
 
             // Assign the pattern the type of the struct.
             let ctor_tpt = ty::lookup_item_type(tcx, s_def_id);
@@ -372,11 +373,11 @@ pub fn check_struct_pat(pcx: &pat_ctxt, pat_id: ast::NodeId, span: Span,
 
     // Check to ensure that the struct is the one specified.
     match tcx.def_map.borrow().find(&pat_id) {
-        Some(&ast::DefStruct(supplied_def_id))
+        Some(&def::DefStruct(supplied_def_id))
                 if supplied_def_id == struct_id => {
             // OK.
         }
-        Some(&ast::DefStruct(..)) | Some(&ast::DefVariant(..)) => {
+        Some(&def::DefStruct(..)) | Some(&def::DefVariant(..)) => {
             let name = pprust::path_to_str(path);
             tcx.sess
                .span_err(span,
@@ -408,7 +409,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
 
     // Find the variant that was specified.
     match tcx.def_map.borrow().find(&pat_id) {
-        Some(&ast::DefVariant(found_enum_id, variant_id, _))
+        Some(&def::DefVariant(found_enum_id, variant_id, _))
                 if found_enum_id == enum_id => {
             // Get the struct fields from this struct-like enum variant.
             let class_fields = ty::lookup_struct_fields(tcx, variant_id);
@@ -416,7 +417,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
             check_struct_pat_fields(pcx, span, fields, class_fields,
                                     variant_id, substitutions, etc);
         }
-        Some(&ast::DefStruct(..)) | Some(&ast::DefVariant(..)) => {
+        Some(&def::DefStruct(..)) | Some(&def::DefVariant(..)) => {
             let name = pprust::path_to_str(path);
             tcx.sess.span_err(span,
                               format!("mismatched types: expected `{}` but \
@@ -477,8 +478,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
       }
       ast::PatEnum(..) |
       ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => {
-        let const_did = ast_util::def_id_of_def(tcx.def_map.borrow()
-                                                   .get_copy(&pat.id));
+        let const_did = tcx.def_map.borrow().get_copy(&pat.id).def_id();
         let const_tpt = ty::lookup_item_type(tcx, const_did);
         demand::suptype(fcx, pat.span, expected, const_tpt.ty);
         fcx.write_ty(pat.id, const_tpt.ty);
@@ -558,7 +558,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
                             "a structure pattern".to_string(),
                             None);
                 match tcx.def_map.borrow().find(&pat.id) {
-                    Some(&ast::DefStruct(supplied_def_id)) => {
+                    Some(&def::DefStruct(supplied_def_id)) => {
                          check_struct_pat(pcx,
                                           pat.id,
                                           pat.span,
index a2bf979180ffec9cbc21de136c0c7baf8c22c3d8..a09c92d4db01fa29765cd0a52a35fce0af711060 100644 (file)
@@ -78,6 +78,7 @@
 
 
 use middle::const_eval;
+use middle::def;
 use middle::lang_items::{ExchangeHeapLangItem, GcLangItem};
 use middle::lang_items::{ManagedHeapLangItem};
 use middle::lint::UnreachableCode;
@@ -1523,13 +1524,13 @@ pub enum DerefArgs {
 // Given the provenance of a static method, returns the generics of the static
 // method's container.
 fn generics_of_static_method_container(type_context: &ty::ctxt,
-                                       provenance: ast::MethodProvenance)
+                                       provenance: def::MethodProvenance)
                                        -> ty::Generics {
     match provenance {
-        ast::FromTrait(trait_def_id) => {
+        def::FromTrait(trait_def_id) => {
             ty::lookup_trait_def(type_context, trait_def_id).generics.clone()
         }
-        ast::FromImpl(impl_def_id) => {
+        def::FromImpl(impl_def_id) => {
             ty::lookup_item_type(type_context, impl_def_id).generics.clone()
         }
     }
@@ -1539,7 +1540,7 @@ fn generics_of_static_method_container(type_context: &ty::ctxt,
 // locations.
 fn check_type_parameter_positions_in_path(function_context: &FnCtxt,
                                           path: &ast::Path,
-                                          def: ast::Def) {
+                                          def: def::Def) {
     // We only care about checking the case in which the path has two or
     // more segments.
     if path.segments.len() < 2 {
@@ -1580,13 +1581,13 @@ fn check_type_parameter_positions_in_path(function_context: &FnCtxt,
         // ensure that the segment of the path which names the trait or
         // implementation (the penultimate segment) is annotated with the
         // right number of type parameters.
-        ast::DefStaticMethod(_, provenance, _) => {
+        def::DefStaticMethod(_, provenance, _) => {
             let generics =
                 generics_of_static_method_container(function_context.ccx.tcx,
                                                     provenance);
             let name = match provenance {
-                ast::FromTrait(_) => "trait",
-                ast::FromImpl(_) => "impl",
+                def::FromTrait(_) => "trait",
+                def::FromImpl(_) => "impl",
             };
 
             let trait_segment = &path.segments.get(path.segments.len() - 2);
@@ -2706,7 +2707,7 @@ fn check_struct_enum_variant(fcx: &FnCtxt,
                   // FIXME(pcwalton): For now we hardcode the two permissible
                   // places: the exchange heap and the managed heap.
                   let definition = lookup_def(fcx, path.span, place.id);
-                  let def_id = ast_util::def_id_of_def(definition);
+                  let def_id = definition.def_id();
                   match tcx.lang_items
                            .items
                            .get(ExchangeHeapLangItem as uint) {
@@ -3256,11 +3257,11 @@ fn types_compatible(fcx: &FnCtxt, sp: Span,
         // Resolve the path.
         let def = tcx.def_map.borrow().find(&id).map(|i| *i);
         match def {
-            Some(ast::DefStruct(type_def_id)) => {
+            Some(def::DefStruct(type_def_id)) => {
                 check_struct_constructor(fcx, id, expr.span, type_def_id,
                                          fields.as_slice(), base_expr);
             }
-            Some(ast::DefVariant(enum_id, variant_id, _)) => {
+            Some(def::DefVariant(enum_id, variant_id, _)) => {
                 check_struct_enum_variant(fcx, id, expr.span, enum_id,
                                           variant_id, fields.as_slice());
             }
@@ -3809,54 +3810,54 @@ fn do_check(ccx: &CrateCtxt,
     check_instantiable(ccx.tcx, sp, id);
 }
 
-pub fn lookup_def(fcx: &FnCtxt, sp: Span, id: ast::NodeId) -> ast::Def {
+pub fn lookup_def(fcx: &FnCtxt, sp: Span, id: ast::NodeId) -> def::Def {
     lookup_def_ccx(fcx.ccx, sp, id)
 }
 
 // Returns the type parameter count and the type for the given definition.
 pub fn ty_param_bounds_and_ty_for_def(fcx: &FnCtxt,
                                       sp: Span,
-                                      defn: ast::Def)
+                                      defn: def::Def)
                                    -> ty_param_bounds_and_ty {
     match defn {
-      ast::DefArg(nid, _) | ast::DefLocal(nid, _) |
-      ast::DefBinding(nid, _) => {
+      def::DefArg(nid, _) | def::DefLocal(nid, _) |
+      def::DefBinding(nid, _) => {
           let typ = fcx.local_ty(sp, nid);
           return no_params(typ);
       }
-      ast::DefFn(id, _) | ast::DefStaticMethod(id, _, _) |
-      ast::DefStatic(id, _) | ast::DefVariant(_, id, _) |
-      ast::DefStruct(id) => {
+      def::DefFn(id, _) | def::DefStaticMethod(id, _, _) |
+      def::DefStatic(id, _) | def::DefVariant(_, id, _) |
+      def::DefStruct(id) => {
         return ty::lookup_item_type(fcx.ccx.tcx, id);
       }
-      ast::DefUpvar(_, inner, _, _) => {
+      def::DefUpvar(_, inner, _, _) => {
         return ty_param_bounds_and_ty_for_def(fcx, sp, *inner);
       }
-      ast::DefTrait(_) |
-      ast::DefTy(_) |
-      ast::DefPrimTy(_) |
-      ast::DefTyParam(..)=> {
+      def::DefTrait(_) |
+      def::DefTy(_) |
+      def::DefPrimTy(_) |
+      def::DefTyParam(..)=> {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type");
       }
-      ast::DefMod(..) | ast::DefForeignMod(..) => {
+      def::DefMod(..) | def::DefForeignMod(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found module");
       }
-      ast::DefUse(..) => {
+      def::DefUse(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found use");
       }
-      ast::DefRegion(..) => {
+      def::DefRegion(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found region");
       }
-      ast::DefTyParamBinder(..) => {
+      def::DefTyParamBinder(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type parameter");
       }
-      ast::DefLabel(..) => {
+      def::DefLabel(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found label");
       }
-      ast::DefSelfTy(..) => {
+      def::DefSelfTy(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found self ty");
       }
-      ast::DefMethod(..) => {
+      def::DefMethod(..) => {
         fcx.ccx.tcx.sess.span_bug(sp, "expected value but found method");
       }
     }
@@ -3867,7 +3868,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: &FnCtxt,
 pub fn instantiate_path(fcx: &FnCtxt,
                         pth: &ast::Path,
                         tpt: ty_param_bounds_and_ty,
-                        def: ast::Def,
+                        def: def::Def,
                         span: Span,
                         node_id: ast::NodeId) {
     debug!(">>> instantiate_path");
@@ -3918,7 +3919,7 @@ pub fn instantiate_path(fcx: &FnCtxt,
     // of type parameters actually manifest in the AST. This will differ from
     // the internal type parameter count when there are self types involved.
     let (user_ty_param_count, user_ty_param_req, self_parameter_index) = match def {
-        ast::DefStaticMethod(_, provenance @ ast::FromTrait(_), _) => {
+        def::DefStaticMethod(_, provenance @ def::FromTrait(_), _) => {
             let generics = generics_of_static_method_container(fcx.ccx.tcx,
                                                                provenance);
             (ty_param_count - 1, ty_param_req - 1, Some(generics.type_param_defs().len()))
@@ -4153,7 +4154,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: ast::P<ast::Block>) -> bool
         match e.node {
             ast::ExprBreak(Some(_)) => {
                 match cx.def_map.borrow().find(&e.id) {
-                    Some(&ast::DefLabel(loop_id)) if id == loop_id => true,
+                    Some(&def::DefLabel(loop_id)) if id == loop_id => true,
                     _ => false,
                 }
             }
index 34e8b5e169ff8f68c54a7566ba1ffeaad24d15ca..e1db465424af88946486e9362e1f09bed4082c93 100644 (file)
@@ -118,7 +118,8 @@ fn get_i(x: &'a Bar) -> &'a int {
 
 */
 
-
+use middle::def;
+use middle::def::{DefArg, DefBinding, DefLocal, DefUpvar};
 use middle::freevars;
 use mc = middle::mem_categorization;
 use middle::ty::{ReScope};
@@ -134,9 +135,7 @@ fn get_i(x: &'a Bar) -> &'a int {
 use util::nodemap::NodeMap;
 use util::ppaux::{ty_to_str, region_to_str, Repr};
 
-use syntax::ast::{DefArg, DefBinding, DefLocal, DefUpvar};
 use syntax::ast;
-use syntax::ast_util;
 use syntax::codemap::Span;
 use syntax::visit;
 use syntax::visit::Visitor;
@@ -163,7 +162,7 @@ pub struct Rcx<'a> {
     repeating_scope: ast::NodeId,
 }
 
-fn region_of_def(fcx: &FnCtxt, def: ast::Def) -> ty::Region {
+fn region_of_def(fcx: &FnCtxt, def: def::Def) -> ty::Region {
     /*!
      * Returns the validity region of `def` -- that is, how long
      * is `def` valid?
@@ -665,7 +664,7 @@ fn constrain_free_variables(rcx: &mut Rcx,
 
             // Identify the variable being closed over and its node-id.
             let def = freevar.def;
-            let def_id = ast_util::def_id_of_def(def);
+            let def_id = def.def_id();
             assert!(def_id.krate == ast::LOCAL_CRATE);
             let upvar_id = ty::UpvarId { var_id: def_id.node,
                                          closure_expr_id: expr.id };
@@ -725,7 +724,7 @@ fn propagate_upupvar_borrow_kind(rcx: &mut Rcx,
             // determining the final borrow_kind) and propagate that as
             // a constraint on the outer closure.
             match freevar.def {
-                ast::DefUpvar(var_id, _, outer_closure_id, _) => {
+                def::DefUpvar(var_id, _, outer_closure_id, _) => {
                     // thing being captured is itself an upvar:
                     let outer_upvar_id = ty::UpvarId {
                         var_id: var_id,
index 3f8d8285ae48af44cefefbe0d94be87ba4cfe547..2bbbf3102eac20a99488ba7dc94df5cc0f7f61e0 100644 (file)
@@ -632,7 +632,7 @@ fn mutability_allowed(a_mutbl: ast::Mutability,
             debug!("vtable resolution on parameter bounds for expr {}",
                    ex.repr(fcx.tcx()));
             let def = cx.tcx.def_map.borrow().get_copy(&ex.id);
-            let did = ast_util::def_id_of_def(def);
+            let did = def.def_id();
             let item_ty = ty::lookup_item_type(cx.tcx, did);
             debug!("early resolve expr: def {:?} {:?}, {:?}, {}", ex.id, did, def,
                    fcx.infcx().ty_to_str(item_ty.ty));
index 514bb85349efb0b30d98cf4f9452a3b987dd29a3..63dc122f7cbf64c3082ae050e15e631466a7df71 100644 (file)
@@ -12,7 +12,7 @@
 // unresolved type variables and replaces "ty_var" types with their
 // substitutions.
 
-
+use middle::def;
 use middle::pat_util;
 use middle::subst;
 use middle::ty;
@@ -232,10 +232,10 @@ fn visit_adjustments(&self, reason: ResolveReason, id: ast::NodeId) {
                         // bare functions to coerce to a closure to avoid
                         // constructing (slower) indirect call wrappers.
                         match self.tcx().def_map.borrow().find(&id) {
-                            Some(&ast::DefFn(..)) |
-                            Some(&ast::DefStaticMethod(..)) |
-                            Some(&ast::DefVariant(..)) |
-                            Some(&ast::DefStruct(_)) => {
+                            Some(&def::DefFn(..)) |
+                            Some(&def::DefStaticMethod(..)) |
+                            Some(&def::DefVariant(..)) |
+                            Some(&def::DefStruct(_)) => {
                             }
                             _ => {
                                 self.tcx().sess.span_err(
index f9729ff767684b0b3c380c7f8a07c657a255ab4a..99a6aad715ccbf548c9f1895e3a6b58f77a5651b 100644 (file)
 use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
 use middle::typeck::infer;
 use util::ppaux::Repr;
-use syntax::ast::{Crate, DefId, DefStruct, DefTy};
+use middle::def::{DefStruct, DefTy};
+use syntax::ast::{Crate, DefId};
 use syntax::ast::{Item, ItemEnum, ItemImpl, ItemMod, ItemStruct};
 use syntax::ast::{LOCAL_CRATE, TraitRef, TyPath};
 use syntax::ast;
 use syntax::ast_map::NodeItem;
 use syntax::ast_map;
-use syntax::ast_util::{def_id_of_def, local_def};
+use syntax::ast_util::{local_def};
 use syntax::codemap::Span;
 use syntax::parse::token;
 use syntax::visit;
@@ -543,7 +544,7 @@ fn check_privileged_scopes(&self, krate: &Crate) {
     fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId {
         let def_map = &self.crate_context.tcx.def_map;
         let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
-        let trait_id = def_id_of_def(trait_def);
+        let trait_id = trait_def.def_id();
         return trait_id;
     }
 
index a6478675a89b1d9647dd30001803c82f58f9e398..c6bc6ce72974052cc40b7143650ad0e8efa98547 100644 (file)
@@ -32,6 +32,7 @@
 
 
 use metadata::csearch;
+use middle::def;
 use middle::lang_items::SizedTraitLangItem;
 use middle::resolve_lifetime;
 use middle::subst;
@@ -740,7 +741,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
             ast::TyPath(_, _, path_id) => {
                 let def_map = tcx.def_map.borrow();
                 match def_map.find(&path_id) {
-                    Some(&ast::DefStruct(def_id)) => {
+                    Some(&def::DefStruct(def_id)) => {
                         // FIXME(#12511) Check for cycles in the inheritance hierarchy.
                         // Check super-struct is virtual.
                         match tcx.map.find(def_id.node) {
@@ -831,7 +832,7 @@ pub fn instantiate_trait_ref(ccx: &CrateCtxt,
     let rscope = ExplicitRscope;
 
     match lookup_def_tcx(ccx.tcx, ast_trait_ref.path.span, ast_trait_ref.ref_id) {
-        ast::DefTrait(trait_did) => {
+        def::DefTrait(trait_did) => {
             let trait_ref =
                 astconv::ast_path_to_trait_ref(
                     ccx, &rscope, trait_did, Some(self_ty), &ast_trait_ref.path);
index 5853de005748a60cde3d3a6f872e31d6ae185c08..6464b191b76911b431cdabbb970ef4af4d9ae57f 100644 (file)
@@ -60,6 +60,7 @@
 */
 
 use std::collections::HashSet;
+use middle::def;
 use middle::ty;
 use middle::ty::{Region, ReFree};
 use middle::typeck::infer;
@@ -1045,7 +1046,7 @@ fn rebuild_arg_ty_or_output(&self,
                         Some(&d) => d
                     };
                     match a_def {
-                        ast::DefTy(did) | ast::DefStruct(did) => {
+                        def::DefTy(did) | def::DefStruct(did) => {
                             let ty::ty_param_bounds_and_ty {
                                 generics: generics,
                                 ty: _
index d1c6618a9c0e2bca9c44aba0cdc91ff25dde2870..9bf6728c95ba325bd324337cabe2417d61d7113e 100644 (file)
@@ -63,6 +63,7 @@
 
 use driver::config;
 
+use middle::def;
 use middle::resolve;
 use middle::subst;
 use middle::ty;
@@ -266,7 +267,7 @@ pub fn write_substs_to_tcx(tcx: &ty::ctxt,
         tcx.item_substs.borrow_mut().insert(node_id, item_substs);
     }
 }
-pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> ast::Def {
+pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
     match tcx.def_map.borrow().find(&id) {
         Some(&x) => x,
         _ => {
@@ -276,7 +277,7 @@ pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> ast::Def {
 }
 
 pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
-                   -> ast::Def {
+                   -> def::Def {
     lookup_def_tcx(ccx.tcx, sp, id)
 }
 
index 9d8bfa8302c74504198d9d2bd280c05cdc158b8f..9db9a0e7612a6908a5f9bba2a5a11d59366c968d 100644 (file)
@@ -16,6 +16,7 @@
 
 use rustc::metadata::csearch;
 use rustc::metadata::decoder;
+use rustc::middle::def;
 use rustc::middle::ty;
 
 use core;
@@ -46,22 +47,22 @@ pub fn try_inline(id: ast::NodeId) -> Option<Vec<clean::Item>> {
         Some(def) => *def,
         None => return None,
     };
-    let did = ast_util::def_id_of_def(def);
+    let did = def.def_id();
     if ast_util::is_local(did) { return None }
     try_inline_def(&**cx, tcx, def)
 }
 
 fn try_inline_def(cx: &core::DocContext,
                   tcx: &ty::ctxt,
-                  def: ast::Def) -> Option<Vec<clean::Item>> {
+                  def: def::Def) -> Option<Vec<clean::Item>> {
     let mut ret = Vec::new();
-    let did = ast_util::def_id_of_def(def);
+    let did = def.def_id();
     let inner = match def {
-        ast::DefTrait(did) => {
+        def::DefTrait(did) => {
             record_extern_fqn(cx, did, clean::TypeTrait);
             clean::TraitItem(build_external_trait(tcx, did))
         }
-        ast::DefFn(did, style) => {
+        def::DefFn(did, style) => {
             // If this function is a tuple struct constructor, we just skip it
             if csearch::get_tuple_struct_definition_if_ctor(&tcx.sess.cstore,
                                                             did).is_some() {
@@ -70,20 +71,20 @@ fn try_inline_def(cx: &core::DocContext,
             record_extern_fqn(cx, did, clean::TypeFunction);
             clean::FunctionItem(build_external_function(tcx, did, style))
         }
-        ast::DefStruct(did) => {
+        def::DefStruct(did) => {
             record_extern_fqn(cx, did, clean::TypeStruct);
             ret.extend(build_impls(cx, tcx, did).move_iter());
             clean::StructItem(build_struct(tcx, did))
         }
-        ast::DefTy(did) => {
+        def::DefTy(did) => {
             record_extern_fqn(cx, did, clean::TypeEnum);
             ret.extend(build_impls(cx, tcx, did).move_iter());
             build_type(tcx, did)
         }
         // Assume that the enum type is reexported next to the variant, and
         // variants don't show up in documentation specially.
-        ast::DefVariant(..) => return Some(Vec::new()),
-        ast::DefMod(did) => {
+        def::DefVariant(..) => return Some(Vec::new()),
+        def::DefMod(did) => {
             record_extern_fqn(cx, did, clean::TypeModule);
             clean::ModuleItem(build_module(cx, tcx, did))
         }
@@ -248,7 +249,7 @@ fn populate_impls(cx: &core::DocContext,
                           impls: &mut Vec<Option<clean::Item>>) {
             match def {
                 decoder::DlImpl(did) => impls.push(build_impl(cx, tcx, did)),
-                decoder::DlDef(ast::DefMod(did)) => {
+                decoder::DlDef(def::DefMod(did)) => {
                     csearch::each_child_of_item(&tcx.sess.cstore,
                                                 did,
                                                 |def, _, _| {
index 70c90b67d78643c110a4934cc113841a6c944126..3cb5c663c4ea5a4d64db78b9c57b2b639baf7fb1 100644 (file)
@@ -25,6 +25,7 @@
 use rustc::metadata::cstore;
 use rustc::metadata::csearch;
 use rustc::metadata::decoder;
+use rustc::middle::def;
 use rustc::middle::subst;
 use rustc::middle::ty;
 
@@ -191,7 +192,7 @@ fn clean(&self) -> ExternalCrate {
                                                       self.cnum,
                                                       |def, _, _| {
                     let did = match def {
-                        decoder::DlDef(ast::DefMod(did)) => did,
+                        decoder::DlDef(def::DefMod(did)) => did,
                         _ => return
                     };
                     let attrs = inline::load_attrs(tcx, did);
@@ -1949,8 +1950,8 @@ fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound>>,
     };
 
     match def {
-        ast::DefSelfTy(i) => return Self(ast_util::local_def(i)),
-        ast::DefPrimTy(p) => match p {
+        def::DefSelfTy(i) => return Self(ast_util::local_def(i)),
+        def::DefPrimTy(p) => match p {
             ast::TyStr => return Primitive(Str),
             ast::TyBool => return Primitive(Bool),
             ast::TyChar => return Primitive(Char),
@@ -1968,24 +1969,24 @@ fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound>>,
             ast::TyFloat(ast::TyF64) => return Primitive(F64),
             ast::TyFloat(ast::TyF128) => return Primitive(F128),
         },
-        ast::DefTyParam(i, _) => return Generic(i),
-        ast::DefTyParamBinder(i) => return TyParamBinder(i),
+        def::DefTyParam(i, _) => return Generic(i),
+        def::DefTyParamBinder(i) => return TyParamBinder(i),
         _ => {}
     };
     let did = register_def(&**cx, def);
     ResolvedPath { path: path, typarams: tpbs, did: did }
 }
 
-fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
+fn register_def(cx: &core::DocContext, def: def::Def) -> ast::DefId {
     let (did, kind) = match def {
-        ast::DefFn(i, _) => (i, TypeFunction),
-        ast::DefTy(i) => (i, TypeEnum),
-        ast::DefTrait(i) => (i, TypeTrait),
-        ast::DefStruct(i) => (i, TypeStruct),
-        ast::DefMod(i) => (i, TypeModule),
-        ast::DefStatic(i, _) => (i, TypeStatic),
-        ast::DefVariant(i, _, _) => (i, TypeEnum),
-        _ => return ast_util::def_id_of_def(def),
+        def::DefFn(i, _) => (i, TypeFunction),
+        def::DefTy(i) => (i, TypeEnum),
+        def::DefTrait(i) => (i, TypeTrait),
+        def::DefStruct(i) => (i, TypeStruct),
+        def::DefMod(i) => (i, TypeModule),
+        def::DefStatic(i, _) => (i, TypeStatic),
+        def::DefVariant(i, _, _) => (i, TypeEnum),
+        _ => return def.def_id()
     };
     if ast_util::is_local(did) { return did }
     let tcx = match cx.maybe_typed {
index 9f1ad02decd128ed0522a25fe0e787bf454efce2..da9169d70fd3c9f5a37395e388f20a63055459d6 100644 (file)
@@ -195,7 +195,7 @@ fn resolve_id(&mut self, id: ast::NodeId, glob: bool,
             core::Typed(ref tcx) => tcx,
             core::NotTyped(_) => return false
         };
-        let def = ast_util::def_id_of_def(*tcx.def_map.borrow().get(&id));
+        let def = tcx.def_map.borrow().get(&id).def_id();
         if !ast_util::is_local(def) { return false }
         let analysis = match self.analysis {
             Some(analysis) => analysis, None => return false
index 9cbe7e0b5fce582755ae0a41fd4a234f631f4360..2bc24fd1eb36994fa3801ed3cbfc6b6ebea0b044 100644 (file)
@@ -206,49 +206,6 @@ pub fn is_type_parameterized(&self) -> bool {
     }
 }
 
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
-pub enum MethodProvenance {
-    FromTrait(DefId),
-    FromImpl(DefId),
-}
-
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
-pub enum Def {
-    DefFn(DefId, FnStyle),
-    DefStaticMethod(/* method */ DefId, MethodProvenance, FnStyle),
-    DefSelfTy(/* trait id */ NodeId),
-    DefMod(DefId),
-    DefForeignMod(DefId),
-    DefStatic(DefId, bool /* is_mutbl */),
-    DefArg(NodeId, BindingMode),
-    DefLocal(NodeId, BindingMode),
-    DefVariant(DefId /* enum */, DefId /* variant */, bool /* is_structure */),
-    DefTy(DefId),
-    DefTrait(DefId),
-    DefPrimTy(PrimTy),
-    DefTyParam(DefId, uint),
-    DefBinding(NodeId, BindingMode),
-    DefUse(DefId),
-    DefUpvar(NodeId,  // id of closed over var
-              @Def,     // closed over def
-              NodeId,  // expr node that creates the closure
-              NodeId), // id for the block/body of the closure expr
-
-    /// Note that if it's a tuple struct's definition, the node id of the DefId
-    /// may either refer to the item definition's id or the StructDef.ctor_id.
-    ///
-    /// The cases that I have encountered so far are (this is not exhaustive):
-    /// - If it's a ty_path referring to some tuple struct, then DefMap maps
-    ///   it to a def whose id is the item definition's id.
-    /// - If it's an ExprPath referring to some tuple struct, then DefMap maps
-    ///   it to a def whose id is the StructDef.ctor_id.
-    DefStruct(DefId),
-    DefTyParamBinder(NodeId), /* struct, impl or trait with ty params */
-    DefRegion(NodeId),
-    DefLabel(NodeId),
-    DefMethod(DefId /* method */, Option<DefId> /* trait */),
-}
-
 #[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)]
 pub enum DefRegion {
     DefStaticRegion,
index e4f2f7f26cf0da1c328147bb919527a24ef56af4..a1ad3cc14c5180fa13cc7ca4ebcf099372a74f42 100644 (file)
@@ -52,33 +52,6 @@ pub fn stmt_id(s: &Stmt) -> NodeId {
     }
 }
 
-pub fn variant_def_ids(d: Def) -> Option<(DefId, DefId)> {
-    match d {
-      DefVariant(enum_id, var_id, _) => {
-          Some((enum_id, var_id))
-      }
-      _ => None
-    }
-}
-
-pub fn def_id_of_def(d: Def) -> DefId {
-    match d {
-        DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) |
-        DefForeignMod(id) | DefStatic(id, _) |
-        DefVariant(_, id, _) | DefTy(id) | DefTyParam(id, _) |
-        DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => {
-            id
-        }
-        DefArg(id, _) | DefLocal(id, _) | DefSelfTy(id)
-        | DefUpvar(id, _, _, _) | DefBinding(id, _) | DefRegion(id)
-        | DefTyParamBinder(id) | DefLabel(id) => {
-            local_def(id)
-        }
-
-        DefPrimTy(_) => fail!()
-    }
-}
-
 pub fn binop_to_str(op: BinOp) -> &'static str {
     match op {
         BiAdd => "+",