rustc_metadata: move more RBML tags to auto-serialization.
This commit is contained in:
parent
88c5679c4e
commit
8734aaa33e
40 changed files with 1084 additions and 2139 deletions
|
@ -103,18 +103,13 @@ pub enum DepNode<D: Clone + Debug> {
|
|||
// table in the tcx (or elsewhere) maps to one of these
|
||||
// nodes. Often we map multiple tables to the same node if there
|
||||
// is no point in distinguishing them (e.g., both the type and
|
||||
// predicates for an item wind up in `ItemSignature`). Other
|
||||
// times, such as `ImplItems` vs `TraitItemDefIds`, tables which
|
||||
// might be mergable are kept distinct because the sets of def-ids
|
||||
// to which they apply are disjoint, and hence we might as well
|
||||
// have distinct labels for easier debugging.
|
||||
// predicates for an item wind up in `ItemSignature`).
|
||||
ImplOrTraitItems(D),
|
||||
ItemSignature(D),
|
||||
FieldTy(D),
|
||||
SizedConstraint(D),
|
||||
TraitItemDefIds(D),
|
||||
ImplOrTraitItemIds(D),
|
||||
InherentImpls(D),
|
||||
ImplItems(D),
|
||||
|
||||
// The set of impls for a given trait. Ultimately, it would be
|
||||
// nice to get more fine-grained here (e.g., to include a
|
||||
|
@ -162,9 +157,8 @@ impl<D: Clone + Debug> DepNode<D> {
|
|||
ImplOrTraitItems,
|
||||
ItemSignature,
|
||||
FieldTy,
|
||||
TraitItemDefIds,
|
||||
ImplOrTraitItemIds,
|
||||
InherentImpls,
|
||||
ImplItems,
|
||||
TraitImpls,
|
||||
ReprHints,
|
||||
}
|
||||
|
@ -231,9 +225,8 @@ impl<D: Clone + Debug> DepNode<D> {
|
|||
ItemSignature(ref d) => op(d).map(ItemSignature),
|
||||
FieldTy(ref d) => op(d).map(FieldTy),
|
||||
SizedConstraint(ref d) => op(d).map(SizedConstraint),
|
||||
TraitItemDefIds(ref d) => op(d).map(TraitItemDefIds),
|
||||
ImplOrTraitItemIds(ref d) => op(d).map(ImplOrTraitItemIds),
|
||||
InherentImpls(ref d) => op(d).map(InherentImpls),
|
||||
ImplItems(ref d) => op(d).map(ImplItems),
|
||||
TraitImpls(ref d) => op(d).map(TraitImpls),
|
||||
TraitItems(ref d) => op(d).map(TraitItems),
|
||||
ReprHints(ref d) => op(d).map(ReprHints),
|
||||
|
|
|
@ -92,7 +92,7 @@ pub type DefMap = NodeMap<PathResolution>;
|
|||
// within.
|
||||
pub type ExportMap = NodeMap<Vec<Export>>;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||
pub struct Export {
|
||||
pub name: ast::Name, // The name of the target.
|
||||
pub def_id: DefId, // The definition of the target.
|
||||
|
|
|
@ -580,22 +580,24 @@ impl<'ast> Map<'ast> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expect_struct(&self, id: NodeId) -> &'ast VariantData {
|
||||
pub fn expect_variant_data(&self, id: NodeId) -> &'ast VariantData {
|
||||
match self.find(id) {
|
||||
Some(NodeItem(i)) => {
|
||||
match i.node {
|
||||
ItemStruct(ref struct_def, _) => struct_def,
|
||||
_ => bug!("struct ID bound to non-struct")
|
||||
ItemStruct(ref struct_def, _) |
|
||||
ItemUnion(ref struct_def, _) => struct_def,
|
||||
_ => {
|
||||
bug!("struct ID bound to non-struct {}",
|
||||
self.node_to_string(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(NodeVariant(variant)) => {
|
||||
if variant.node.data.is_struct() {
|
||||
&variant.node.data
|
||||
} else {
|
||||
bug!("struct ID bound to enum variant that isn't struct-like")
|
||||
}
|
||||
Some(NodeStructCtor(data)) => data,
|
||||
Some(NodeVariant(variant)) => &variant.node.data,
|
||||
_ => {
|
||||
bug!("expected struct or variant, found {}",
|
||||
self.node_to_string(id));
|
||||
}
|
||||
_ => bug!("expected struct, found {}", self.node_to_string(id)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,14 +28,13 @@ use hir::map as hir_map;
|
|||
use hir::map::definitions::DefKey;
|
||||
use hir::svh::Svh;
|
||||
use middle::lang_items;
|
||||
use ty::{self, Ty, TyCtxt, VariantKind};
|
||||
use ty::{self, Ty, TyCtxt};
|
||||
use mir::repr::Mir;
|
||||
use mir::mir_map::MirMap;
|
||||
use session::Session;
|
||||
use session::config::PanicStrategy;
|
||||
use session::search_paths::PathKind;
|
||||
use util::nodemap::{FnvHashMap, NodeSet, DefIdMap};
|
||||
use std::rc::Rc;
|
||||
use util::nodemap::{NodeSet, DefIdMap};
|
||||
use std::path::PathBuf;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
|
@ -47,7 +46,6 @@ use rustc_back::target::Target;
|
|||
use hir;
|
||||
use hir::intravisit::Visitor;
|
||||
|
||||
pub use self::DefLike::{DlDef, DlField, DlImpl};
|
||||
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
|
||||
|
||||
// lonely orphan structs and enums looking for a better home
|
||||
|
@ -67,27 +65,17 @@ pub struct CrateSource {
|
|||
pub cnum: CrateNum,
|
||||
}
|
||||
|
||||
#[derive(Copy, Debug, PartialEq, Clone)]
|
||||
#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
|
||||
pub enum LinkagePreference {
|
||||
RequireDynamic,
|
||||
RequireStatic,
|
||||
}
|
||||
|
||||
enum_from_u32! {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum NativeLibraryKind {
|
||||
NativeStatic, // native static library (.a archive)
|
||||
NativeFramework, // OSX-specific
|
||||
NativeUnknown, // default way to specify a dynamic library
|
||||
}
|
||||
}
|
||||
|
||||
// Something that a name can resolve to.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum DefLike {
|
||||
DlDef(Def),
|
||||
DlImpl(DefId),
|
||||
DlField
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum NativeLibraryKind {
|
||||
NativeStatic, // native static library (.a archive)
|
||||
NativeFramework, // OSX-specific
|
||||
NativeUnknown, // default way to specify a dynamic library
|
||||
}
|
||||
|
||||
/// The data we save and restore about an inlined item or method. This is not
|
||||
|
@ -110,7 +98,7 @@ pub enum InlinedItemRef<'a> {
|
|||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct ChildItem {
|
||||
pub def: DefLike,
|
||||
pub def: Def,
|
||||
pub name: ast::Name,
|
||||
pub vis: ty::Visibility,
|
||||
}
|
||||
|
@ -166,21 +154,15 @@ pub trait CrateStore<'tcx> {
|
|||
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
|
||||
|
||||
// trait info
|
||||
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>;
|
||||
fn provided_trait_methods<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::Method<'tcx>>>;
|
||||
fn trait_item_def_ids(&self, def: DefId)
|
||||
-> Vec<ty::ImplOrTraitItemId>;
|
||||
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
|
||||
|
||||
// impl info
|
||||
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
|
||||
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
|
||||
fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Option<ty::TraitRef<'tcx>>;
|
||||
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>;
|
||||
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
|
||||
fn custom_coerce_unsized_kind(&self, def: DefId)
|
||||
-> Option<ty::adjustment::CustomCoerceUnsized>;
|
||||
fn associated_consts<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::AssociatedConst<'tcx>>>;
|
||||
fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
|
||||
|
||||
// trait/impl-item info
|
||||
|
@ -191,12 +173,10 @@ pub trait CrateStore<'tcx> {
|
|||
// flags
|
||||
fn is_const_fn(&self, did: DefId) -> bool;
|
||||
fn is_defaulted_trait(&self, did: DefId) -> bool;
|
||||
fn is_impl(&self, did: DefId) -> bool;
|
||||
fn is_default_impl(&self, impl_did: DefId) -> bool;
|
||||
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool;
|
||||
fn is_foreign_item(&self, did: DefId) -> bool;
|
||||
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
|
||||
fn is_typedef(&self, did: DefId) -> bool;
|
||||
|
||||
// crate metadata
|
||||
fn dylib_dependency_formats(&self, cnum: CrateNum)
|
||||
|
@ -218,8 +198,6 @@ pub trait CrateStore<'tcx> {
|
|||
fn original_crate_name(&self, cnum: CrateNum) -> InternedString;
|
||||
fn crate_hash(&self, cnum: CrateNum) -> Svh;
|
||||
fn crate_disambiguator(&self, cnum: CrateNum) -> InternedString;
|
||||
fn crate_struct_field_attrs(&self, cnum: CrateNum)
|
||||
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
|
||||
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
|
||||
fn native_libraries(&self, cnum: CrateNum) -> Vec<(NativeLibraryKind, String)>;
|
||||
fn reachable_ids(&self, cnum: CrateNum) -> Vec<DefId>;
|
||||
|
@ -232,12 +210,10 @@ pub trait CrateStore<'tcx> {
|
|||
-> Option<DefIndex>;
|
||||
fn def_key(&self, def: DefId) -> hir_map::DefKey;
|
||||
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath>;
|
||||
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind>;
|
||||
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>;
|
||||
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
|
||||
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
|
||||
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
|
||||
fn crate_top_level_items(&self, cnum: CrateNum) -> Vec<ChildItem>;
|
||||
|
||||
// misc. metadata
|
||||
fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
|
@ -344,11 +320,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
|
||||
|
||||
// trait info
|
||||
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId> { vec![] }
|
||||
fn provided_trait_methods<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::Method<'tcx>>> { bug!("provided_trait_methods") }
|
||||
fn trait_item_def_ids(&self, def: DefId)
|
||||
-> Vec<ty::ImplOrTraitItemId> { bug!("trait_item_def_ids") }
|
||||
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }
|
||||
fn def_index_for_def_key(&self,
|
||||
cnum: CrateNum,
|
||||
def: DefKey)
|
||||
|
@ -357,16 +329,14 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
}
|
||||
|
||||
// impl info
|
||||
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
|
||||
{ bug!("impl_items") }
|
||||
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
|
||||
{ bug!("impl_or_trait_items") }
|
||||
fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
|
||||
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity> { bug!("impl_polarity") }
|
||||
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
|
||||
fn custom_coerce_unsized_kind(&self, def: DefId)
|
||||
-> Option<ty::adjustment::CustomCoerceUnsized>
|
||||
{ bug!("custom_coerce_unsized_kind") }
|
||||
fn associated_consts<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::AssociatedConst<'tcx>>> { bug!("associated_consts") }
|
||||
fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
|
||||
|
||||
// trait/impl-item info
|
||||
|
@ -377,13 +347,11 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
// flags
|
||||
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
|
||||
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
|
||||
fn is_impl(&self, did: DefId) -> bool { bug!("is_impl") }
|
||||
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
|
||||
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool
|
||||
{ bug!("is_extern_item") }
|
||||
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
|
||||
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
|
||||
fn is_typedef(&self, did: DefId) -> bool { bug!("is_typedef") }
|
||||
|
||||
// crate metadata
|
||||
fn dylib_dependency_formats(&self, cnum: CrateNum)
|
||||
|
@ -411,9 +379,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
|
||||
fn crate_disambiguator(&self, cnum: CrateNum)
|
||||
-> InternedString { bug!("crate_disambiguator") }
|
||||
fn crate_struct_field_attrs(&self, cnum: CrateNum)
|
||||
-> FnvHashMap<DefId, Vec<ast::Attribute>>
|
||||
{ bug!("crate_struct_field_attrs") }
|
||||
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
|
||||
{ bug!("plugin_registrar_fn") }
|
||||
fn native_libraries(&self, cnum: CrateNum) -> Vec<(NativeLibraryKind, String)>
|
||||
|
@ -426,15 +391,12 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath> {
|
||||
bug!("relative_def_path")
|
||||
}
|
||||
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind> { bug!("variant_kind") }
|
||||
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
|
||||
{ bug!("struct_ctor_def_id") }
|
||||
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>
|
||||
{ bug!("tuple_struct_definition_if_ctor") }
|
||||
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
|
||||
fn item_children(&self, did: DefId) -> Vec<ChildItem> { bug!("item_children") }
|
||||
fn crate_top_level_items(&self, cnum: CrateNum) -> Vec<ChildItem>
|
||||
{ bug!("crate_top_level_items") }
|
||||
|
||||
// misc. metadata
|
||||
fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
|
|
|
@ -470,7 +470,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
|||
// This is done to handle the case where, for example, the static
|
||||
// method of a private type is used, but the type itself is never
|
||||
// called directly.
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
let impl_items = self.tcx.impl_or_trait_item_ids.borrow();
|
||||
if let Some(impl_list) =
|
||||
self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
|
||||
for impl_did in impl_list.iter() {
|
||||
|
|
|
@ -43,7 +43,7 @@ macro_rules! language_item_table {
|
|||
|
||||
|
||||
enum_from_u32! {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum LangItem {
|
||||
$($variant,)*
|
||||
}
|
||||
|
|
|
@ -493,7 +493,7 @@ impl Passes {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Hash)]
|
||||
#[derive(Clone, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum PanicStrategy {
|
||||
Unwind,
|
||||
Abort,
|
||||
|
|
|
@ -814,7 +814,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
fn filter_negative_impls(&self, candidate: SelectionCandidate<'tcx>)
|
||||
-> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
|
||||
if let ImplCandidate(def_id) = candidate {
|
||||
if self.tcx().trait_impl_polarity(def_id) == Some(hir::ImplPolarity::Negative) {
|
||||
if self.tcx().trait_impl_polarity(def_id) == hir::ImplPolarity::Negative {
|
||||
return Err(Unimplemented)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::{OverlapError, specializes};
|
||||
|
@ -287,21 +286,10 @@ impl<'a, 'gcx, 'tcx> Node {
|
|||
|
||||
/// Iterate over the items defined directly by the given (impl or trait) node.
|
||||
pub fn items(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> NodeItems<'a, 'gcx> {
|
||||
match *self {
|
||||
Node::Impl(impl_def_id) => {
|
||||
NodeItems::Impl {
|
||||
tcx: tcx.global_tcx(),
|
||||
items: cell::Ref::map(tcx.impl_items.borrow(),
|
||||
|impl_items| &impl_items[&impl_def_id]),
|
||||
idx: 0,
|
||||
}
|
||||
}
|
||||
Node::Trait(trait_def_id) => {
|
||||
NodeItems::Trait {
|
||||
items: tcx.trait_items(trait_def_id).clone(),
|
||||
idx: 0,
|
||||
}
|
||||
}
|
||||
NodeItems {
|
||||
tcx: tcx.global_tcx(),
|
||||
items: tcx.impl_or_trait_items(self.def_id()),
|
||||
idx: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,42 +302,23 @@ impl<'a, 'gcx, 'tcx> Node {
|
|||
}
|
||||
|
||||
/// An iterator over the items defined within a trait or impl.
|
||||
pub enum NodeItems<'a, 'tcx: 'a> {
|
||||
Impl {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
items: cell::Ref<'a, Vec<ty::ImplOrTraitItemId>>,
|
||||
idx: usize,
|
||||
},
|
||||
Trait {
|
||||
items: Rc<Vec<ImplOrTraitItem<'tcx>>>,
|
||||
idx: usize,
|
||||
},
|
||||
pub struct NodeItems<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
items: Rc<Vec<ty::ImplOrTraitItemId>>,
|
||||
idx: usize
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Iterator for NodeItems<'a, 'tcx> {
|
||||
type Item = ImplOrTraitItem<'tcx>;
|
||||
fn next(&mut self) -> Option<ImplOrTraitItem<'tcx>> {
|
||||
match *self {
|
||||
NodeItems::Impl { tcx, ref items, ref mut idx } => {
|
||||
let items_table = tcx.impl_or_trait_items.borrow();
|
||||
if *idx < items.len() {
|
||||
let item_def_id = items[*idx].def_id();
|
||||
let item = items_table[&item_def_id].clone();
|
||||
*idx += 1;
|
||||
Some(item)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
NodeItems::Trait { ref items, ref mut idx } => {
|
||||
if *idx < items.len() {
|
||||
let item = items[*idx].clone();
|
||||
*idx += 1;
|
||||
Some(item)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
if self.idx < self.items.len() {
|
||||
let item_def_id = self.items[self.idx].def_id();
|
||||
let items_table = self.tcx.impl_or_trait_items.borrow();
|
||||
let item = items_table[&item_def_id].clone();
|
||||
self.idx += 1;
|
||||
Some(item)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -330,8 +330,8 @@ pub struct GlobalCtxt<'tcx> {
|
|||
/// Maps from a trait item to the trait item "descriptor"
|
||||
pub impl_or_trait_items: RefCell<DepTrackingMap<maps::ImplOrTraitItems<'tcx>>>,
|
||||
|
||||
/// Maps from a trait def-id to a list of the def-ids of its trait items
|
||||
pub trait_item_def_ids: RefCell<DepTrackingMap<maps::TraitItemDefIds<'tcx>>>,
|
||||
/// Maps from an impl/trait def-id to a list of the def-ids of its items
|
||||
pub impl_or_trait_item_ids: RefCell<DepTrackingMap<maps::ImplOrTraitItemIds<'tcx>>>,
|
||||
|
||||
/// A cache for the trait_items() routine; note that the routine
|
||||
/// itself pushes the `TraitItems` dependency node.
|
||||
|
@ -392,12 +392,6 @@ pub struct GlobalCtxt<'tcx> {
|
|||
/// Methods in these implementations don't need to be exported.
|
||||
pub inherent_impls: RefCell<DepTrackingMap<maps::InherentImpls<'tcx>>>,
|
||||
|
||||
/// Maps a DefId of an impl to a list of its items.
|
||||
/// Note that this contains all of the impls that we know about,
|
||||
/// including ones in other crates. It's not clear that this is the best
|
||||
/// way to do it.
|
||||
pub impl_items: RefCell<DepTrackingMap<maps::ImplItems<'tcx>>>,
|
||||
|
||||
/// Set of used unsafe nodes (functions or blocks). Unsafe nodes not
|
||||
/// present in this set can be warned about.
|
||||
pub used_unsafe: RefCell<NodeSet>,
|
||||
|
@ -734,13 +728,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
rcache: RefCell::new(FnvHashMap()),
|
||||
tc_cache: RefCell::new(FnvHashMap()),
|
||||
impl_or_trait_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
|
||||
trait_item_def_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
|
||||
impl_or_trait_item_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
|
||||
trait_items_cache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
|
||||
ty_param_defs: RefCell::new(NodeMap()),
|
||||
normalized_cache: RefCell::new(FnvHashMap()),
|
||||
lang_items: lang_items,
|
||||
inherent_impls: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
|
||||
impl_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
|
||||
used_unsafe: RefCell::new(NodeSet()),
|
||||
used_mut_nodes: RefCell::new(NodeSet()),
|
||||
used_trait_imports: RefCell::new(NodeSet()),
|
||||
|
@ -1401,7 +1394,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
pub fn trait_items(self, trait_did: DefId) -> Rc<Vec<ty::ImplOrTraitItem<'gcx>>> {
|
||||
self.trait_items_cache.memoize(trait_did, || {
|
||||
let def_ids = self.trait_item_def_ids(trait_did);
|
||||
let def_ids = self.impl_or_trait_items(trait_did);
|
||||
Rc::new(def_ids.iter()
|
||||
.map(|d| self.impl_or_trait_item(d.def_id()))
|
||||
.collect())
|
||||
|
|
|
@ -34,13 +34,13 @@ dep_map_ty! { Tcache: ItemSignature(DefId) -> Ty<'tcx> }
|
|||
dep_map_ty! { Generics: ItemSignature(DefId) -> &'tcx ty::Generics<'tcx> }
|
||||
dep_map_ty! { Predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
|
||||
dep_map_ty! { SuperPredicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
|
||||
dep_map_ty! { TraitItemDefIds: TraitItemDefIds(DefId) -> Rc<Vec<ty::ImplOrTraitItemId>> }
|
||||
dep_map_ty! { ImplOrTraitItemIds: ImplOrTraitItemIds(DefId)
|
||||
-> Rc<Vec<ty::ImplOrTraitItemId>> }
|
||||
dep_map_ty! { ImplTraitRefs: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>> }
|
||||
dep_map_ty! { TraitDefs: ItemSignature(DefId) -> &'tcx ty::TraitDef<'tcx> }
|
||||
dep_map_ty! { AdtDefs: ItemSignature(DefId) -> ty::AdtDefMaster<'tcx> }
|
||||
dep_map_ty! { ItemVariances: ItemSignature(DefId) -> Rc<Vec<ty::Variance>> }
|
||||
dep_map_ty! { InherentImpls: InherentImpls(DefId) -> Vec<DefId> }
|
||||
dep_map_ty! { ImplItems: ImplItems(DefId) -> Vec<ty::ImplOrTraitItemId> }
|
||||
dep_map_ty! { TraitItems: TraitItems(DefId) -> Rc<Vec<ty::ImplOrTraitItem<'tcx>>> }
|
||||
dep_map_ty! { ReprHints: ReprHints(DefId) -> Rc<Vec<attr::ReprAttr>> }
|
||||
dep_map_ty! { InlinedClosures: Hir(DefId) -> ast::NodeId }
|
||||
|
|
|
@ -50,7 +50,6 @@ use syntax_pos::{DUMMY_SP, Span};
|
|||
use rustc_const_math::ConstInt;
|
||||
|
||||
use hir;
|
||||
use hir::{ItemImpl, ItemTrait, PatKind};
|
||||
use hir::intravisit::Visitor;
|
||||
|
||||
pub use self::sty::{Binder, DebruijnIndex};
|
||||
|
@ -251,7 +250,7 @@ impl<'tcx> ImplOrTraitItem<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum ImplOrTraitItemId {
|
||||
ConstTraitItemId(DefId),
|
||||
MethodTraitItemId(DefId),
|
||||
|
@ -268,7 +267,7 @@ impl ImplOrTraitItemId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Copy)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable)]
|
||||
pub enum Visibility {
|
||||
/// Visible everywhere (including in other crates).
|
||||
Public,
|
||||
|
@ -346,34 +345,12 @@ pub struct Method<'tcx> {
|
|||
pub explicit_self: ExplicitSelfCategory<'tcx>,
|
||||
pub vis: Visibility,
|
||||
pub defaultness: hir::Defaultness,
|
||||
pub has_body: bool,
|
||||
pub def_id: DefId,
|
||||
pub container: ImplOrTraitItemContainer,
|
||||
}
|
||||
|
||||
impl<'tcx> Method<'tcx> {
|
||||
pub fn new(name: Name,
|
||||
generics: &'tcx ty::Generics<'tcx>,
|
||||
predicates: GenericPredicates<'tcx>,
|
||||
fty: &'tcx BareFnTy<'tcx>,
|
||||
explicit_self: ExplicitSelfCategory<'tcx>,
|
||||
vis: Visibility,
|
||||
defaultness: hir::Defaultness,
|
||||
def_id: DefId,
|
||||
container: ImplOrTraitItemContainer)
|
||||
-> Method<'tcx> {
|
||||
Method {
|
||||
name: name,
|
||||
generics: generics,
|
||||
predicates: predicates,
|
||||
fty: fty,
|
||||
explicit_self: explicit_self,
|
||||
vis: vis,
|
||||
defaultness: defaultness,
|
||||
def_id: def_id,
|
||||
container: container,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn container_id(&self) -> DefId {
|
||||
match self.container {
|
||||
TraitContainer(id) => id,
|
||||
|
@ -2236,7 +2213,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
match self.map.find(id) {
|
||||
Some(ast_map::NodeLocal(pat)) => {
|
||||
match pat.node {
|
||||
PatKind::Binding(_, ref path1, _) => path1.node.as_str(),
|
||||
hir::PatKind::Binding(_, ref path1, _) => path1.node.as_str(),
|
||||
_ => {
|
||||
bug!("Variable id {} maps to {:?}, not local", id, pat);
|
||||
},
|
||||
|
@ -2299,84 +2276,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn provided_trait_methods(self, id: DefId) -> Vec<Rc<Method<'gcx>>> {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
if let ItemTrait(.., ref ms) = self.map.expect_item(id).node {
|
||||
ms.iter().filter_map(|ti| {
|
||||
if let hir::MethodTraitItem(_, Some(_)) = ti.node {
|
||||
match self.impl_or_trait_item(self.map.local_def_id(ti.id)) {
|
||||
MethodTraitItem(m) => Some(m),
|
||||
_ => {
|
||||
bug!("provided_trait_methods(): \
|
||||
non-method item found from \
|
||||
looking up provided method?!")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
} else {
|
||||
bug!("provided_trait_methods: `{:?}` is not a trait", id)
|
||||
self.impl_or_trait_items(id).iter().filter_map(|id| {
|
||||
match self.impl_or_trait_item(id.def_id()) {
|
||||
MethodTraitItem(ref m) if m.has_body => Some(m.clone()),
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
self.sess.cstore.provided_trait_methods(self.global_tcx(), id)
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
pub fn associated_consts(self, id: DefId) -> Vec<Rc<AssociatedConst<'gcx>>> {
|
||||
pub fn trait_impl_polarity(self, id: DefId) -> hir::ImplPolarity {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
match self.map.expect_item(id).node {
|
||||
ItemTrait(.., ref tis) => {
|
||||
tis.iter().filter_map(|ti| {
|
||||
if let hir::ConstTraitItem(..) = ti.node {
|
||||
match self.impl_or_trait_item(self.map.local_def_id(ti.id)) {
|
||||
ConstTraitItem(ac) => Some(ac),
|
||||
_ => {
|
||||
bug!("associated_consts(): \
|
||||
non-const item found from \
|
||||
looking up a constant?!")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
ItemImpl(.., ref iis) => {
|
||||
iis.iter().filter_map(|ii| {
|
||||
if let hir::ImplItemKind::Const(..) = ii.node {
|
||||
match self.impl_or_trait_item(self.map.local_def_id(ii.id)) {
|
||||
ConstTraitItem(ac) => Some(ac),
|
||||
_ => {
|
||||
bug!("associated_consts(): \
|
||||
non-const item found from \
|
||||
looking up a constant?!")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
_ => {
|
||||
bug!("associated_consts: `{:?}` is not a trait or impl", id)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.sess.cstore.associated_consts(self.global_tcx(), id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trait_impl_polarity(self, id: DefId) -> Option<hir::ImplPolarity> {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
match self.map.find(id) {
|
||||
Some(ast_map::NodeItem(item)) => {
|
||||
match item.node {
|
||||
hir::ItemImpl(_, polarity, ..) => Some(polarity),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
hir::ItemImpl(_, polarity, ..) => polarity,
|
||||
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
|
||||
}
|
||||
} else {
|
||||
self.sess.cstore.impl_polarity(id)
|
||||
|
@ -2409,10 +2321,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
.expect("missing ImplOrTraitItem in metadata"))
|
||||
}
|
||||
|
||||
pub fn trait_item_def_ids(self, id: DefId) -> Rc<Vec<ImplOrTraitItemId>> {
|
||||
pub fn impl_or_trait_items(self, id: DefId) -> Rc<Vec<ImplOrTraitItemId>> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"trait_item_def_ids", id, &self.trait_item_def_ids,
|
||||
|| Rc::new(self.sess.cstore.trait_item_def_ids(id)))
|
||||
"impl_or_trait_items", id, &self.impl_or_trait_item_ids,
|
||||
|| Rc::new(self.sess.cstore.impl_or_trait_items(id)))
|
||||
}
|
||||
|
||||
/// Returns the trait-ref corresponding to a given impl, or None if it is
|
||||
|
@ -2423,20 +2335,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|| self.sess.cstore.impl_trait_ref(self.global_tcx(), id))
|
||||
}
|
||||
|
||||
/// Returns whether this DefId refers to an impl
|
||||
pub fn is_impl(self, id: DefId) -> bool {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
if let Some(ast_map::NodeItem(
|
||||
&hir::Item { node: hir::ItemImpl(..), .. })) = self.map.find(id) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
self.sess.cstore.is_impl(id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a path resolution for node id if it exists, panics otherwise.
|
||||
pub fn expect_resolution(self, id: NodeId) -> PathResolution {
|
||||
*self.def_map.borrow().get(&id).expect("no def-map entry for node id")
|
||||
|
@ -2699,10 +2597,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
debug!("populate_implementations_for_primitive_if_necessary: searching for {:?}",
|
||||
primitive_def_id);
|
||||
|
||||
let impl_items = self.sess.cstore.impl_items(primitive_def_id);
|
||||
let impl_items = self.sess.cstore.impl_or_trait_items(primitive_def_id);
|
||||
|
||||
// Store the implementation info.
|
||||
self.impl_items.borrow_mut().insert(primitive_def_id, impl_items);
|
||||
self.impl_or_trait_item_ids.borrow_mut().insert(primitive_def_id, Rc::new(impl_items));
|
||||
self.populated_external_primitive_impls.borrow_mut().insert(primitive_def_id);
|
||||
}
|
||||
|
||||
|
@ -2728,8 +2626,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
let inherent_impls = self.sess.cstore.inherent_implementations_for_type(type_id);
|
||||
for &impl_def_id in &inherent_impls {
|
||||
// Store the implementation info.
|
||||
let impl_items = self.sess.cstore.impl_items(impl_def_id);
|
||||
self.impl_items.borrow_mut().insert(impl_def_id, impl_items);
|
||||
let impl_items = self.sess.cstore.impl_or_trait_items(impl_def_id);
|
||||
self.impl_or_trait_item_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
|
||||
}
|
||||
|
||||
self.inherent_impls.borrow_mut().insert(type_id, inherent_impls);
|
||||
|
@ -2758,8 +2656,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.record_trait_has_default_impl(trait_id);
|
||||
}
|
||||
|
||||
for impl_def_id in self.sess.cstore.implementations_of_trait(trait_id) {
|
||||
let impl_items = self.sess.cstore.impl_items(impl_def_id);
|
||||
for impl_def_id in self.sess.cstore.implementations_of_trait(Some(trait_id)) {
|
||||
let impl_items = self.sess.cstore.impl_or_trait_items(impl_def_id);
|
||||
let trait_ref = self.impl_trait_ref(impl_def_id).unwrap();
|
||||
|
||||
// Record the trait->implementation mapping.
|
||||
|
@ -2779,7 +2677,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
// Store the implementation info.
|
||||
self.impl_items.borrow_mut().insert(impl_def_id, impl_items);
|
||||
self.impl_or_trait_item_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
|
||||
}
|
||||
|
||||
def.flags.set(def.flags.get() | TraitFlags::IMPLS_VALID);
|
||||
|
@ -3012,7 +2910,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
/// The category of explicit self.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum ExplicitSelfCategory<'tcx> {
|
||||
Static,
|
||||
ByValue,
|
||||
|
|
|
@ -1080,9 +1080,17 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
// when constructing the inference context above.
|
||||
match selection {
|
||||
traits::VtableImpl(ref impl_data) => {
|
||||
match tcx.associated_consts(impl_data.impl_def_id)
|
||||
.iter().find(|ic| ic.name == ti.name) {
|
||||
Some(ic) => lookup_const_by_id(tcx, ic.def_id, None),
|
||||
let ac = tcx.impl_or_trait_items(impl_data.impl_def_id)
|
||||
.iter().filter_map(|id| {
|
||||
match *id {
|
||||
ty::ConstTraitItemId(def_id) => {
|
||||
Some(tcx.impl_or_trait_item(def_id))
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}).find(|ic| ic.name() == ti.name);
|
||||
match ac {
|
||||
Some(ic) => lookup_const_by_id(tcx, ic.def_id(), None),
|
||||
None => match ti.node {
|
||||
hir::ConstTraitItem(ref ty, Some(ref expr)) => {
|
||||
Some((&*expr, tcx.ast_ty_to_prim_ty(ty)))
|
||||
|
|
|
@ -10,13 +10,38 @@
|
|||
|
||||
#![allow(non_camel_case_types, non_upper_case_globals)]
|
||||
|
||||
use rustc::ty;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
pub enum Family {
|
||||
ImmStatic,
|
||||
MutStatic,
|
||||
Fn,
|
||||
Method,
|
||||
AssociatedType,
|
||||
Type,
|
||||
Mod,
|
||||
ForeignMod,
|
||||
Enum,
|
||||
Variant(ty::VariantKind),
|
||||
Impl,
|
||||
DefaultImpl,
|
||||
Trait,
|
||||
Struct(ty::VariantKind),
|
||||
Union,
|
||||
PublicField,
|
||||
InheritedField,
|
||||
Const,
|
||||
AssociatedConst,
|
||||
}
|
||||
|
||||
// GAP 0x00...0x19
|
||||
|
||||
pub const tag_items: usize = 0x100; // top-level only
|
||||
|
||||
pub const tag_paths_data_name: usize = 0x20;
|
||||
|
||||
pub const tag_def_id: usize = 0x21;
|
||||
pub const tag_def_index: usize = 0x21;
|
||||
|
||||
pub const tag_items_data: usize = 0x22;
|
||||
|
||||
|
@ -26,9 +51,7 @@ pub const tag_items_data_item_family: usize = 0x24;
|
|||
|
||||
pub const tag_items_data_item_type: usize = 0x25;
|
||||
|
||||
// GAP 0x26
|
||||
|
||||
pub const tag_items_data_item_variant: usize = 0x27;
|
||||
// GAP 0x26, 0x27
|
||||
|
||||
pub const tag_items_data_parent_item: usize = 0x28;
|
||||
|
||||
|
@ -47,19 +70,11 @@ pub const tag_attributes: usize = 0x101; // top-level only
|
|||
|
||||
// The list of crates that this crate depends on
|
||||
pub const tag_crate_deps: usize = 0x102; // top-level only
|
||||
|
||||
// A single crate dependency
|
||||
pub const tag_crate_dep: usize = 0x35;
|
||||
|
||||
pub const tag_crate_hash: usize = 0x103; // top-level only
|
||||
pub const tag_crate_crate_name: usize = 0x104; // top-level only
|
||||
pub const tag_crate_disambiguator: usize = 0x113; // top-level only
|
||||
|
||||
pub const tag_crate_dep_crate_name: usize = 0x36;
|
||||
pub const tag_crate_dep_hash: usize = 0x37;
|
||||
pub const tag_crate_dep_explicitly_linked: usize = 0x38; // top-level only
|
||||
|
||||
pub const tag_item_trait_item: usize = 0x3a;
|
||||
// GAP 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a
|
||||
|
||||
pub const tag_item_trait_ref: usize = 0x3b;
|
||||
|
||||
|
@ -68,26 +83,13 @@ pub const tag_disr_val: usize = 0x3c;
|
|||
|
||||
// GAP 0x3d, 0x3e, 0x3f, 0x40
|
||||
|
||||
pub const tag_item_field: usize = 0x41;
|
||||
pub const tag_item_fields: usize = 0x41;
|
||||
// GAP 0x42
|
||||
pub const tag_item_variances: usize = 0x43;
|
||||
/*
|
||||
trait items contain tag_item_trait_item elements,
|
||||
impl items contain tag_item_impl_item elements, and classes
|
||||
have both. That's because some code treats classes like traits,
|
||||
and other code treats them like impls. Because classes can contain
|
||||
both, tag_item_trait_item and tag_item_impl_item have to be two
|
||||
different tags.
|
||||
*/
|
||||
pub const tag_item_impl_item: usize = 0x44;
|
||||
// GAP 0x44
|
||||
pub const tag_item_trait_method_explicit_self: usize = 0x45;
|
||||
|
||||
|
||||
// Reexports are found within module tags. Each reexport contains def_ids
|
||||
// and names.
|
||||
pub const tag_items_data_item_reexport: usize = 0x46;
|
||||
pub const tag_items_data_item_reexport_def_id: usize = 0x47;
|
||||
pub const tag_items_data_item_reexport_name: usize = 0x48;
|
||||
// GAP 0x46, 0x47, 0x48
|
||||
|
||||
// used to encode crate_ctxt side tables
|
||||
pub const tag_ast: usize = 0x50;
|
||||
|
@ -98,58 +100,58 @@ pub const tag_mir: usize = 0x52;
|
|||
|
||||
// GAP 0x53...0x6a
|
||||
|
||||
pub const tag_item_trait_item_sort: usize = 0x70;
|
||||
pub const tag_item_trait_item_has_body: usize = 0x70;
|
||||
|
||||
pub const tag_crate_triple: usize = 0x105; // top-level only
|
||||
|
||||
pub const tag_dylib_dependency_formats: usize = 0x106; // top-level only
|
||||
|
||||
// Language items are a top-level directory (for speed). Hierarchy:
|
||||
//
|
||||
// tag_lang_items
|
||||
// - tag_lang_items_item
|
||||
// - tag_lang_items_item_id: u32
|
||||
// - tag_lang_items_item_index: u32
|
||||
|
||||
pub const tag_lang_items: usize = 0x107; // top-level only
|
||||
pub const tag_lang_items_item: usize = 0x73;
|
||||
pub const tag_lang_items_item_id: usize = 0x74;
|
||||
pub const tag_lang_items_item_index: usize = 0x75;
|
||||
pub const tag_lang_items_missing: usize = 0x76;
|
||||
|
||||
pub const tag_item_unnamed_field: usize = 0x77;
|
||||
// GAP 0x73, 0x74, 0x75
|
||||
|
||||
pub const tag_lang_items_missing: usize = 0x76; // top-level only
|
||||
|
||||
// GAP 0x77
|
||||
|
||||
pub const tag_items_data_item_visibility: usize = 0x78;
|
||||
pub const tag_items_data_item_inherent_impl: usize = 0x79;
|
||||
pub const tag_items_data_item_inherent_impls: usize = 0x79;
|
||||
|
||||
// GAP 0x7a
|
||||
pub const tag_mod_child: usize = 0x7b;
|
||||
|
||||
// GAP 0x7c
|
||||
pub const tag_mod_children: usize = 0x7b;
|
||||
|
||||
// GAP 0x108 // top-level only
|
||||
|
||||
// GAP 0x7c
|
||||
|
||||
// GAP 0x108
|
||||
pub const tag_impls: usize = 0x109; // top-level only
|
||||
pub const tag_impls_trait: usize = 0x7d;
|
||||
pub const tag_impls_trait_impl: usize = 0x7e;
|
||||
|
||||
// GAP 0x7f, 0x80, 0x81
|
||||
// GAP 0x7d, 0x7e, 0x7f, 0x80, 0x81
|
||||
|
||||
pub const tag_native_libraries: usize = 0x10a; // top-level only
|
||||
pub const tag_native_libraries_lib: usize = 0x82;
|
||||
pub const tag_native_libraries_name: usize = 0x83;
|
||||
pub const tag_native_libraries_kind: usize = 0x84;
|
||||
|
||||
// GAP 0x82, 0x83, 0x84
|
||||
|
||||
pub const tag_plugin_registrar_fn: usize = 0x10b; // top-level only
|
||||
|
||||
pub const tag_method_argument_names: usize = 0x85;
|
||||
pub const tag_method_argument_name: usize = 0x86;
|
||||
|
||||
// GAP 0x86
|
||||
|
||||
pub const tag_reachable_ids: usize = 0x10c; // top-level only
|
||||
pub const tag_reachable_id: usize = 0x87;
|
||||
|
||||
// GAP 0x87
|
||||
|
||||
pub const tag_items_data_item_stability: usize = 0x88;
|
||||
|
||||
pub const tag_items_data_item_repr: usize = 0x89;
|
||||
|
||||
pub const tag_struct_fields: usize = 0x10d; // top-level only
|
||||
pub const tag_struct_field: usize = 0x8a;
|
||||
// GAP 0x10d // top-level only
|
||||
|
||||
// GAP 0x8a
|
||||
|
||||
pub const tag_items_data_item_struct_ctor: usize = 0x8b;
|
||||
pub const tag_attribute_is_sugared_doc: usize = 0x8c;
|
||||
|
@ -160,10 +162,7 @@ pub const tag_item_generics: usize = 0x8f;
|
|||
// GAP 0x90, 0x91, 0x92, 0x93, 0x94
|
||||
|
||||
pub const tag_item_predicates: usize = 0x95;
|
||||
// GAP 0x96
|
||||
|
||||
pub const tag_predicate: usize = 0x97;
|
||||
// GAP 0x98, 0x99
|
||||
// GAP 0x96, 0x97, 0x98, 0x99
|
||||
|
||||
pub const tag_unsafety: usize = 0x9a;
|
||||
|
||||
|
@ -173,15 +172,14 @@ pub const tag_associated_type_name: usize = 0x9c;
|
|||
pub const tag_polarity: usize = 0x9d;
|
||||
|
||||
pub const tag_macro_defs: usize = 0x10e; // top-level only
|
||||
pub const tag_macro_def: usize = 0x9e;
|
||||
pub const tag_macro_def_body: usize = 0x9f;
|
||||
pub const tag_macro_def_span_lo: usize = 0xa8;
|
||||
pub const tag_macro_def_span_hi: usize = 0xa9;
|
||||
|
||||
// GAP 0x9e, 0x9f
|
||||
|
||||
pub const tag_paren_sugar: usize = 0xa0;
|
||||
|
||||
pub const tag_codemap: usize = 0xa1;
|
||||
pub const tag_codemap_filemap: usize = 0xa2;
|
||||
|
||||
// GAP 0xa2
|
||||
|
||||
pub const tag_item_super_predicates: usize = 0xa3;
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ impl<'a> CrateReader<'a> {
|
|||
|
||||
// Check for (potential) conflicts with the local crate
|
||||
if self.local_crate_name == crate_name &&
|
||||
self.sess.local_crate_disambiguator() == disambiguator {
|
||||
self.sess.local_crate_disambiguator() == &disambiguator[..] {
|
||||
span_fatal!(self.sess, span, E0519,
|
||||
"the current crate is indistinguishable from one of its \
|
||||
dependencies: it has the same crate-name `{}` and was \
|
||||
|
@ -320,7 +320,6 @@ impl<'a> CrateReader<'a> {
|
|||
let loader::Library { dylib, rlib, metadata } = lib;
|
||||
|
||||
let cnum_map = self.resolve_crate_deps(root, metadata.as_slice(), cnum, span);
|
||||
let staged_api = self.is_staged_api(metadata.as_slice());
|
||||
|
||||
let cmeta = Rc::new(cstore::CrateMetadata {
|
||||
name: name.to_string(),
|
||||
|
@ -332,7 +331,6 @@ impl<'a> CrateReader<'a> {
|
|||
cnum_map: RefCell::new(cnum_map),
|
||||
cnum: cnum,
|
||||
codemap_import_info: RefCell::new(vec![]),
|
||||
staged_api: staged_api,
|
||||
explicitly_linked: Cell::new(explicitly_linked),
|
||||
});
|
||||
|
||||
|
@ -352,16 +350,6 @@ impl<'a> CrateReader<'a> {
|
|||
(cnum, cmeta, source)
|
||||
}
|
||||
|
||||
fn is_staged_api(&self, data: &[u8]) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(data);
|
||||
for attr in &attrs {
|
||||
if attr.name() == "stable" || attr.name() == "unstable" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn resolve_crate(&mut self,
|
||||
root: &Option<CratePaths>,
|
||||
ident: &str,
|
||||
|
|
|
@ -14,11 +14,11 @@ use decoder;
|
|||
use encoder;
|
||||
use loader;
|
||||
|
||||
use middle::cstore::{InlinedItem, CrateStore, CrateSource, ChildItem, ExternCrate, DefLike};
|
||||
use middle::cstore::{InlinedItem, CrateStore, CrateSource, ChildItem, ExternCrate};
|
||||
use middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference};
|
||||
use rustc::hir::def;
|
||||
use middle::lang_items;
|
||||
use rustc::ty::{self, Ty, TyCtxt, VariantKind};
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
|
||||
|
||||
use rustc::dep_graph::DepNode;
|
||||
|
@ -26,10 +26,9 @@ use rustc::hir::map as hir_map;
|
|||
use rustc::hir::map::DefKey;
|
||||
use rustc::mir::repr::Mir;
|
||||
use rustc::mir::mir_map::MirMap;
|
||||
use rustc::util::nodemap::{FnvHashMap, NodeSet, DefIdMap};
|
||||
use rustc::util::nodemap::{NodeSet, DefIdMap};
|
||||
use rustc::session::config::PanicStrategy;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::path::PathBuf;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
|
@ -166,42 +165,27 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
result
|
||||
}
|
||||
|
||||
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>
|
||||
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(def_id));
|
||||
if let Some(def_id) = filter {
|
||||
self.dep_graph.read(DepNode::MetaData(def_id));
|
||||
}
|
||||
let mut result = vec![];
|
||||
self.iter_crate_data(|_, cdata| {
|
||||
decoder::each_implementation_for_trait(cdata, def_id, &mut |iid| {
|
||||
decoder::each_implementation_for_trait(cdata, filter, &mut |iid| {
|
||||
result.push(iid)
|
||||
})
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
fn provided_trait_methods<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::Method<'tcx>>>
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(def));
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_provided_trait_methods(&cdata, def.index, tcx)
|
||||
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId> {
|
||||
self.dep_graph.read(DepNode::MetaData(def_id));
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::get_impl_or_trait_items(&cdata, def_id.index)
|
||||
}
|
||||
|
||||
fn trait_item_def_ids(&self, def: DefId)
|
||||
-> Vec<ty::ImplOrTraitItemId>
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(def));
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_trait_item_def_ids(&cdata, def.index)
|
||||
}
|
||||
|
||||
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(impl_def_id));
|
||||
let cdata = self.get_crate_data(impl_def_id.krate);
|
||||
decoder::get_impl_items(&cdata, impl_def_id.index)
|
||||
}
|
||||
|
||||
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>
|
||||
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(def));
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
|
@ -224,14 +208,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
decoder::get_custom_coerce_unsized_kind(&cdata, def.index)
|
||||
}
|
||||
|
||||
// FIXME: killme
|
||||
fn associated_consts<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::AssociatedConst<'tcx>>> {
|
||||
self.dep_graph.read(DepNode::MetaData(def));
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_associated_consts(&cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn impl_parent(&self, impl_def: DefId) -> Option<DefId> {
|
||||
self.dep_graph.read(DepNode::MetaData(impl_def));
|
||||
let cdata = self.get_crate_data(impl_def.krate);
|
||||
|
@ -266,13 +242,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
decoder::is_defaulted_trait(&cdata, trait_def_id.index)
|
||||
}
|
||||
|
||||
fn is_impl(&self, did: DefId) -> bool
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(did));
|
||||
let cdata = self.get_crate_data(did.krate);
|
||||
decoder::is_impl(&cdata, did.index)
|
||||
}
|
||||
|
||||
fn is_default_impl(&self, impl_did: DefId) -> bool {
|
||||
self.dep_graph.read(DepNode::MetaData(impl_did));
|
||||
let cdata = self.get_crate_data(impl_did.krate);
|
||||
|
@ -295,12 +264,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
self.do_is_statically_included_foreign_item(id)
|
||||
}
|
||||
|
||||
fn is_typedef(&self, did: DefId) -> bool {
|
||||
self.dep_graph.read(DepNode::MetaData(did));
|
||||
let cdata = self.get_crate_data(did.krate);
|
||||
decoder::is_typedef(&cdata, did.index)
|
||||
}
|
||||
|
||||
fn dylib_dependency_formats(&self, cnum: CrateNum)
|
||||
-> Vec<(CrateNum, LinkagePreference)>
|
||||
{
|
||||
|
@ -310,12 +273,8 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
|
||||
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
|
||||
{
|
||||
let mut result = vec![];
|
||||
let crate_data = self.get_crate_data(cnum);
|
||||
decoder::each_lang_item(&crate_data, |did, lid| {
|
||||
result.push((did, lid)); true
|
||||
});
|
||||
result
|
||||
decoder::get_lang_items(&crate_data)
|
||||
}
|
||||
|
||||
fn missing_lang_items(&self, cnum: CrateNum)
|
||||
|
@ -327,7 +286,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
|
||||
fn is_staged_api(&self, cnum: CrateNum) -> bool
|
||||
{
|
||||
self.get_crate_data(cnum).staged_api
|
||||
self.get_crate_data(cnum).is_staged_api()
|
||||
}
|
||||
|
||||
fn is_explicitly_linked(&self, cnum: CrateNum) -> bool
|
||||
|
@ -355,7 +314,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
|
||||
fn crate_attrs(&self, cnum: CrateNum) -> Vec<ast::Attribute>
|
||||
{
|
||||
decoder::get_crate_attributes(self.get_crate_data(cnum).data())
|
||||
decoder::get_item_attrs(&self.get_crate_data(cnum), CRATE_DEF_INDEX)
|
||||
}
|
||||
|
||||
fn crate_name(&self, cnum: CrateNum) -> token::InternedString
|
||||
|
@ -382,13 +341,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
fn crate_disambiguator(&self, cnum: CrateNum) -> token::InternedString
|
||||
{
|
||||
let cdata = self.get_crate_data(cnum);
|
||||
token::intern_and_get_ident(decoder::get_crate_disambiguator(cdata.data()))
|
||||
}
|
||||
|
||||
fn crate_struct_field_attrs(&self, cnum: CrateNum)
|
||||
-> FnvHashMap<DefId, Vec<ast::Attribute>>
|
||||
{
|
||||
decoder::get_struct_field_attrs(&self.get_crate_data(cnum))
|
||||
token::intern_and_get_ident(&decoder::get_crate_disambiguator(cdata.data()))
|
||||
}
|
||||
|
||||
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
|
||||
|
@ -447,12 +400,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
decoder::def_path(&cdata, def.index)
|
||||
}
|
||||
|
||||
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind> {
|
||||
self.dep_graph.read(DepNode::MetaData(def_id));
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::get_variant_kind(&cdata, def_id.index)
|
||||
}
|
||||
|
||||
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
|
||||
{
|
||||
self.dep_graph.read(DepNode::MetaData(struct_def_id));
|
||||
|
@ -486,17 +433,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
result
|
||||
}
|
||||
|
||||
fn crate_top_level_items(&self, cnum: CrateNum) -> Vec<ChildItem>
|
||||
{
|
||||
let mut result = vec![];
|
||||
let crate_data = self.get_crate_data(cnum);
|
||||
let get_crate_data = |cnum| self.get_crate_data(cnum);
|
||||
decoder::each_top_level_item_of_crate(&crate_data, get_crate_data, |def, name, vis| {
|
||||
result.push(ChildItem { def: def, name: name, vis: vis });
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
fn maybe_get_item_ast<'a>(&'tcx self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
|
@ -726,9 +662,10 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
|
||||
let mut bfs_queue = &mut VecDeque::new();
|
||||
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: ChildItem, parent: DefId| {
|
||||
let child = match child.def {
|
||||
DefLike::DlDef(def) if child.vis == ty::Visibility::Public => def.def_id(),
|
||||
_ => return,
|
||||
let child = if child.vis == ty::Visibility::Public {
|
||||
child.def.def_id()
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
match visible_parent_map.entry(child) {
|
||||
|
@ -746,10 +683,10 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
}
|
||||
};
|
||||
|
||||
let croot = DefId { krate: cnum, index: CRATE_DEF_INDEX };
|
||||
for child in self.crate_top_level_items(cnum) {
|
||||
add_child(bfs_queue, child, croot);
|
||||
}
|
||||
bfs_queue.push_back(DefId {
|
||||
krate: cnum,
|
||||
index: CRATE_DEF_INDEX
|
||||
});
|
||||
while let Some(def) = bfs_queue.pop_front() {
|
||||
for child in self.item_children(def) {
|
||||
add_child(bfs_queue, child, def);
|
||||
|
@ -760,4 +697,3 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
visible_parent_map
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ use index;
|
|||
use loader;
|
||||
|
||||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::hir::def_id::{CrateNum, DefIndex, DefId};
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex, DefId};
|
||||
use rustc::hir::map::DefKey;
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc::middle::cstore::ExternCrate;
|
||||
|
@ -77,7 +77,6 @@ pub struct CrateMetadata {
|
|||
pub cnum_map: RefCell<CrateNumMap>,
|
||||
pub cnum: CrateNum,
|
||||
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
|
||||
pub staged_api: bool,
|
||||
|
||||
pub index: index::Index,
|
||||
pub xref_index: index::DenseIndex,
|
||||
|
@ -300,9 +299,9 @@ impl CStore {
|
|||
|
||||
impl CrateMetadata {
|
||||
pub fn data<'a>(&'a self) -> &'a [u8] { self.data.as_slice() }
|
||||
pub fn name(&self) -> &str { decoder::get_crate_name(self.data()) }
|
||||
pub fn name(&self) -> String { decoder::get_crate_name(self.data()) }
|
||||
pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
|
||||
pub fn disambiguator(&self) -> &str {
|
||||
pub fn disambiguator(&self) -> String {
|
||||
decoder::get_crate_disambiguator(self.data())
|
||||
}
|
||||
pub fn imported_filemaps<'a>(&'a self, codemap: &codemap::CodeMap)
|
||||
|
@ -320,23 +319,30 @@ impl CrateMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_staged_api(&self) -> bool {
|
||||
let attrs = decoder::get_item_attrs(self, CRATE_DEF_INDEX);
|
||||
attrs.iter().any(|attr| {
|
||||
attr.name() == "stable" || attr.name() == "unstable"
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_allocator(&self) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(self.data());
|
||||
let attrs = decoder::get_item_attrs(self, CRATE_DEF_INDEX);
|
||||
attr::contains_name(&attrs, "allocator")
|
||||
}
|
||||
|
||||
pub fn needs_allocator(&self) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(self.data());
|
||||
let attrs = decoder::get_item_attrs(self, CRATE_DEF_INDEX);
|
||||
attr::contains_name(&attrs, "needs_allocator")
|
||||
}
|
||||
|
||||
pub fn is_panic_runtime(&self) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(self.data());
|
||||
let attrs = decoder::get_item_attrs(self, CRATE_DEF_INDEX);
|
||||
attr::contains_name(&attrs, "panic_runtime")
|
||||
}
|
||||
|
||||
pub fn needs_panic_runtime(&self) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(self.data());
|
||||
let attrs = decoder::get_item_attrs(self, CRATE_DEF_INDEX);
|
||||
attr::contains_name(&attrs, "needs_panic_runtime")
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -38,17 +38,11 @@
|
|||
//!
|
||||
//! What record will do is to (a) record the current offset, (b) emit
|
||||
//! the `common::data_item` tag, and then call `callback_fn` with the
|
||||
//! given data as well as an `ItemContentBuilder`. Once `callback_fn`
|
||||
//! given data as well as the `EncodingContext`. Once `callback_fn`
|
||||
//! returns, the `common::data_item` tag will be closed.
|
||||
//!
|
||||
//! The `ItemContentBuilder` is another type that just offers access
|
||||
//! to the `ecx` that was given in, as well as maintaining a list of
|
||||
//! `xref` instances, which are used to extract common data so it is
|
||||
//! not re-serialized.
|
||||
//!
|
||||
//! `ItemContentBuilder` is a distinct type which does not offer the
|
||||
//! `record` method, so that we can ensure that `common::data_item` elements
|
||||
//! are never nested.
|
||||
//! `EncodingContext` does not offer the `record` method, so that we
|
||||
//! can ensure that `common::data_item` elements are never nested.
|
||||
//!
|
||||
//! In addition, while the `callback_fn` is executing, we will push a
|
||||
//! task `MetaData(some_def_id)`, which can then observe the
|
||||
|
@ -67,8 +61,7 @@ use index::IndexData;
|
|||
use rustc::dep_graph::DepNode;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc_data_structures::fnv::FnvHashMap;
|
||||
use rustc::ty::TyCtxt;
|
||||
use syntax::ast;
|
||||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
@ -77,54 +70,27 @@ use std::ops::{Deref, DerefMut};
|
|||
/// Item encoding cannot be nested.
|
||||
pub struct IndexBuilder<'a, 'b: 'a, 'tcx: 'b> {
|
||||
items: IndexData,
|
||||
builder: ItemContentBuilder<'a, 'b, 'tcx>,
|
||||
}
|
||||
|
||||
/// Builder that can encode the content of items, but can't start a
|
||||
/// new item itself. Most code is attached to here.
|
||||
pub struct ItemContentBuilder<'a, 'b: 'a, 'tcx: 'b> {
|
||||
xrefs: FnvHashMap<XRef<'tcx>, u32>, // sequentially-assigned
|
||||
pub ecx: &'a mut EncodeContext<'b, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> Deref for IndexBuilder<'a, 'b, 'tcx> {
|
||||
type Target = EncodeContext<'b, 'tcx>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.builder.ecx
|
||||
self.ecx
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> DerefMut for IndexBuilder<'a, 'b, 'tcx> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.builder.ecx
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> Deref for ItemContentBuilder<'a, 'b, 'tcx> {
|
||||
type Target = EncodeContext<'b, 'tcx>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.ecx
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> DerefMut for ItemContentBuilder<'a, 'b, 'tcx> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.ecx
|
||||
}
|
||||
}
|
||||
|
||||
/// "interned" entries referenced by id
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
pub enum XRef<'tcx> { Predicate(ty::Predicate<'tcx>) }
|
||||
|
||||
impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
|
||||
pub fn new(ecx: &'a mut EncodeContext<'b, 'tcx>) -> Self {
|
||||
IndexBuilder {
|
||||
items: IndexData::new(ecx.tcx.map.num_local_def_ids()),
|
||||
builder: ItemContentBuilder {
|
||||
ecx: ecx,
|
||||
xrefs: FnvHashMap(),
|
||||
},
|
||||
ecx: ecx,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,28 +113,21 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
|
|||
/// content system.
|
||||
pub fn record<DATA>(&mut self,
|
||||
id: DefId,
|
||||
op: fn(&mut ItemContentBuilder<'a, 'b, 'tcx>, DATA),
|
||||
op: fn(&mut EncodeContext<'b, 'tcx>, DATA),
|
||||
data: DATA)
|
||||
where DATA: DepGraphRead
|
||||
{
|
||||
let position = self.builder.ecx.mark_stable_position();
|
||||
let position = self.ecx.mark_stable_position();
|
||||
self.items.record(id, position);
|
||||
let _task = self.tcx.dep_graph.in_task(DepNode::MetaData(id));
|
||||
self.builder.ecx.start_tag(tag_items_data_item).unwrap();
|
||||
self.ecx.start_tag(tag_items_data_item).unwrap();
|
||||
data.read(self.tcx);
|
||||
op(&mut self.builder, data);
|
||||
self.builder.ecx.end_tag().unwrap();
|
||||
op(&mut self.ecx, data);
|
||||
self.ecx.end_tag().unwrap();
|
||||
}
|
||||
|
||||
pub fn into_fields(self) -> (IndexData, FnvHashMap<XRef<'tcx>, u32>) {
|
||||
(self.items, self.builder.xrefs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
|
||||
pub fn add_xref(&mut self, xref: XRef<'tcx>) -> u32 {
|
||||
let old_len = self.xrefs.len() as u32;
|
||||
*self.xrefs.entry(xref).or_insert(old_len)
|
||||
pub fn into_items(self) -> IndexData {
|
||||
self.items
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
||||
#![cfg_attr(not(stage0), deny(warnings))]
|
||||
|
||||
#![feature(conservative_impl_trait)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
|
|
@ -80,19 +80,16 @@ impl<'doc> Doc<'doc> {
|
|||
}
|
||||
|
||||
pub fn get(&self, tag: usize) -> Doc<'doc> {
|
||||
get_doc(*self, tag)
|
||||
match maybe_get_doc(*self, tag) {
|
||||
Some(d) => d,
|
||||
None => {
|
||||
bug!("failed to find block with tag {:?}", tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.start == self.end
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &'doc str {
|
||||
str::from_utf8(&self.data[self.start..self.end]).unwrap()
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
self.as_str().to_string()
|
||||
pub fn children(self) -> DocsIterator<'doc> {
|
||||
DocsIterator { d: self }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +126,7 @@ pub struct Res {
|
|||
pub next: usize,
|
||||
}
|
||||
|
||||
pub fn tag_at(data: &[u8], start: usize) -> Result<Res, Error> {
|
||||
fn tag_at(data: &[u8], start: usize) -> Result<Res, Error> {
|
||||
let v = data[start] as usize;
|
||||
if v < 0xf0 {
|
||||
Ok(Res {
|
||||
|
@ -180,7 +177,7 @@ fn vuint_at_slow(data: &[u8], start: usize) -> Result<Res, Error> {
|
|||
Err(Error::IntTooBig(a as usize))
|
||||
}
|
||||
|
||||
pub fn vuint_at(data: &[u8], start: usize) -> Result<Res, Error> {
|
||||
fn vuint_at(data: &[u8], start: usize) -> Result<Res, Error> {
|
||||
if data.len() - start < 4 {
|
||||
return vuint_at_slow(data, start);
|
||||
}
|
||||
|
@ -234,7 +231,7 @@ pub fn vuint_at(data: &[u8], start: usize) -> Result<Res, Error> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn tag_len_at(data: &[u8], next: usize) -> Result<Res, Error> {
|
||||
fn tag_len_at(data: &[u8], next: usize) -> Result<Res, Error> {
|
||||
vuint_at(data, next)
|
||||
}
|
||||
|
||||
|
@ -255,27 +252,14 @@ pub fn maybe_get_doc<'a>(d: Doc<'a>, tg: usize) -> Option<Doc<'a>> {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn get_doc<'a>(d: Doc<'a>, tg: usize) -> Doc<'a> {
|
||||
match maybe_get_doc(d, tg) {
|
||||
Some(d) => d,
|
||||
None => {
|
||||
bug!("failed to find block with tag {:?}", tg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn docs<'a>(d: Doc<'a>) -> DocsIterator<'a> {
|
||||
DocsIterator { d: d }
|
||||
}
|
||||
|
||||
pub struct DocsIterator<'a> {
|
||||
d: Doc<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for DocsIterator<'a> {
|
||||
type Item = (usize, Doc<'a>);
|
||||
type Item = Doc<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<(usize, Doc<'a>)> {
|
||||
fn next(&mut self) -> Option<Doc<'a>> {
|
||||
if self.d.start >= self.d.end {
|
||||
return None;
|
||||
}
|
||||
|
@ -297,98 +281,10 @@ impl<'a> Iterator for DocsIterator<'a> {
|
|||
};
|
||||
|
||||
self.d.start = end;
|
||||
return Some((elt_tag.val, doc));
|
||||
return Some(doc);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tagged_docs<'a>(d: Doc<'a>, tag: usize) -> TaggedDocsIterator<'a> {
|
||||
TaggedDocsIterator {
|
||||
iter: docs(d),
|
||||
tag: tag,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaggedDocsIterator<'a> {
|
||||
iter: DocsIterator<'a>,
|
||||
tag: usize,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for TaggedDocsIterator<'a> {
|
||||
type Item = Doc<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Doc<'a>> {
|
||||
while let Some((tag, doc)) = self.iter.next() {
|
||||
if tag == self.tag {
|
||||
return Some(doc);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_doc_data<T, F>(d: Doc, f: F) -> T
|
||||
where F: FnOnce(&[u8]) -> T
|
||||
{
|
||||
f(&d.data[d.start..d.end])
|
||||
}
|
||||
|
||||
pub fn doc_as_u8(d: Doc) -> u8 {
|
||||
assert_eq!(d.end, d.start + 1);
|
||||
d.data[d.start]
|
||||
}
|
||||
|
||||
pub fn doc_as_u64(d: Doc) -> u64 {
|
||||
if d.end >= 8 {
|
||||
// For performance, we read 8 big-endian bytes,
|
||||
// and mask off the junk if there is any. This
|
||||
// obviously won't work on the first 8 bytes
|
||||
// of a file - we will fall of the start
|
||||
// of the page and segfault.
|
||||
|
||||
let mut b = [0; 8];
|
||||
b.copy_from_slice(&d.data[d.end - 8..d.end]);
|
||||
let data = unsafe { (*(b.as_ptr() as *const u64)).to_be() };
|
||||
let len = d.end - d.start;
|
||||
if len < 8 {
|
||||
data & ((1 << (len * 8)) - 1)
|
||||
} else {
|
||||
data
|
||||
}
|
||||
} else {
|
||||
let mut result = 0;
|
||||
for b in &d.data[d.start..d.end] {
|
||||
result = (result << 8) + (*b as u64);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn doc_as_u16(d: Doc) -> u16 {
|
||||
doc_as_u64(d) as u16
|
||||
}
|
||||
#[inline]
|
||||
pub fn doc_as_u32(d: Doc) -> u32 {
|
||||
doc_as_u64(d) as u32
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn doc_as_i8(d: Doc) -> i8 {
|
||||
doc_as_u8(d) as i8
|
||||
}
|
||||
#[inline]
|
||||
pub fn doc_as_i16(d: Doc) -> i16 {
|
||||
doc_as_u16(d) as i16
|
||||
}
|
||||
#[inline]
|
||||
pub fn doc_as_i32(d: Doc) -> i32 {
|
||||
doc_as_u32(d) as i32
|
||||
}
|
||||
#[inline]
|
||||
pub fn doc_as_i64(d: Doc) -> i64 {
|
||||
doc_as_u64(d) as i64
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vuint_at() {
|
||||
let data = &[
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::mem;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{self, SeekFrom, Cursor};
|
||||
|
||||
|
@ -112,50 +111,10 @@ impl<'a> Encoder<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn wr_tag<F>(&mut self, tag_id: usize, blk: F) -> EncodeResult
|
||||
where F: FnOnce() -> EncodeResult
|
||||
{
|
||||
self.start_tag(tag_id)?;
|
||||
blk()?;
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
pub fn wr_tagged_bytes(&mut self, tag_id: usize, b: &[u8]) -> EncodeResult {
|
||||
write_tag(&mut self.opaque.cursor, tag_id)?;
|
||||
write_vuint(&mut self.opaque.cursor, b.len())?;
|
||||
self.opaque.cursor.write_all(b)
|
||||
}
|
||||
|
||||
pub fn wr_tagged_u64(&mut self, tag_id: usize, v: u64) -> EncodeResult {
|
||||
let bytes: [u8; 8] = unsafe { mem::transmute(v.to_be()) };
|
||||
// tagged integers are emitted in big-endian, with no
|
||||
// leading zeros.
|
||||
let leading_zero_bytes = v.leading_zeros() / 8;
|
||||
self.wr_tagged_bytes(tag_id, &bytes[leading_zero_bytes as usize..])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn wr_tagged_u32(&mut self, tag_id: usize, v: u32) -> EncodeResult {
|
||||
self.wr_tagged_u64(tag_id, v as u64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn wr_tagged_u8(&mut self, tag_id: usize, v: u8) -> EncodeResult {
|
||||
self.wr_tagged_bytes(tag_id, &[v])
|
||||
}
|
||||
|
||||
pub fn wr_tagged_str(&mut self, tag_id: usize, v: &str) -> EncodeResult {
|
||||
self.wr_tagged_bytes(tag_id, v.as_bytes())
|
||||
}
|
||||
|
||||
pub fn wr_bytes(&mut self, b: &[u8]) -> EncodeResult {
|
||||
debug!("Write {:?} bytes", b.len());
|
||||
self.opaque.cursor.write_all(b)
|
||||
}
|
||||
|
||||
pub fn wr_str(&mut self, s: &str) -> EncodeResult {
|
||||
debug!("Write str: {:?}", s);
|
||||
self.opaque.cursor.write_all(s.as_bytes())
|
||||
write_tag(&mut self.opaque.cursor, tag_id)?;
|
||||
write_vuint(&mut self.opaque.cursor, v.len())?;
|
||||
self.opaque.cursor.write_all(v.as_bytes())
|
||||
}
|
||||
|
||||
pub fn position(&mut self) -> usize {
|
||||
|
|
|
@ -21,10 +21,10 @@ use ParentLink::{ModuleParentLink, BlockParentLink};
|
|||
use Resolver;
|
||||
use {resolve_error, resolve_struct_error, ResolutionError};
|
||||
|
||||
use rustc::middle::cstore::{ChildItem, DlDef};
|
||||
use rustc::middle::cstore::ChildItem;
|
||||
use rustc::hir::def::*;
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::ty::{self, VariantKind};
|
||||
use rustc::ty;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
|
@ -201,7 +201,7 @@ impl<'b> Resolver<'b> {
|
|||
let module = self.new_extern_crate_module(parent_link, def, item.id);
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
|
||||
self.build_reduced_graph_for_external_crate(module);
|
||||
self.populate_module_if_necessary(module);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,13 +388,8 @@ impl<'b> Resolver<'b> {
|
|||
}
|
||||
|
||||
/// Builds the reduced graph for a single item in an external crate.
|
||||
fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>, xcdef: ChildItem) {
|
||||
let def = match xcdef.def {
|
||||
DlDef(def) => def,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
if let Def::ForeignMod(def_id) = def {
|
||||
fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>, child: ChildItem) {
|
||||
if let Def::ForeignMod(def_id) = child.def {
|
||||
// Foreign modules have no names. Recur and populate eagerly.
|
||||
for child in self.session.cstore.item_children(def_id) {
|
||||
self.build_reduced_graph_for_external_crate_def(parent, child);
|
||||
|
@ -402,8 +397,9 @@ impl<'b> Resolver<'b> {
|
|||
return;
|
||||
}
|
||||
|
||||
let name = xcdef.name;
|
||||
let vis = if parent.is_trait() { ty::Visibility::Public } else { xcdef.vis };
|
||||
let def = child.def;
|
||||
let name = child.name;
|
||||
let vis = if parent.is_trait() { ty::Visibility::Public } else { child.vis };
|
||||
|
||||
match def {
|
||||
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) => {
|
||||
|
@ -413,16 +409,12 @@ impl<'b> Resolver<'b> {
|
|||
let module = self.new_module(parent_link, Some(def), None);
|
||||
let _ = self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
|
||||
}
|
||||
Def::Variant(_, variant_id) => {
|
||||
Def::Variant(..) => {
|
||||
debug!("(building reduced graph for external crate) building variant {}", name);
|
||||
// Variants are always treated as importable to allow them to be glob used.
|
||||
// All variants are defined in both type and value namespaces as future-proofing.
|
||||
let _ = self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
|
||||
let _ = self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
|
||||
if self.session.cstore.variant_kind(variant_id) == Some(VariantKind::Struct) {
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
self.structs.insert(variant_id, Vec::new());
|
||||
}
|
||||
}
|
||||
Def::Fn(..) |
|
||||
Def::Static(..) |
|
||||
|
@ -439,7 +431,7 @@ impl<'b> Resolver<'b> {
|
|||
// If this is a trait, add all the trait item names to the trait
|
||||
// info.
|
||||
|
||||
let trait_item_def_ids = self.session.cstore.trait_item_def_ids(def_id);
|
||||
let trait_item_def_ids = self.session.cstore.impl_or_trait_items(def_id);
|
||||
for trait_item_def in &trait_item_def_ids {
|
||||
let trait_item_name =
|
||||
self.session.cstore.item_name(trait_item_def.def_id());
|
||||
|
@ -493,15 +485,6 @@ impl<'b> Resolver<'b> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Builds the reduced graph rooted at the 'use' directive for an external
|
||||
/// crate.
|
||||
fn build_reduced_graph_for_external_crate(&mut self, root: Module<'b>) {
|
||||
let root_cnum = root.def_id().unwrap().krate;
|
||||
for child in self.session.cstore.crate_top_level_items(root_cnum) {
|
||||
self.build_reduced_graph_for_external_crate_def(root, child);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensures that the reduced graph rooted at the given external module
|
||||
/// is built, building it if it is not.
|
||||
pub fn populate_module_if_necessary(&mut self, module: Module<'b>) {
|
||||
|
|
|
@ -1275,6 +1275,7 @@ impl<'a> Resolver<'a> {
|
|||
-> Module<'a> {
|
||||
let mut module = ModuleS::new(parent_link, Some(def), Some(local_node_id));
|
||||
module.extern_crate_id = Some(local_node_id);
|
||||
module.populated.set(false);
|
||||
self.arenas.modules.alloc(module)
|
||||
}
|
||||
|
||||
|
|
|
@ -543,10 +543,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
.map(|mr| mr.def_id())
|
||||
}
|
||||
ty::ImplContainer(def_id) => {
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
Some(impl_items.get(&def_id)
|
||||
.unwrap()
|
||||
.iter()
|
||||
let impl_items = self.tcx.impl_or_trait_items(def_id);
|
||||
Some(impl_items.iter()
|
||||
.find(|mr| {
|
||||
self.tcx.impl_or_trait_item(mr.def_id()).name() ==
|
||||
ti.name()
|
||||
|
|
|
@ -627,25 +627,23 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
|||
fn can_result_in_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> bool {
|
||||
if !match tcx.lookup_item_type(def_id).ty.sty {
|
||||
ty::TyFnDef(def_id, ..) => {
|
||||
match tcx.lookup_item_type(def_id).ty.sty {
|
||||
ty::TyFnDef(def_id, _, f) => {
|
||||
// Some constructors also have type TyFnDef but they are
|
||||
// always instantiated inline and don't result in
|
||||
// translation item. Same for FFI functions.
|
||||
match tcx.map.get_if_local(def_id) {
|
||||
Some(hir_map::NodeVariant(_)) |
|
||||
Some(hir_map::NodeStructCtor(_)) |
|
||||
Some(hir_map::NodeForeignItem(_)) => false,
|
||||
Some(_) => true,
|
||||
None => {
|
||||
tcx.sess.cstore.variant_kind(def_id).is_none()
|
||||
if let Some(hir_map::NodeForeignItem(_)) = tcx.map.get_if_local(def_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() {
|
||||
if adt_def.variants.iter().any(|v| def_id == v.did) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::TyClosure(..) => true,
|
||||
_ => false
|
||||
} {
|
||||
return false;
|
||||
ty::TyClosure(..) => {}
|
||||
_ => return false
|
||||
}
|
||||
|
||||
can_have_local_instance(tcx, def_id)
|
||||
|
|
|
@ -230,7 +230,7 @@ pub fn get_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
|
||||
tcx.populate_implementations_for_trait_if_necessary(trait_id);
|
||||
|
||||
let trait_item_def_ids = tcx.trait_item_def_ids(trait_id);
|
||||
let trait_item_def_ids = tcx.impl_or_trait_items(trait_id);
|
||||
trait_item_def_ids
|
||||
.iter()
|
||||
|
||||
|
|
|
@ -247,11 +247,17 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
|||
let vtable = common::fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref);
|
||||
if let traits::VtableImpl(vtable_impl) = vtable {
|
||||
let name = ccx.tcx().item_name(instance.def);
|
||||
for ac in ccx.tcx().associated_consts(vtable_impl.impl_def_id) {
|
||||
if ac.name == name {
|
||||
instance = Instance::new(ac.def_id, vtable_impl.substs);
|
||||
break;
|
||||
}
|
||||
let ac = ccx.tcx().impl_or_trait_items(vtable_impl.impl_def_id)
|
||||
.iter().filter_map(|id| {
|
||||
match *id {
|
||||
ty::ConstTraitItemId(def_id) => {
|
||||
Some(ccx.tcx().impl_or_trait_item(def_id))
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}).find(|ic| ic.name() == name);
|
||||
if let Some(ac) = ac {
|
||||
instance = Instance::new(ac.def_id(), vtable_impl.substs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// Trait must have a method named `m_name` and it should not have
|
||||
// type parameters or early-bound regions.
|
||||
let tcx = self.tcx;
|
||||
let method_item = self.trait_item(trait_def_id, m_name).unwrap();
|
||||
let method_item = self.impl_or_trait_item(trait_def_id, m_name).unwrap();
|
||||
let method_ty = method_item.as_opt_method().unwrap();
|
||||
assert_eq!(method_ty.generics.types.len(), 0);
|
||||
assert_eq!(method_ty.generics.regions.len(), 0);
|
||||
|
@ -359,27 +359,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
Ok(def)
|
||||
}
|
||||
|
||||
/// Find item with name `item_name` defined in `trait_def_id`
|
||||
/// and return it, or `None`, if no such item.
|
||||
pub fn trait_item(&self,
|
||||
trait_def_id: DefId,
|
||||
item_name: ast::Name)
|
||||
-> Option<ty::ImplOrTraitItem<'tcx>>
|
||||
/// Find item with name `item_name` defined in impl/trait `def_id`
|
||||
/// and return it, or `None`, if no such item was defined there.
|
||||
pub fn impl_or_trait_item(&self,
|
||||
def_id: DefId,
|
||||
item_name: ast::Name)
|
||||
-> Option<ty::ImplOrTraitItem<'tcx>>
|
||||
{
|
||||
let trait_items = self.tcx.trait_items(trait_def_id);
|
||||
trait_items.iter()
|
||||
.find(|item| item.name() == item_name)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn impl_item(&self,
|
||||
impl_def_id: DefId,
|
||||
item_name: ast::Name)
|
||||
-> Option<ty::ImplOrTraitItem<'tcx>>
|
||||
{
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
let impl_items = impl_items.get(&impl_def_id).unwrap();
|
||||
impl_items
|
||||
self.tcx.impl_or_trait_items(def_id)
|
||||
.iter()
|
||||
.map(|&did| self.tcx.impl_or_trait_item(did.def_id()))
|
||||
.find(|m| m.name() == item_name)
|
||||
|
|
|
@ -403,7 +403,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
|||
|
||||
debug!("assemble_inherent_impl_probe {:?}", impl_def_id);
|
||||
|
||||
let item = match self.impl_item(impl_def_id) {
|
||||
let item = match self.impl_or_trait_item(impl_def_id) {
|
||||
Some(m) => m,
|
||||
None => { return; } // No method with correct name on this impl
|
||||
};
|
||||
|
@ -555,7 +555,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
|||
|
||||
let tcx = self.tcx;
|
||||
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
|
||||
let item = match self.trait_item(bound_trait_ref.def_id()) {
|
||||
let item = match self.impl_or_trait_item(bound_trait_ref.def_id()) {
|
||||
Some(v) => v,
|
||||
None => { continue; }
|
||||
};
|
||||
|
@ -1292,18 +1292,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
|||
self.tcx.erase_late_bound_regions(value)
|
||||
}
|
||||
|
||||
fn impl_item(&self, impl_def_id: DefId)
|
||||
-> Option<ty::ImplOrTraitItem<'tcx>>
|
||||
/// Find item with name `item_name` defined in impl/trait `def_id`
|
||||
/// and return it, or `None`, if no such item was defined there.
|
||||
fn impl_or_trait_item(&self, def_id: DefId)
|
||||
-> Option<ty::ImplOrTraitItem<'tcx>>
|
||||
{
|
||||
self.fcx.impl_item(impl_def_id, self.item_name)
|
||||
}
|
||||
|
||||
/// Find item with name `item_name` defined in `trait_def_id`
|
||||
/// and return it, or `None`, if no such item.
|
||||
fn trait_item(&self, trait_def_id: DefId)
|
||||
-> Option<ty::ImplOrTraitItem<'tcx>>
|
||||
{
|
||||
self.fcx.trait_item(trait_def_id, self.item_name)
|
||||
self.fcx.impl_or_trait_item(def_id, self.item_name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,8 @@ use CrateCtxt;
|
|||
use check::{FnCtxt};
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::ty::{self, Ty, ToPolyTraitRef, ToPredicate, TypeFoldable};
|
||||
use middle::cstore;
|
||||
use hir::def::Def;
|
||||
use hir::def_id::DefId;
|
||||
use hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use middle::lang_items::FnOnceTraitLangItem;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::traits::{Obligation, SelectionContext};
|
||||
|
@ -92,9 +91,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
CandidateSource::ImplSource(impl_did) => {
|
||||
// Provide the best span we can. Use the item, if local to crate, else
|
||||
// the impl, if local to crate (item may be defaulted), else nothing.
|
||||
let item = self.impl_item(impl_did, item_name)
|
||||
let item = self.impl_or_trait_item(impl_did, item_name)
|
||||
.or_else(|| {
|
||||
self.trait_item(
|
||||
self.impl_or_trait_item(
|
||||
self.tcx.impl_trait_ref(impl_did).unwrap().def_id,
|
||||
|
||||
item_name
|
||||
|
@ -127,7 +126,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
CandidateSource::TraitSource(trait_did) => {
|
||||
let item = self.trait_item(trait_did, item_name).unwrap();
|
||||
let item = self.impl_or_trait_item(trait_did, item_name).unwrap();
|
||||
let item_span = self.tcx.map.def_id_span(item.def_id(), span);
|
||||
span_note!(err, item_span,
|
||||
"candidate #{} is defined in the trait `{}`",
|
||||
|
@ -321,7 +320,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// implementing a trait would be legal but is rejected
|
||||
// here).
|
||||
(type_is_local || info.def_id.is_local())
|
||||
&& self.trait_item(info.def_id, item_name).is_some()
|
||||
&& self.impl_or_trait_item(info.def_id, item_name).is_some()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -449,34 +448,30 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
|
|||
|
||||
// Cross-crate:
|
||||
let mut external_mods = FnvHashSet();
|
||||
fn handle_external_def(traits: &mut AllTraitsVec,
|
||||
fn handle_external_def(ccx: &CrateCtxt,
|
||||
traits: &mut AllTraitsVec,
|
||||
external_mods: &mut FnvHashSet<DefId>,
|
||||
ccx: &CrateCtxt,
|
||||
cstore: &for<'a> cstore::CrateStore<'a>,
|
||||
dl: cstore::DefLike) {
|
||||
match dl {
|
||||
cstore::DlDef(Def::Trait(did)) => {
|
||||
def: Def) {
|
||||
match def {
|
||||
Def::Trait(did) => {
|
||||
traits.push(TraitInfo::new(did));
|
||||
}
|
||||
cstore::DlDef(Def::Mod(did)) => {
|
||||
Def::Mod(did) => {
|
||||
if !external_mods.insert(did) {
|
||||
return;
|
||||
}
|
||||
for child in cstore.item_children(did) {
|
||||
handle_external_def(traits, external_mods,
|
||||
ccx, cstore, child.def)
|
||||
for child in ccx.tcx.sess.cstore.item_children(did) {
|
||||
handle_external_def(ccx, traits, external_mods, child.def)
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let cstore = &*ccx.tcx.sess.cstore;
|
||||
|
||||
for cnum in ccx.tcx.sess.cstore.crates() {
|
||||
for child in cstore.crate_top_level_items(cnum) {
|
||||
handle_external_def(&mut traits, &mut external_mods,
|
||||
ccx, cstore, child.def)
|
||||
}
|
||||
handle_external_def(ccx, &mut traits, &mut external_mods, Def::Mod(DefId {
|
||||
krate: cnum,
|
||||
index: CRATE_DEF_INDEX
|
||||
}));
|
||||
}
|
||||
|
||||
*ccx.all_traits.borrow_mut() = Some(traits);
|
||||
|
|
|
@ -39,6 +39,8 @@ use rustc::hir::intravisit;
|
|||
use rustc::hir::{Item, ItemImpl};
|
||||
use rustc::hir;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
mod orphan;
|
||||
mod overlap;
|
||||
mod unsafety;
|
||||
|
@ -156,7 +158,7 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
tcx.impl_items.borrow_mut().insert(impl_did, impl_items);
|
||||
tcx.impl_or_trait_item_ids.borrow_mut().insert(impl_did, Rc::new(impl_items));
|
||||
}
|
||||
|
||||
fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) {
|
||||
|
@ -208,7 +210,7 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
|
|||
tcx.populate_implementations_for_trait_if_necessary(drop_trait);
|
||||
let drop_trait = tcx.lookup_trait_def(drop_trait);
|
||||
|
||||
let impl_items = tcx.impl_items.borrow();
|
||||
let impl_items = tcx.impl_or_trait_item_ids.borrow();
|
||||
|
||||
drop_trait.for_each_impl(tcx, |impl_did| {
|
||||
let items = impl_items.get(&impl_did).unwrap();
|
||||
|
|
|
@ -55,12 +55,12 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
let impl_items = self.tcx.impl_or_trait_item_ids.borrow();
|
||||
|
||||
for item1 in &impl_items[&impl1] {
|
||||
for item1 in &impl_items[&impl1][..] {
|
||||
let (name, namespace) = name_and_namespace(self.tcx, item1);
|
||||
|
||||
for item2 in &impl_items[&impl2] {
|
||||
for item2 in &impl_items[&impl2][..] {
|
||||
if (name, namespace) == name_and_namespace(self.tcx, item2) {
|
||||
let msg = format!("duplicate definitions with name `{}`", name);
|
||||
let node_id = self.tcx.map.as_local_node_id(item1.def_id()).unwrap();
|
||||
|
|
|
@ -563,6 +563,7 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
vis: &hir::Visibility,
|
||||
sig: &hir::MethodSig,
|
||||
defaultness: hir::Defaultness,
|
||||
has_body: bool,
|
||||
untransformed_rcvr_ty: Ty<'tcx>,
|
||||
rcvr_ty_predicates: &ty::GenericPredicates<'tcx>) {
|
||||
let def_id = ccx.tcx.map.local_def_id(id);
|
||||
|
@ -580,15 +581,18 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
sig, untransformed_rcvr_ty, anon_scope)
|
||||
};
|
||||
|
||||
let ty_method = ty::Method::new(name,
|
||||
ty_generics,
|
||||
ty_generic_predicates,
|
||||
fty,
|
||||
explicit_self_category,
|
||||
ty::Visibility::from_hir(vis, id, ccx.tcx),
|
||||
defaultness,
|
||||
def_id,
|
||||
container);
|
||||
let ty_method = ty::Method {
|
||||
name: name,
|
||||
generics: ty_generics,
|
||||
predicates: ty_generic_predicates,
|
||||
fty: fty,
|
||||
explicit_self: explicit_self_category,
|
||||
vis: ty::Visibility::from_hir(vis, id, ccx.tcx),
|
||||
defaultness: defaultness,
|
||||
has_body: has_body,
|
||||
def_id: def_id,
|
||||
container: container,
|
||||
};
|
||||
|
||||
let substs = mk_item_substs(&ccx.icx(&(rcvr_ty_predicates, &sig.generics)),
|
||||
ccx.tcx.map.span(id), def_id);
|
||||
|
@ -843,7 +847,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
|
|||
|
||||
convert_method(ccx, ImplContainer(def_id),
|
||||
impl_item.name, impl_item.id, method_vis,
|
||||
sig, impl_item.defaultness, selfty,
|
||||
sig, impl_item.defaultness, true, selfty,
|
||||
&ty_predicates);
|
||||
}
|
||||
}
|
||||
|
@ -905,7 +909,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
|
|||
|
||||
// Convert all the methods
|
||||
for trait_item in trait_items {
|
||||
if let hir::MethodTraitItem(ref sig, _) = trait_item.node {
|
||||
if let hir::MethodTraitItem(ref sig, ref body) = trait_item.node {
|
||||
convert_method(ccx,
|
||||
container,
|
||||
trait_item.name,
|
||||
|
@ -913,6 +917,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
|
|||
&hir::Inherited,
|
||||
sig,
|
||||
hir::Defaultness::Default,
|
||||
body.is_some(),
|
||||
tcx.mk_self_type(),
|
||||
&trait_predicates);
|
||||
|
||||
|
@ -928,8 +933,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
|
|||
hir::TypeTraitItem(..) => ty::TypeTraitItemId(def_id)
|
||||
}
|
||||
}).collect());
|
||||
tcx.trait_item_def_ids.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id),
|
||||
trait_item_def_ids);
|
||||
tcx.impl_or_trait_item_ids.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id),
|
||||
trait_item_def_ids);
|
||||
},
|
||||
hir::ItemStruct(ref struct_def, _) |
|
||||
hir::ItemUnion(ref struct_def, _) => {
|
||||
|
|
|
@ -15,7 +15,6 @@ use std::iter::once;
|
|||
use syntax::ast;
|
||||
use rustc::hir;
|
||||
|
||||
use rustc::middle::cstore;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::print as pprust;
|
||||
|
@ -96,12 +95,12 @@ fn try_inline_def<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
Def::TyAlias(did) => {
|
||||
record_extern_fqn(cx, did, clean::TypeTypedef);
|
||||
ret.extend(build_impls(cx, tcx, did));
|
||||
build_type(cx, tcx, did)
|
||||
clean::TypedefItem(build_type_alias(cx, tcx, did), false)
|
||||
}
|
||||
Def::Enum(did) => {
|
||||
record_extern_fqn(cx, did, clean::TypeEnum);
|
||||
ret.extend(build_impls(cx, tcx, did));
|
||||
build_type(cx, tcx, did)
|
||||
clean::EnumItem(build_enum(cx, tcx, did))
|
||||
}
|
||||
// Assume that the enum type is reexported next to the variant, and
|
||||
// variants don't show up in documentation specially.
|
||||
|
@ -200,6 +199,18 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx
|
|||
}
|
||||
}
|
||||
|
||||
fn build_enum<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
did: DefId) -> clean::Enum {
|
||||
let t = tcx.lookup_item_type(did);
|
||||
let predicates = tcx.lookup_predicates(did);
|
||||
|
||||
clean::Enum {
|
||||
generics: (t.generics, &predicates).clean(cx),
|
||||
variants_stripped: false,
|
||||
variants: tcx.lookup_adt_def(did).variants.clean(cx),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
did: DefId) -> clean::Struct {
|
||||
let t = tcx.lookup_item_type(did);
|
||||
|
@ -232,25 +243,15 @@ fn build_union<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
fn build_type<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
did: DefId) -> clean::ItemEnum {
|
||||
fn build_type_alias<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
did: DefId) -> clean::Typedef {
|
||||
let t = tcx.lookup_item_type(did);
|
||||
let predicates = tcx.lookup_predicates(did);
|
||||
match t.ty.sty {
|
||||
ty::TyAdt(edef, _) if edef.is_enum() && !tcx.sess.cstore.is_typedef(did) => {
|
||||
return clean::EnumItem(clean::Enum {
|
||||
generics: (t.generics, &predicates).clean(cx),
|
||||
variants_stripped: false,
|
||||
variants: edef.variants.clean(cx),
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
clean::TypedefItem(clean::Typedef {
|
||||
clean::Typedef {
|
||||
type_: t.ty.clean(cx),
|
||||
generics: (t.generics, &predicates).clean(cx),
|
||||
}, false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_impls<'a, 'tcx>(cx: &DocContext,
|
||||
|
@ -264,32 +265,49 @@ pub fn build_impls<'a, 'tcx>(cx: &DocContext,
|
|||
build_impl(cx, tcx, did, &mut impls);
|
||||
}
|
||||
}
|
||||
|
||||
// If this is the first time we've inlined something from this crate, then
|
||||
// we inline *all* impls from the crate into this crate. Note that there's
|
||||
// If this is the first time we've inlined something from another crate, then
|
||||
// we inline *all* impls from all the crates into this crate. Note that there's
|
||||
// currently no way for us to filter this based on type, and we likely need
|
||||
// many impls for a variety of reasons.
|
||||
//
|
||||
// Primarily, the impls will be used to populate the documentation for this
|
||||
// type being inlined, but impls can also be used when generating
|
||||
// documentation for primitives (no way to find those specifically).
|
||||
if cx.populated_crate_impls.borrow_mut().insert(did.krate) {
|
||||
for item in tcx.sess.cstore.crate_top_level_items(did.krate) {
|
||||
populate_impls(cx, tcx, item.def, &mut impls);
|
||||
}
|
||||
if cx.populated_all_crate_impls.get() {
|
||||
return impls;
|
||||
}
|
||||
|
||||
fn populate_impls<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def: cstore::DefLike,
|
||||
impls: &mut Vec<clean::Item>) {
|
||||
match def {
|
||||
cstore::DlImpl(did) => build_impl(cx, tcx, did, impls),
|
||||
cstore::DlDef(Def::Mod(did)) => {
|
||||
for item in tcx.sess.cstore.item_children(did) {
|
||||
populate_impls(cx, tcx, item.def, impls)
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
cx.populated_all_crate_impls.set(true);
|
||||
|
||||
for did in tcx.sess.cstore.implementations_of_trait(None) {
|
||||
build_impl(cx, tcx, did, &mut impls);
|
||||
}
|
||||
|
||||
// Also try to inline primitive impls from other crates.
|
||||
let primitive_impls = [
|
||||
tcx.lang_items.isize_impl(),
|
||||
tcx.lang_items.i8_impl(),
|
||||
tcx.lang_items.i16_impl(),
|
||||
tcx.lang_items.i32_impl(),
|
||||
tcx.lang_items.i64_impl(),
|
||||
tcx.lang_items.usize_impl(),
|
||||
tcx.lang_items.u8_impl(),
|
||||
tcx.lang_items.u16_impl(),
|
||||
tcx.lang_items.u32_impl(),
|
||||
tcx.lang_items.u64_impl(),
|
||||
tcx.lang_items.f32_impl(),
|
||||
tcx.lang_items.f64_impl(),
|
||||
tcx.lang_items.char_impl(),
|
||||
tcx.lang_items.str_impl(),
|
||||
tcx.lang_items.slice_impl(),
|
||||
tcx.lang_items.slice_impl(),
|
||||
tcx.lang_items.const_ptr_impl()
|
||||
];
|
||||
|
||||
for def_id in primitive_impls.iter().filter_map(|&def_id| def_id) {
|
||||
if !def_id.is_local() {
|
||||
tcx.populate_implementations_for_primitive_if_necessary(def_id);
|
||||
build_impl(cx, tcx, def_id, &mut impls);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +366,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
|
|||
}
|
||||
|
||||
let predicates = tcx.lookup_predicates(did);
|
||||
let trait_items = tcx.sess.cstore.impl_items(did)
|
||||
let trait_items = tcx.sess.cstore.impl_or_trait_items(did)
|
||||
.iter()
|
||||
.filter_map(|did| {
|
||||
let did = did.def_id();
|
||||
|
@ -453,7 +471,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
|
|||
for_: for_,
|
||||
generics: (ty.generics, &predicates).clean(cx),
|
||||
items: trait_items,
|
||||
polarity: polarity.map(|p| { p.clean(cx) }),
|
||||
polarity: Some(polarity.clean(cx)),
|
||||
}),
|
||||
source: clean::Span::empty(),
|
||||
name: None,
|
||||
|
@ -482,19 +500,17 @@ fn build_module<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let mut visited = FnvHashSet();
|
||||
for item in tcx.sess.cstore.item_children(did) {
|
||||
match item.def {
|
||||
cstore::DlDef(Def::ForeignMod(did)) => {
|
||||
Def::ForeignMod(did) => {
|
||||
fill_in(cx, tcx, did, items);
|
||||
}
|
||||
cstore::DlDef(def) if item.vis == ty::Visibility::Public => {
|
||||
if !visited.insert(def) { continue }
|
||||
if let Some(i) = try_inline_def(cx, tcx, def) {
|
||||
items.extend(i)
|
||||
def => {
|
||||
if item.vis == ty::Visibility::Public {
|
||||
if !visited.insert(def) { continue }
|
||||
if let Some(i) = try_inline_def(cx, tcx, def) {
|
||||
items.extend(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
cstore::DlDef(..) => {}
|
||||
// All impls were inlined above
|
||||
cstore::DlImpl(..) => {}
|
||||
cstore::DlField => panic!("unimplemented field"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ use syntax::print::pprust as syntax_pprust;
|
|||
use syntax_pos::{self, DUMMY_SP, Pos};
|
||||
|
||||
use rustc_trans::back::link;
|
||||
use rustc::middle::cstore;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::middle::resolve_lifetime::DefRegion::*;
|
||||
use rustc::hir::def::Def;
|
||||
|
@ -239,9 +238,10 @@ impl Clean<ExternalCrate> for CrateNum {
|
|||
fn clean(&self, cx: &DocContext) -> ExternalCrate {
|
||||
let mut primitives = Vec::new();
|
||||
cx.tcx_opt().map(|tcx| {
|
||||
for item in tcx.sess.cstore.crate_top_level_items(self.0) {
|
||||
let root = DefId { krate: self.0, index: CRATE_DEF_INDEX };
|
||||
for item in tcx.sess.cstore.item_children(root) {
|
||||
let did = match item.def {
|
||||
cstore::DlDef(Def::Mod(did)) => did,
|
||||
Def::Mod(did) => did,
|
||||
_ => continue
|
||||
};
|
||||
let attrs = inline::load_attrs(cx, tcx, did);
|
||||
|
@ -1877,11 +1877,9 @@ impl Clean<Item> for hir::StructField {
|
|||
|
||||
impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
|
||||
fn clean(&self, cx: &DocContext) -> Item {
|
||||
// FIXME: possible O(n^2)-ness! Not my fault.
|
||||
let attr_map = cx.tcx().sess.cstore.crate_struct_field_attrs(self.did.krate);
|
||||
Item {
|
||||
name: Some(self.name).clean(cx),
|
||||
attrs: attr_map.get(&self.did).unwrap_or(&Vec::new()).clean(cx),
|
||||
attrs: cx.tcx().get_attrs(self.did).clean(cx),
|
||||
source: Span::empty(),
|
||||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, self.did),
|
||||
|
|
|
@ -13,13 +13,13 @@ use rustc_lint;
|
|||
use rustc_driver::{driver, target_features, abort_on_err};
|
||||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::session::{self, config};
|
||||
use rustc::hir::def_id::{CrateNum, DefId};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::lint;
|
||||
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
|
||||
use rustc::util::nodemap::FnvHashMap;
|
||||
use rustc_trans::back::link;
|
||||
use rustc_resolve as resolve;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
|
@ -53,7 +53,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
|
|||
pub map: &'a hir_map::Map<'tcx>,
|
||||
pub maybe_typed: MaybeTyped<'a, 'tcx>,
|
||||
pub input: Input,
|
||||
pub populated_crate_impls: RefCell<FnvHashSet<CrateNum>>,
|
||||
pub populated_all_crate_impls: Cell<bool>,
|
||||
pub deref_trait_did: Cell<Option<DefId>>,
|
||||
pub deref_mut_trait_did: Cell<Option<DefId>>,
|
||||
// Note that external items for which `doc(hidden)` applies to are shown as
|
||||
|
@ -205,7 +205,7 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
map: &tcx.map,
|
||||
maybe_typed: Typed(tcx),
|
||||
input: input,
|
||||
populated_crate_impls: Default::default(),
|
||||
populated_all_crate_impls: Cell::new(false),
|
||||
deref_trait_did: Cell::new(None),
|
||||
deref_mut_trait_did: Cell::new(None),
|
||||
access_levels: RefCell::new(access_levels),
|
||||
|
|
|
@ -106,8 +106,8 @@ pub fn run(input: &str,
|
|||
map: &map,
|
||||
maybe_typed: core::NotTyped(&sess),
|
||||
input: input,
|
||||
populated_all_crate_impls: Cell::new(false),
|
||||
external_traits: Default::default(),
|
||||
populated_crate_impls: Default::default(),
|
||||
deref_trait_did: Cell::new(None),
|
||||
deref_mut_trait_did: Cell::new(None),
|
||||
access_levels: Default::default(),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use rustc::middle::cstore::{CrateStore, ChildItem, DefLike};
|
||||
use rustc::middle::cstore::{CrateStore, ChildItem};
|
||||
use rustc::middle::privacy::{AccessLevels, AccessLevel};
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId};
|
||||
|
@ -66,39 +66,32 @@ impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> {
|
|||
|
||||
pub fn visit_mod(&mut self, did: DefId) {
|
||||
for item in self.cstore.item_children(did) {
|
||||
if let DefLike::DlDef(def) = item.def {
|
||||
match def {
|
||||
Def::Mod(did) |
|
||||
Def::ForeignMod(did) |
|
||||
Def::Trait(did) |
|
||||
Def::Struct(did) |
|
||||
Def::Union(did) |
|
||||
Def::Enum(did) |
|
||||
Def::TyAlias(did) |
|
||||
Def::Fn(did) |
|
||||
Def::Method(did) |
|
||||
Def::Static(did, _) |
|
||||
Def::Const(did) => self.visit_item(did, item),
|
||||
_ => {}
|
||||
}
|
||||
match item.def {
|
||||
Def::Mod(did) |
|
||||
Def::ForeignMod(did) |
|
||||
Def::Trait(did) |
|
||||
Def::Struct(did) |
|
||||
Def::Union(did) |
|
||||
Def::Enum(did) |
|
||||
Def::TyAlias(did) |
|
||||
Def::Fn(did) |
|
||||
Def::Method(did) |
|
||||
Def::Static(did, _) |
|
||||
Def::Const(did) => self.visit_item(did, item),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, did: DefId, item: ChildItem) {
|
||||
let inherited_item_level = match item.def {
|
||||
DefLike::DlImpl(..) | DefLike::DlField => unreachable!(),
|
||||
DefLike::DlDef(def) => {
|
||||
match def {
|
||||
Def::ForeignMod(..) => self.prev_level,
|
||||
_ => if item.vis == Visibility::Public { self.prev_level } else { None }
|
||||
}
|
||||
}
|
||||
Def::ForeignMod(..) => self.prev_level,
|
||||
_ => if item.vis == Visibility::Public { self.prev_level } else { None }
|
||||
};
|
||||
|
||||
let item_level = self.update(did, inherited_item_level);
|
||||
|
||||
if let DefLike::DlDef(Def::Mod(did)) = item.def {
|
||||
if let Def::Mod(did) = item.def {
|
||||
let orig_level = self.prev_level;
|
||||
|
||||
self.prev_level = item_level;
|
||||
|
|
Loading…
Add table
Reference in a new issue