extern crate log;
pub mod middle {
+ pub mod def;
pub mod trans;
pub mod ty;
pub mod ty_fold;
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;
-> 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 };
// 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,
}
// Something that a name can resolve to.
#[deriving(Clone)]
pub enum DefLike {
- DlDef(ast::Def),
+ DlDef(def::Def),
DlImpl(ast::DefId),
DlField
}
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.
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;
// ______________________________________________________________________
// 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))
}
}
}
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;
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,
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)
}
// except according to those terms.
use middle::cfg::*;
+use middle::def;
use middle::graph;
use middle::typeck;
use middle::ty;
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;
use driver::session::Session;
+use middle::def::*;
use middle::resolve;
use middle::ty;
use middle::typeck;
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;
use metadata::csearch;
use middle::astencode;
+use middle::def;
use middle::ty;
use middle::typeck::astconv;
use util::nodemap::{DefIdMap};
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
*/
+use middle::def;
+use middle::ty;
+use middle::typeck;
use std::io;
use std::string::String;
use std::uint;
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;
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 => {
// 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;
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;
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),
--- /dev/null
+// 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
+ }
+ }
+}
//! 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;
}
ast::ExprPath(..) => {
match ty::resolve_expr(self.tcx, expr) {
- ast::DefStatic(_, true) => {
+ def::DefStatic(_, true) => {
self.require_unsafe(expr.span, "use of mutable static")
}
_ => {}
*/
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;
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));
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)
}
#![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;
// (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>>;
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,
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.
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!");
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);
}
_ => {
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);
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.
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()
}
_ => {
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
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`
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 \
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);
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);
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
}
}
* to return explicitly.
*/
-
+use middle::def::*;
use middle::freevars;
use middle::lint::{UnusedVariable, DeadAssignment};
use middle::pat_util;
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
#![allow(non_camel_case_types)]
+use middle::def;
use middle::ty;
use middle::typeck;
use util::nodemap::NodeMap;
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,
}))
}
- ast::DefStatic(_, true) => {
+ def::DefStatic(_, true) => {
Ok(Rc::new(cmt_ {
id:id,
span:span,
}))
}
- 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`?
}))
}
- 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) => {
}
}
- 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,
}
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 = {
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 =
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)));
}
// 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;
use std::mem::replace;
use metadata::csearch;
+use middle::def;
use middle::lint;
use middle::resolve;
use middle::ty;
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;
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)
}
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);
}
_ => 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,
.last()
.unwrap()
.identifier);
- let origdid = def_id_of_def(orig_def);
+ let origdid = orig_def.def_id();
self.ensure_public(span,
def,
Some(origdid),
// 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"),
_ => {}
}
}
}
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));
}
};
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 {
}
// 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),
}
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));
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...
// reachable as well.
use driver::config;
+use middle::def;
use middle::ty;
use middle::typeck;
use middle::privacy;
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;
}
};
- 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)
// 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);
}
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;
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;
}
};
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) |
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
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,
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 => {
}
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, _) => {
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
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);
}
* 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>)
* - `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>,
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;
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 {
}
unreachable!();
}
- ast::DefFn(..) |
- ast::DefStruct(_) => {
+ def::DefFn(..) |
+ def::DefStruct(_) => {
return lit(UnitLikeStructLit(pat_id));
}
_ => {
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 {
// 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;
}
_ => {
// 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)));
}
// 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)));
}
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
}
}
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,
}
}
}
- 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.
}
}
}
- Some(ast::DefStatic(_, false)) => {
+ Some(def::DefStatic(_, false)) => {
}
_ => {
// Nothing to do here.
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;
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 {:?} \
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::*;
use arena::TypedArena;
use syntax::ast;
-use syntax::ast_util;
// ___Good to know (tm)__________________________________________________
//
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);
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 \
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");
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;
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 => {
use metadata::csearch;
use middle::const_eval;
+use middle::def;
use middle::trans::adt;
use middle::trans::base;
use middle::trans::base::push_ctxt;
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)
(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(),
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)
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(),
use lib::llvm::*;
use driver::config::FullDebugInfo;
+use middle::def;
use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
use middle::trans::base::*;
use middle::trans::build::*;
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())
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;
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)
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");
};
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.
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) => {
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)
}
}
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.
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) {
}
}
}
- 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)
}
_ => {
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,
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};
}
}
-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 => {
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.
}
}
- ast::DefStruct(_) => {
+ def::DefStruct(_) => {
match get(expr_ty(tcx, expr)).sty {
ty_bare_fn(..) => RvalueDatumExpr,
_ => RvalueDpsExpr
}
// 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(
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
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,
* 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};
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);
// 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()
// 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 => {
}
}
}
- 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 {
// 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,
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
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");
}
_ => {
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
#![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;
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);
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);
// 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,
// 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);
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 \
}
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);
"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,
use middle::const_eval;
+use middle::def;
use middle::lang_items::{ExchangeHeapLangItem, GcLangItem};
use middle::lang_items::{ManagedHeapLangItem};
use middle::lint::UnreachableCode;
// 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()
}
}
// 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 {
// 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);
// 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) {
// 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());
}
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");
}
}
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");
// 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()))
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,
}
}
*/
-
+use middle::def;
+use middle::def::{DefArg, DefBinding, DefLocal, DefUpvar};
use middle::freevars;
use mc = middle::mem_categorization;
use middle::ty::{ReScope};
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;
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?
// 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 };
// 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,
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));
// unresolved type variables and replaces "ty_var" types with their
// substitutions.
-
+use middle::def;
use middle::pat_util;
use middle::subst;
use middle::ty;
// 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(
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;
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;
}
use metadata::csearch;
+use middle::def;
use middle::lang_items::SizedTraitLangItem;
use middle::resolve_lifetime;
use middle::subst;
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) {
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);
*/
use std::collections::HashSet;
+use middle::def;
use middle::ty;
use middle::ty::{Region, ReFree};
use middle::typeck::infer;
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: _
use driver::config;
+use middle::def;
use middle::resolve;
use middle::subst;
use middle::ty;
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,
_ => {
}
pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
- -> ast::Def {
+ -> def::Def {
lookup_def_tcx(ccx.tcx, sp, id)
}
use rustc::metadata::csearch;
use rustc::metadata::decoder;
+use rustc::middle::def;
use rustc::middle::ty;
use core;
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() {
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))
}
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, _, _| {
use rustc::metadata::cstore;
use rustc::metadata::csearch;
use rustc::metadata::decoder;
+use rustc::middle::def;
use rustc::middle::subst;
use rustc::middle::ty;
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);
};
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),
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 {
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
}
}
-#[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,
}
}
-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 => "+",