stop using csearch in librustc and librustc_lint
This commit is contained in:
parent
da0444d5d4
commit
3877664b56
@ -406,4 +406,3 @@ pub fn def_path(tcx: &ty::ctxt, def: DefId) -> ast_map::DefPath {
|
||||
let local_path = cdata.local_def_path();
|
||||
local_path.into_iter().chain(path).collect()
|
||||
}
|
||||
|
||||
|
@ -21,3 +21,4 @@ pub mod loader;
|
||||
pub mod filesearch;
|
||||
pub mod macro_import;
|
||||
pub mod inline;
|
||||
pub mod util;
|
||||
|
324
src/librustc/metadata/util.rs
Normal file
324
src/librustc/metadata/util.rs
Normal file
@ -0,0 +1,324 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use front::map as ast_map;
|
||||
use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
use middle::astencode;
|
||||
use middle::lang_items;
|
||||
use middle::ty;
|
||||
use middle::def_id::{DefId, DefIndex};
|
||||
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use rustc_front::hir;
|
||||
|
||||
pub use metadata::csearch::FoundAst;
|
||||
pub use metadata::cstore::LinkagePreference;
|
||||
pub use metadata::decoder::DecodeInlinedItem;
|
||||
pub use metadata::inline::InlinedItem;
|
||||
|
||||
pub trait CrateStore<'tcx> {
|
||||
// item info
|
||||
fn stability(&self, def: DefId) -> Option<attr::Stability>;
|
||||
fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
|
||||
-> ty::ClosureKind;
|
||||
fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
|
||||
-> ty::ClosureTy<'tcx>;
|
||||
fn item_variances(&self, def: DefId) -> ty::ItemVariances;
|
||||
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr>;
|
||||
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::TypeScheme<'tcx>;
|
||||
fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem>;
|
||||
fn item_name(&self, def: DefId) -> ast::Name;
|
||||
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::GenericPredicates<'tcx>;
|
||||
fn item_super_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::GenericPredicates<'tcx>;
|
||||
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
|
||||
fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
|
||||
fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'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(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::Method<'tcx>>>;
|
||||
fn trait_item_def_ids(&self, def: DefId)
|
||||
-> Vec<ty::ImplOrTraitItemId>;
|
||||
|
||||
// impl info
|
||||
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
|
||||
fn impl_trait_ref(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> Option<ty::TraitRef<'tcx>>;
|
||||
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>;
|
||||
fn custom_coerce_unsized_kind(&self, def: DefId)
|
||||
-> Option<ty::adjustment::CustomCoerceUnsized>;
|
||||
fn associated_consts(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::AssociatedConst<'tcx>>>;
|
||||
|
||||
// trait/impl-item info
|
||||
fn trait_of_item(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
|
||||
-> Option<DefId>;
|
||||
fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::ImplOrTraitItem<'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;
|
||||
|
||||
// metadata
|
||||
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
|
||||
-> Vec<(ast::CrateNum, cstore::LinkagePreference)>;
|
||||
fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>;
|
||||
fn missing_lang_items(&self, cnum: ast::CrateNum)
|
||||
-> Vec<lang_items::LangItem>;
|
||||
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool;
|
||||
|
||||
// misc.
|
||||
fn def_path(&self, def: DefId) -> ast_map::DefPath;
|
||||
fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> FoundAst<'tcx>;
|
||||
}
|
||||
|
||||
impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
||||
fn stability(&self, def: DefId) -> Option<attr::Stability>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_stability(&*cdata, def.index)
|
||||
}
|
||||
|
||||
fn closure_kind(&self, _tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureKind
|
||||
{
|
||||
assert!(!def_id.is_local());
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::closure_kind(&*cdata, def_id.index)
|
||||
}
|
||||
|
||||
fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureTy<'tcx>
|
||||
{
|
||||
assert!(!def_id.is_local());
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::closure_ty(&*cdata, def_id.index, tcx)
|
||||
}
|
||||
|
||||
fn item_variances(&self, def: DefId) -> ty::ItemVariances {
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_item_variances(&*cdata, def.index)
|
||||
}
|
||||
|
||||
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr> {
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_repr_attrs(&*cdata, def.index)
|
||||
}
|
||||
|
||||
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::TypeScheme<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_type(&*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::GenericPredicates<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_predicates(&*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn item_super_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::GenericPredicates<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_super_predicates(&*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>
|
||||
{
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::get_item_attrs(&*cdata, def_id.index)
|
||||
}
|
||||
|
||||
fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::TraitDef<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_trait_def(&*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_adt_def(&self.intr, &*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem> {
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
let path = decoder::get_item_path(&*cdata, def.index);
|
||||
|
||||
cdata.with_local_path(|cpath| {
|
||||
let mut r = Vec::with_capacity(cpath.len() + path.len());
|
||||
r.push_all(cpath);
|
||||
r.push_all(&path);
|
||||
r
|
||||
})
|
||||
}
|
||||
|
||||
fn item_name(&self, def: DefId) -> ast::Name {
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_item_name(&self.intr, &cdata, def.index)
|
||||
}
|
||||
|
||||
|
||||
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>
|
||||
{
|
||||
let mut result = vec![];
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::each_inherent_implementation_for_type(&*cdata, def_id.index,
|
||||
|iid| result.push(iid));
|
||||
result
|
||||
}
|
||||
|
||||
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>
|
||||
{
|
||||
let mut result = vec![];
|
||||
self.iter_crate_data(|_, cdata| {
|
||||
decoder::each_implementation_for_trait(cdata, def_id, &mut |iid| {
|
||||
result.push(iid)
|
||||
})
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
fn provided_trait_methods(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::Method<'tcx>>>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_provided_trait_methods(self.intr.clone(), &*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn trait_item_def_ids(&self, def: DefId)
|
||||
-> Vec<ty::ImplOrTraitItemId>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_impl_polarity(&*cdata, def.index)
|
||||
}
|
||||
|
||||
fn impl_trait_ref(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> Option<ty::TraitRef<'tcx>>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_impl_trait(&*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn custom_coerce_unsized_kind(&self, def: DefId)
|
||||
-> Option<ty::adjustment::CustomCoerceUnsized>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_custom_coerce_unsized_kind(&*cdata, def.index)
|
||||
}
|
||||
|
||||
// FIXME: killme
|
||||
fn associated_consts(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> Vec<Rc<ty::AssociatedConst<'tcx>>> {
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_associated_consts(self.intr.clone(), &*cdata, def.index, tcx)
|
||||
}
|
||||
|
||||
fn trait_of_item(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) -> Option<DefId>
|
||||
{
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::get_trait_of_item(&*cdata, def_id.index, tcx)
|
||||
}
|
||||
|
||||
fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> ty::ImplOrTraitItem<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
decoder::get_impl_or_trait_item(
|
||||
self.intr.clone(),
|
||||
&*cdata,
|
||||
def.index,
|
||||
tcx)
|
||||
}
|
||||
|
||||
fn is_const_fn(&self, did: DefId) -> bool
|
||||
{
|
||||
let cdata = self.get_crate_data(did.krate);
|
||||
decoder::is_const_fn(&cdata, did.index)
|
||||
}
|
||||
|
||||
fn is_defaulted_trait(&self, trait_def_id: DefId) -> bool {
|
||||
let cdata = self.get_crate_data(trait_def_id.krate);
|
||||
decoder::is_defaulted_trait(&*cdata, trait_def_id.index)
|
||||
}
|
||||
|
||||
fn is_impl(&self, did: DefId) -> bool {
|
||||
let cdata = self.get_crate_data(did.krate);
|
||||
decoder::is_impl(&*cdata, did.index)
|
||||
}
|
||||
|
||||
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
|
||||
-> Vec<(ast::CrateNum, cstore::LinkagePreference)>
|
||||
{
|
||||
let cdata = self.get_crate_data(cnum);
|
||||
decoder::get_dylib_dependency_formats(&cdata)
|
||||
}
|
||||
|
||||
fn lang_items(&self, cnum: ast::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
|
||||
}
|
||||
|
||||
fn missing_lang_items(&self, cnum: ast::CrateNum)
|
||||
-> Vec<lang_items::LangItem>
|
||||
{
|
||||
let cdata = self.get_crate_data(cnum);
|
||||
decoder::get_missing_lang_items(&*cdata)
|
||||
}
|
||||
|
||||
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool
|
||||
{
|
||||
self.get_crate_data(cnum).staged_api
|
||||
}
|
||||
|
||||
fn def_path(&self, def: DefId) -> ast_map::DefPath {
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
let path = decoder::def_path(&*cdata, def.index);
|
||||
let local_path = cdata.local_def_path();
|
||||
local_path.into_iter().chain(path).collect()
|
||||
}
|
||||
|
||||
fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId)
|
||||
-> FoundAst<'tcx>
|
||||
{
|
||||
let cdata = self.get_crate_data(def.krate);
|
||||
let decode_inlined_item = Box::new(astencode::decode_inlined_item);
|
||||
decoder::maybe_get_item_ast(&*cdata, tcx, def.index, decode_inlined_item)
|
||||
}
|
||||
}
|
@ -16,9 +16,8 @@ use self::EvalHint::*;
|
||||
|
||||
use front::map as ast_map;
|
||||
use front::map::blocks::FnLikeNode;
|
||||
use metadata::csearch;
|
||||
use metadata::inline::InlinedItem;
|
||||
use middle::{astencode, def, infer, subst, traits};
|
||||
use metadata::util::{self as mdutil, CrateStore, InlinedItem};
|
||||
use middle::{def, infer, subst, traits};
|
||||
use middle::def_id::DefId;
|
||||
use middle::pat_util::def_to_path;
|
||||
use middle::ty::{self, Ty};
|
||||
@ -145,13 +144,12 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
|
||||
None => {}
|
||||
}
|
||||
let mut used_ref_id = false;
|
||||
let expr_id = match csearch::maybe_get_item_ast(tcx, def_id,
|
||||
Box::new(astencode::decode_inlined_item)) {
|
||||
csearch::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node {
|
||||
let expr_id = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) {
|
||||
mdutil::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node {
|
||||
hir::ItemConst(_, ref const_expr) => Some(const_expr.id),
|
||||
_ => None
|
||||
},
|
||||
csearch::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node {
|
||||
mdutil::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node {
|
||||
hir::ConstTraitItem(_, _) => {
|
||||
used_ref_id = true;
|
||||
match maybe_ref_id {
|
||||
@ -170,7 +168,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
|
||||
}
|
||||
_ => None
|
||||
},
|
||||
csearch::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node {
|
||||
mdutil::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node {
|
||||
hir::ImplItemKind::Const(_, ref expr) => Some(expr.id),
|
||||
_ => None
|
||||
},
|
||||
@ -196,15 +194,14 @@ fn inline_const_fn_from_external_crate(tcx: &ty::ctxt, def_id: DefId)
|
||||
None => {}
|
||||
}
|
||||
|
||||
if !csearch::is_const_fn(&tcx.sess.cstore, def_id) {
|
||||
if !tcx.sess.cstore.is_const_fn(def_id) {
|
||||
tcx.extern_const_fns.borrow_mut().insert(def_id, ast::DUMMY_NODE_ID);
|
||||
return None;
|
||||
}
|
||||
|
||||
let fn_id = match csearch::maybe_get_item_ast(tcx, def_id,
|
||||
box astencode::decode_inlined_item) {
|
||||
csearch::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id),
|
||||
csearch::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id),
|
||||
let fn_id = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) {
|
||||
mdutil::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id),
|
||||
mdutil::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id),
|
||||
_ => None
|
||||
};
|
||||
tcx.extern_const_fns.borrow_mut().insert(def_id,
|
||||
|
@ -65,8 +65,8 @@ use syntax::ast;
|
||||
|
||||
use session;
|
||||
use session::config;
|
||||
use metadata::cstore;
|
||||
use metadata::csearch;
|
||||
use metadata::util::CrateStore;
|
||||
use metadata::util::LinkagePreference::{self, RequireStatic, RequireDynamic};
|
||||
use util::nodemap::FnvHashMap;
|
||||
|
||||
/// A list of dependencies for a certain crate type.
|
||||
@ -155,8 +155,8 @@ fn calculate_type(sess: &session::Session,
|
||||
let src = sess.cstore.get_used_crate_source(cnum).unwrap();
|
||||
if src.dylib.is_some() {
|
||||
info!("adding dylib: {}", data.name);
|
||||
add_library(sess, cnum, cstore::RequireDynamic, &mut formats);
|
||||
let deps = csearch::get_dylib_dependency_formats(&sess.cstore, cnum);
|
||||
add_library(sess, cnum, RequireDynamic, &mut formats);
|
||||
let deps = sess.cstore.dylib_dependency_formats(cnum);
|
||||
for &(depnum, style) in &deps {
|
||||
info!("adding {:?}: {}", style,
|
||||
sess.cstore.get_crate_data(depnum).name.clone());
|
||||
@ -168,8 +168,8 @@ fn calculate_type(sess: &session::Session,
|
||||
// Collect what we've got so far in the return vector.
|
||||
let mut ret = (1..sess.cstore.next_crate_num()).map(|i| {
|
||||
match formats.get(&i) {
|
||||
Some(&cstore::RequireDynamic) => Linkage::Dynamic,
|
||||
Some(&cstore::RequireStatic) => Linkage::IncludedFromDylib,
|
||||
Some(&RequireDynamic) => Linkage::Dynamic,
|
||||
Some(&RequireStatic) => Linkage::IncludedFromDylib,
|
||||
None => Linkage::NotLinked,
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
@ -186,7 +186,7 @@ fn calculate_type(sess: &session::Session,
|
||||
data.explicitly_linked.get() {
|
||||
assert!(src.rlib.is_some());
|
||||
info!("adding staticlib: {}", data.name);
|
||||
add_library(sess, cnum, cstore::RequireStatic, &mut formats);
|
||||
add_library(sess, cnum, RequireStatic, &mut formats);
|
||||
ret[cnum as usize - 1] = Linkage::Static;
|
||||
}
|
||||
});
|
||||
@ -229,8 +229,8 @@ fn calculate_type(sess: &session::Session,
|
||||
|
||||
fn add_library(sess: &session::Session,
|
||||
cnum: ast::CrateNum,
|
||||
link: cstore::LinkagePreference,
|
||||
m: &mut FnvHashMap<ast::CrateNum, cstore::LinkagePreference>) {
|
||||
link: LinkagePreference,
|
||||
m: &mut FnvHashMap<ast::CrateNum, LinkagePreference>) {
|
||||
match m.get(&cnum) {
|
||||
Some(&link2) => {
|
||||
// If the linkages differ, then we'd have two copies of the library
|
||||
@ -240,7 +240,7 @@ fn add_library(sess: &session::Session,
|
||||
//
|
||||
// This error is probably a little obscure, but I imagine that it
|
||||
// can be refined over time.
|
||||
if link2 != link || link == cstore::RequireStatic {
|
||||
if link2 != link || link == RequireStatic {
|
||||
let data = sess.cstore.get_crate_data(cnum);
|
||||
sess.err(&format!("cannot satisfy dependencies so `{}` only \
|
||||
shows up once", data.name));
|
||||
@ -253,7 +253,7 @@ fn add_library(sess: &session::Session,
|
||||
}
|
||||
|
||||
fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
|
||||
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
|
||||
let crates = sess.cstore.get_used_crates(RequireStatic);
|
||||
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
|
||||
return None
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ pub use self::LangItem::*;
|
||||
|
||||
use front::map as hir_map;
|
||||
use session::Session;
|
||||
use metadata::csearch::each_lang_item;
|
||||
use metadata::util::CrateStore;
|
||||
use middle::def_id::DefId;
|
||||
use middle::ty;
|
||||
use middle::weak_lang_items;
|
||||
@ -205,11 +205,10 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
|
||||
pub fn collect_external_language_items(&mut self) {
|
||||
let crate_store = &self.session.cstore;
|
||||
crate_store.iter_crate_data(|crate_number, _crate_metadata| {
|
||||
each_lang_item(crate_store, crate_number, |index, item_index| {
|
||||
for (index, item_index) in crate_store.lang_items(crate_number) {
|
||||
let def_id = DefId { krate: crate_number, index: index };
|
||||
self.collect_item(item_index, def_id, DUMMY_SP);
|
||||
true
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,11 @@ pub use self::StabilityLevel::*;
|
||||
use session::Session;
|
||||
use lint;
|
||||
use metadata::cstore::LOCAL_CRATE;
|
||||
use metadata::util::CrateStore;
|
||||
use middle::def;
|
||||
use middle::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use middle::ty;
|
||||
use middle::privacy::AccessLevels;
|
||||
use metadata::csearch;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
use syntax::ast;
|
||||
@ -621,7 +621,7 @@ fn is_staged_api(tcx: &ty::ctxt, id: DefId) -> bool {
|
||||
}
|
||||
_ => {
|
||||
*tcx.stability.borrow_mut().staged_api.entry(id.krate).or_insert_with(
|
||||
|| csearch::is_staged_api(&tcx.sess.cstore, id.krate))
|
||||
|| tcx.sess.cstore.is_staged_api(id.krate))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -653,7 +653,7 @@ fn lookup_uncached<'tcx>(tcx: &ty::ctxt<'tcx>, id: DefId) -> Option<&'tcx Stabil
|
||||
let item_stab = if id.is_local() {
|
||||
None // The stability cache is filled partially lazily
|
||||
} else {
|
||||
csearch::get_stability(&tcx.sess.cstore, id).map(|st| tcx.intern_stability(st))
|
||||
tcx.sess.cstore.stability(id).map(|st| tcx.intern_stability(st))
|
||||
};
|
||||
|
||||
item_stab.or_else(|| {
|
||||
|
@ -16,7 +16,7 @@
|
||||
use front::map as ast_map;
|
||||
use session::Session;
|
||||
use lint;
|
||||
use metadata::csearch;
|
||||
use metadata::util::CrateStore;
|
||||
use middle;
|
||||
use middle::def::DefMap;
|
||||
use middle::def_id::DefId;
|
||||
@ -155,7 +155,7 @@ impl<'tcx> Tables<'tcx> {
|
||||
return kind;
|
||||
}
|
||||
|
||||
let kind = csearch::closure_kind(tcx, def_id);
|
||||
let kind = tcx.sess.cstore.closure_kind(tcx, def_id);
|
||||
this.borrow_mut().closure_kinds.insert(def_id, kind);
|
||||
kind
|
||||
}
|
||||
@ -173,7 +173,7 @@ impl<'tcx> Tables<'tcx> {
|
||||
return ty.subst(tcx, &substs.func_substs);
|
||||
}
|
||||
|
||||
let ty = csearch::closure_ty(tcx, def_id);
|
||||
let ty = tcx.sess.cstore.closure_ty(tcx, def_id);
|
||||
this.borrow_mut().closure_tys.insert(def_id, ty.clone());
|
||||
ty.subst(tcx, &substs.func_substs)
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ pub use self::LvaluePreference::*;
|
||||
|
||||
use front::map as ast_map;
|
||||
use front::map::LinkedPath;
|
||||
use metadata::csearch;
|
||||
use metadata::cstore::LOCAL_CRATE;
|
||||
use metadata::util::CrateStore;
|
||||
use middle;
|
||||
use middle::def::{self, ExportMap};
|
||||
use middle::def_id::DefId;
|
||||
@ -2131,7 +2131,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
self.sess.bug(&format!("provided_trait_methods: `{:?}` is not a trait", id))
|
||||
}
|
||||
} else {
|
||||
csearch::get_provided_trait_methods(self, id)
|
||||
self.sess.cstore.provided_trait_methods(self, id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2176,7 +2176,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
csearch::get_associated_consts(self, id)
|
||||
self.sess.cstore.associated_consts(self, id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2208,14 +2208,14 @@ impl<'tcx> ctxt<'tcx> {
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
csearch::get_impl_polarity(self, id)
|
||||
self.sess.cstore.impl_polarity(id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn custom_coerce_unsized_kind(&self, did: DefId) -> adjustment::CustomCoerceUnsized {
|
||||
memoized(&self.custom_coerce_unsized_kinds, did, |did: DefId| {
|
||||
let (kind, src) = if did.krate != LOCAL_CRATE {
|
||||
(csearch::get_custom_coerce_unsized_kind(self, did), "external")
|
||||
(self.sess.cstore.custom_coerce_unsized_kind(did), "external")
|
||||
} else {
|
||||
(None, "local")
|
||||
};
|
||||
@ -2234,13 +2234,13 @@ impl<'tcx> ctxt<'tcx> {
|
||||
pub fn impl_or_trait_item(&self, id: DefId) -> ImplOrTraitItem<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"impl_or_trait_items", id, &self.impl_or_trait_items,
|
||||
|| csearch::get_impl_or_trait_item(self, id))
|
||||
|| self.sess.cstore.impl_or_trait_item(self, id))
|
||||
}
|
||||
|
||||
pub fn trait_item_def_ids(&self, id: DefId) -> Rc<Vec<ImplOrTraitItemId>> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"trait_item_def_ids", id, &self.trait_item_def_ids,
|
||||
|| Rc::new(csearch::get_trait_item_def_ids(&self.sess.cstore, id)))
|
||||
|| Rc::new(self.sess.cstore.trait_item_def_ids(id)))
|
||||
}
|
||||
|
||||
/// Returns the trait-ref corresponding to a given impl, or None if it is
|
||||
@ -2248,7 +2248,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
pub fn impl_trait_ref(&self, id: DefId) -> Option<TraitRef<'tcx>> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"impl_trait_refs", id, &self.impl_trait_refs,
|
||||
|| csearch::get_impl_trait(self, id))
|
||||
|| self.sess.cstore.impl_trait_ref(self, id))
|
||||
}
|
||||
|
||||
/// Returns whether this DefId refers to an impl
|
||||
@ -2261,7 +2261,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
csearch::is_impl(&self.sess.cstore, id)
|
||||
self.sess.cstore.is_impl(id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2277,7 +2277,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
if id.is_local() {
|
||||
self.map.def_path(id)
|
||||
} else {
|
||||
csearch::def_path(self, id)
|
||||
self.sess.cstore.def_path(id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2287,7 +2287,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
self.map.with_path(id, f)
|
||||
} else {
|
||||
f(csearch::get_item_path(self, id).iter().cloned().chain(LinkedPath::empty()))
|
||||
f(self.sess.cstore.item_path(id).iter().cloned().chain(LinkedPath::empty()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -2295,7 +2295,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
self.map.get_path_elem(id).name()
|
||||
} else {
|
||||
csearch::get_item_name(self, id)
|
||||
self.sess.cstore.item_name(id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2309,14 +2309,14 @@ impl<'tcx> ctxt<'tcx> {
|
||||
pub fn lookup_item_type(&self, did: DefId) -> TypeScheme<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"tcache", did, &self.tcache,
|
||||
|| csearch::get_type(self, did))
|
||||
|| self.sess.cstore.item_type(self, did))
|
||||
}
|
||||
|
||||
/// Given the did of a trait, returns its canonical trait ref.
|
||||
pub fn lookup_trait_def(&self, did: DefId) -> &'tcx TraitDef<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"trait_defs", did, &self.trait_defs,
|
||||
|| self.alloc_trait_def(csearch::get_trait_def(self, did))
|
||||
|| self.alloc_trait_def(self.sess.cstore.trait_def(self, did))
|
||||
)
|
||||
}
|
||||
|
||||
@ -2326,7 +2326,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
pub fn lookup_adt_def_master(&self, did: DefId) -> AdtDefMaster<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"adt_defs", did, &self.adt_defs,
|
||||
|| csearch::get_adt_def(self, did)
|
||||
|| self.sess.cstore.adt_def(self, did)
|
||||
)
|
||||
}
|
||||
|
||||
@ -2341,14 +2341,14 @@ impl<'tcx> ctxt<'tcx> {
|
||||
pub fn lookup_predicates(&self, did: DefId) -> GenericPredicates<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"predicates", did, &self.predicates,
|
||||
|| csearch::get_predicates(self, did))
|
||||
|| self.sess.cstore.item_predicates(self, did))
|
||||
}
|
||||
|
||||
/// Given the did of a trait, returns its superpredicates.
|
||||
pub fn lookup_super_predicates(&self, did: DefId) -> GenericPredicates<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"super_predicates", did, &self.super_predicates,
|
||||
|| csearch::get_super_predicates(self, did))
|
||||
|| self.sess.cstore.item_super_predicates(self, did))
|
||||
}
|
||||
|
||||
/// Get the attributes of a definition.
|
||||
@ -2356,7 +2356,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
if let Some(id) = self.map.as_local_node_id(did) {
|
||||
Cow::Borrowed(self.map.attrs(id))
|
||||
} else {
|
||||
Cow::Owned(csearch::get_item_attrs(&self.sess.cstore, did))
|
||||
Cow::Owned(self.sess.cstore.item_attrs(did))
|
||||
}
|
||||
}
|
||||
|
||||
@ -2384,7 +2384,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
attr::find_repr_attrs(self.sess.diagnostic(), meta).into_iter()
|
||||
}).collect()
|
||||
} else {
|
||||
csearch::get_repr_attrs(&self.sess.cstore, did)
|
||||
self.sess.cstore.repr_attrs(did)
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -2392,7 +2392,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
pub fn item_variances(&self, item_id: DefId) -> Rc<ItemVariances> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"item_variance_map", item_id, &self.item_variance_map,
|
||||
|| Rc::new(csearch::get_item_variances(&self.sess.cstore, item_id)))
|
||||
|| Rc::new(self.sess.cstore.item_variances(item_id)))
|
||||
}
|
||||
|
||||
pub fn trait_has_default_impl(&self, trait_def_id: DefId) -> bool {
|
||||
@ -2422,7 +2422,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
debug!("populate_implementations_for_primitive_if_necessary: searching for {:?}",
|
||||
primitive_def_id);
|
||||
|
||||
let impl_items = csearch::get_impl_items(&self.sess.cstore, primitive_def_id);
|
||||
let impl_items = self.sess.cstore.impl_items(primitive_def_id);
|
||||
|
||||
// Store the implementation info.
|
||||
self.impl_items.borrow_mut().insert(primitive_def_id, impl_items);
|
||||
@ -2444,15 +2444,12 @@ impl<'tcx> ctxt<'tcx> {
|
||||
debug!("populate_inherent_implementations_for_type_if_necessary: searching for {:?}",
|
||||
type_id);
|
||||
|
||||
let mut inherent_impls = Vec::new();
|
||||
csearch::each_inherent_implementation_for_type(&self.sess.cstore, type_id, |impl_def_id| {
|
||||
// Record the implementation.
|
||||
inherent_impls.push(impl_def_id);
|
||||
|
||||
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 = csearch::get_impl_items(&self.sess.cstore, impl_def_id);
|
||||
let impl_items = self.sess.cstore.impl_items(impl_def_id);
|
||||
self.impl_items.borrow_mut().insert(impl_def_id, impl_items);
|
||||
});
|
||||
}
|
||||
|
||||
self.inherent_impls.borrow_mut().insert(type_id, Rc::new(inherent_impls));
|
||||
self.populated_external_types.borrow_mut().insert(type_id);
|
||||
@ -2472,12 +2469,12 @@ impl<'tcx> ctxt<'tcx> {
|
||||
|
||||
debug!("populate_implementations_for_trait_if_necessary: searching for {:?}", def);
|
||||
|
||||
if csearch::is_defaulted_trait(&self.sess.cstore, trait_id) {
|
||||
if self.sess.cstore.is_defaulted_trait(trait_id) {
|
||||
self.record_trait_has_default_impl(trait_id);
|
||||
}
|
||||
|
||||
csearch::each_implementation_for_trait(&self.sess.cstore, trait_id, |impl_def_id| {
|
||||
let impl_items = csearch::get_impl_items(&self.sess.cstore, impl_def_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);
|
||||
let trait_ref = self.impl_trait_ref(impl_def_id).unwrap();
|
||||
// Record the trait->implementation mapping.
|
||||
def.record_impl(self, impl_def_id, trait_ref);
|
||||
@ -2493,7 +2490,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
|
||||
// Store the implementation info.
|
||||
self.impl_items.borrow_mut().insert(impl_def_id, impl_items);
|
||||
});
|
||||
}
|
||||
|
||||
def.flags.set(def.flags.get() | TraitFlags::IMPLS_VALID);
|
||||
}
|
||||
@ -2520,8 +2517,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
/// ID of the impl that the method belongs to. Otherwise, return `None`.
|
||||
pub fn impl_of_method(&self, def_id: DefId) -> Option<DefId> {
|
||||
if def_id.krate != LOCAL_CRATE {
|
||||
return match csearch::get_impl_or_trait_item(self,
|
||||
def_id).container() {
|
||||
return match self.sess.cstore.impl_or_trait_item(self, def_id).container() {
|
||||
TraitContainer(_) => None,
|
||||
ImplContainer(def_id) => Some(def_id),
|
||||
};
|
||||
@ -2542,7 +2538,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
/// the trait that the method belongs to. Otherwise, return `None`.
|
||||
pub fn trait_of_item(&self, def_id: DefId) -> Option<DefId> {
|
||||
if def_id.krate != LOCAL_CRATE {
|
||||
return csearch::get_trait_of_item(&self.sess.cstore, def_id, self);
|
||||
return self.sess.cstore.trait_of_item(self, def_id);
|
||||
}
|
||||
match self.impl_or_trait_items.borrow().get(&def_id).cloned() {
|
||||
Some(impl_or_trait_item) => {
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
use session::config;
|
||||
use session::Session;
|
||||
use metadata::csearch;
|
||||
use metadata::util::CrateStore;
|
||||
use middle::lang_items;
|
||||
|
||||
use syntax::ast;
|
||||
@ -80,8 +80,8 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
|
||||
|
||||
let mut missing = HashSet::new();
|
||||
sess.cstore.iter_crate_data(|cnum, _| {
|
||||
for item in &csearch::get_missing_lang_items(&sess.cstore, cnum) {
|
||||
missing.insert(*item);
|
||||
for item in sess.cstore.missing_lang_items(cnum) {
|
||||
missing.insert(item);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -8,11 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use metadata::csearch;
|
||||
use middle::pat_util;
|
||||
use middle::ty;
|
||||
use middle::ty::adjustment;
|
||||
use rustc::front::map as hir_map;
|
||||
use util::nodemap::FnvHashMap;
|
||||
use lint::{LateContext, EarlyContext, LintContext, LintArray};
|
||||
use lint::{LintPass, EarlyLintPass, LateLintPass};
|
||||
@ -138,16 +136,8 @@ impl LateLintPass for UnusedResults {
|
||||
ty::TyBool => return,
|
||||
ty::TyStruct(def, _) |
|
||||
ty::TyEnum(def, _) => {
|
||||
if let Some(def_node_id) = cx.tcx.map.as_local_node_id(def.did) {
|
||||
if let hir_map::NodeItem(it) = cx.tcx.map.get(def_node_id) {
|
||||
check_must_use(cx, &it.attrs, s.span)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
let attrs = csearch::get_item_attrs(&cx.sess().cstore, def.did);
|
||||
check_must_use(cx, &attrs[..], s.span)
|
||||
}
|
||||
let attrs = cx.tcx.get_attrs(def.did);
|
||||
check_must_use(cx, &attrs[..], s.span)
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
@ -459,4 +449,3 @@ impl LateLintPass for UnusedAllocation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user