diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 17e659e5391..1b17cfb1bae 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -46,6 +46,7 @@ extern crate time; extern crate log; pub mod middle { + pub mod def; pub mod trans; pub mod ty; pub mod ty_fold; diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 30b40369c10..6469462734e 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -22,6 +22,7 @@ use metadata::tydecode::{parse_ty_data, parse_def_id, 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 } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 61dfde38c28..2cc06f7a32d 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1631,7 +1631,7 @@ impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> { 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. diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 9706ca578f7..f0caf0e7fe8 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -16,6 +16,7 @@ use c = metadata::common; 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)) } } } diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 0fbcf157dac..5706d249c46 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -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 @@ impl<'a> BorrowckCtxt<'a> { 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 @@ impl<'a> BorrowckCtxt<'a> { 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) } diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index e2b4dde577a..4a36e84fbe5 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -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 @@ impl<'a> CFGBuilder<'a> { 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; diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 64b7977c235..2bb7d0bc5c8 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -10,6 +10,7 @@ use driver::session::Session; +use middle::def::*; use middle::resolve; use middle::ty; use middle::typeck; diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 26bc845a15a..39a35e3adfa 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -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; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index e7ad08d4eb2..ca94cf24850 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -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>(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 diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 30792da84e0..3eec3c7e881 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -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; 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 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> { 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 => { diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index d3d5eb3f8fd..fb19fbd70c6 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -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 util::nodemap::NodeSet; 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 @@ impl<'a> MarkSymbolVisitor<'a> { 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 index 00000000000..ca89439eaba --- /dev/null +++ b/src/librustc/middle/def.rs @@ -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 or the MIT license +// , 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 /* 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 + } + } +} diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index bc9a1c9b5fc..c75d793cba6 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -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 @@ impl<'a> Visitor<()> for EffectCheckVisitor<'a> { } ast::ExprPath(..) => { match ty::resolve_expr(self.tcx, expr) { - ast::DefStatic(_, true) => { + def::DefStatic(_, true) => { self.require_unsafe(expr.span, "use of mutable static") } _ => {} diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index cd71d95bee9..c44ea0ae78b 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -15,12 +15,12 @@ */ 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 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> { 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 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> { fn cat_captured_var(&mut self, closure_id: ast::NodeId, closure_span: Span, - upvar_def: ast::Def) + upvar_def: def::Def) -> mc::McResult { // 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) } diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 47523f4f750..614972f3d57 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -13,12 +13,13 @@ #![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>; @@ -64,13 +65,13 @@ impl<'a> Visitor for CollectFreevarsVisitor<'a> { 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, diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index fe57e54c778..39f2e842583 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -21,7 +21,7 @@ use syntax::ast::*; 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 with_appropriate_checker(cx: &Context, 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 diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 871a336479d..cae8436d6df 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -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_item_ctypes(cx: &Context, it: &ast::Item) { 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 } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index b5cb0f8e5aa..8b1de130053 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -102,7 +102,7 @@ * 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 diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 240212699e4..06e0a125772 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { id: ast::NodeId, span: Span, expr_ty: ty::t, - def: ast::Def) + def: def::Def) -> McResult { 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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { })) } - ast::DefStatic(_, true) => { + def::DefStatic(_, true) => { Ok(Rc::new(cmt_ { id:id, span:span, @@ -522,7 +523,7 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { })) } - 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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { })) } - 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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { } } - 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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { } 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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { 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 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { 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))); } diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 49437a90e3f..44ed0192d1d 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -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; diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 5b47336efe5..fcd6d424659 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -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 util::nodemap::{NodeMap, NodeSet}; 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 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> { 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 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> { 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 @@ impl<'a> PrivacyVisitor<'a> { _ => 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 @@ impl<'a> PrivacyVisitor<'a> { .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 @@ impl<'a> PrivacyVisitor<'a> { // 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 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { } 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 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { } }; 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 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { } // 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 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { } 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... diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index a725ac960f8..ef2f78de8f9 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -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 std::collections::HashSet; 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 @@ impl<'a> Visitor<()> for ReachableContext<'a> { } }; - 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 @@ impl<'a> Visitor<()> for ReachableContext<'a> { // 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); } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 2228c21b239..f4962c9083a 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -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 util::nodemap::{NodeMap, DefIdSet, FnvHashMap}; 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 @@ impl<'a> Resolver<'a> { } }; 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 @@ impl<'a> Resolver<'a> { 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 @@ impl<'a> Resolver<'a> { 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 @@ impl<'a> Resolver<'a> { 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 @@ impl<'a> Resolver<'a> { } 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 @@ impl<'a> Resolver<'a> { 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 @@ impl<'a> Resolver<'a> { 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); } diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index a34fb0a99e1..c581dda3164 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -24,7 +24,7 @@ use syntax::codemap::Span; * 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) @@ -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, pub tps: Vec, diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 1cf8a301d80..2a3ec63e995 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -198,6 +198,7 @@ use back::abi; 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 get_options(bcx: &Block, m: &[Match], col: uint) -> Vec { // 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 get_options(bcx: &Block, m: &[Match], col: uint) -> Vec { // 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. diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index a488770689d..005fc446888 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -21,6 +21,7 @@ use driver::session; 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 trans<'a>(bcx: &'a Block<'a>, expr: &ast::Expr) -> 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 {:?} \ diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 9ca66f4c3b0..b5fd37d815f 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -13,6 +13,7 @@ use back::abi; 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 util::ppaux::ty_to_str; 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"); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 46c5edf5f5b..dbb6f3fe1cf 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -17,6 +17,7 @@ use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef}; 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 @@ impl<'a> Block<'a> { 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 => { diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 8b43e99b6ac..ac6e9ca6c64 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -17,6 +17,7 @@ use lib::llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, In 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(), diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index eac7af56ed4..ea152c34808 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -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()) diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 6241c1222f9..d9ae9b08381 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -37,6 +37,7 @@ use back::abi; 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 { /*! * 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(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, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index c47abf5fb73..6275abdc8ab 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -16,6 +16,7 @@ use metadata::csearch; 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, diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 35cfbdeb344..f8821a86e71 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -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 { 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 { if path.segments .iter() @@ -496,7 +496,7 @@ fn mk_pointer { + 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 { + 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( // 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( 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( 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 { 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 diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index cccb40be5ae..df774b21504 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -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, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index a2bf979180f..a09c92d4db0 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -78,6 +78,7 @@ type parameter). 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_expr_with_unifier(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 check_expr_with_unifier(fcx: &FnCtxt, // 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 @@ pub fn check_enum_variants(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) -> 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, } } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 34e8b5e169f..e1db465424a 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -118,7 +118,8 @@ and report an error, and it just seems like more mess in the end.) */ - +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 @@ use middle::pat_util; 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 check_expr_fn_block(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 check_expr_fn_block(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, diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 3f8d8285ae4..2bbbf3102ea 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -632,7 +632,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { 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)); diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 514bb85349e..63dc122f7cb 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -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 @@ impl<'cx> WritebackCx<'cx> { // 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( diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index f9729ff7676..99a6aad715c 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -35,13 +35,14 @@ use middle::typeck::infer::InferCtxt; 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 @@ impl<'a> CoherenceChecker<'a> { 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; } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index a6478675a89..c6bc6ce7297 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -32,6 +32,7 @@ are represented as `ty_param()` instances. 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); diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 5853de00574..6464b191b76 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -60,6 +60,7 @@ time of error detection. */ use std::collections::HashSet; +use middle::def; use middle::ty; use middle::ty::{Region, ReFree}; use middle::typeck::infer; @@ -1045,7 +1046,7 @@ impl<'a> Rebuilder<'a> { 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: _ diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index d1c6618a9c0..9bf6728c95b 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -63,6 +63,7 @@ independently: 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) } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 9d8bfa8302c..9db9a0e7612 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -16,6 +16,7 @@ use syntax::attr::AttrMetaMethods; 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> { 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> { + def: def::Def) -> Option> { 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 build_impls(cx: &core::DocContext, impls: &mut Vec>) { 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, _, _| { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 70c90b67d78..3cb5c663c4e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -25,6 +25,7 @@ use rustc::driver::driver; 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 @@ impl Clean for cstore::crate_metadata { 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>, }; 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>, 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 { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 9f1ad02decd..da9169d70fd 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -195,7 +195,7 @@ impl<'a> RustdocVisitor<'a> { 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 diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9cbe7e0b5fc..2bc24fd1eb3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -206,49 +206,6 @@ impl Generics { } } -#[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 /* trait */), -} - #[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)] pub enum DefRegion { DefStaticRegion, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index e4f2f7f26cf..a1ad3cc14c5 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -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 => "+",