This commit is contained in:
Ariel Ben-Yehuda 2015-11-25 17:02:59 +02:00
parent 52dd2b4c35
commit 4190dce3a7
7 changed files with 32 additions and 27 deletions
src
librustc/middle
librustc_driver
librustc_metadata
librustdoc/clean
test/compile-fail

@ -42,7 +42,7 @@ use syntax::codemap::Span;
use syntax::ptr::P;
use rustc_back::target::Target;
use rustc_front::hir;
use rustc_front::visit::Visitor;
use rustc_front::intravisit::Visitor;
use rustc_front::util::IdVisitor;
pub use self::DefLike::{DlDef, DlField, DlImpl};
@ -123,6 +123,13 @@ pub enum FoundAst<'ast> {
NotFound,
}
/// A store of Rust crates, through with their metadata
/// can be accessed.
///
/// The `: Any` bound is a temporary measure that allows access
/// to the backing `rustc_metadata::cstore::CStore` object. It
/// will be removed in the near future - if you need to access
/// internal APIs, please tell us.
pub trait CrateStore<'tcx> : Any {
// item info
fn stability(&self, def: DefId) -> Option<attr::Stability>;
@ -244,11 +251,7 @@ impl InlinedItem {
}
pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
let mut id_visitor = IdVisitor {
operation: operation,
pass_through_items: true,
visited_outermost: false,
};
let mut id_visitor = IdVisitor::new(operation);
self.visit(&mut id_visitor);
}
}

@ -106,7 +106,10 @@ pub mod target_features;
const BUG_REPORT_URL: &'static str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
md#bug-reports";
// [stage0]: kill this
// SNAP 1af31d4
// This is a terrible hack. Our stage0 is older than 1.4 and does not
// support DST coercions, so this function performs the corecion
// manually. This should go away.
pub fn cstore_to_cratestore(a: Rc<CStore>) -> Rc<for<'s> CrateStore<'s>>
{
use std::mem;

@ -20,7 +20,7 @@ use loader::{self, CratePaths};
use rustc::back::svh::Svh;
use rustc::session::{config, Session};
use rustc::session::search_paths::PathKind;
use rustc::middle::cstore::validate_crate_name;
use rustc::middle::cstore::{CrateStore, validate_crate_name};
use rustc::util::nodemap::FnvHashMap;
use rustc::front::map as hir_map;
@ -223,7 +223,7 @@ impl<'a> CrateReader<'a> {
// We're also sure to compare *paths*, not actual byte slices. The
// `source` stores paths which are normalized which may be different
// from the strings on the command line.
let source = self.cstore.do_get_used_crate_source(cnum).unwrap();
let source = self.cstore.used_crate_source(cnum);
if let Some(locs) = self.sess.opts.externs.get(name) {
let found = locs.iter().any(|l| {
let l = fs::canonicalize(l).ok();
@ -395,7 +395,7 @@ impl<'a> CrateReader<'a> {
if explicitly_linked && !data.explicitly_linked.get() {
data.explicitly_linked.set(explicitly_linked);
}
(cnum, data, self.cstore.do_get_used_crate_source(cnum).unwrap())
(cnum, data, self.cstore.used_crate_source(cnum))
}
LookupResult::Loaded(library) => {
self.register_crate(root, ident, name, span, library,
@ -707,7 +707,8 @@ impl<'a> CrateReader<'a> {
}
impl<'a, 'b> LocalCrateReader<'a, 'b> {
pub fn new(sess: &'a Session, cstore: &'a CStore, map: &'a hir_map::Map<'b>) -> LocalCrateReader<'a, 'b> {
pub fn new(sess: &'a Session, cstore: &'a CStore,
map: &'a hir_map::Map<'b>) -> LocalCrateReader<'a, 'b> {
LocalCrateReader {
sess: sess,
cstore: cstore,

@ -447,12 +447,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource
{
self.do_get_used_crate_source(cnum).unwrap()
self.opt_used_crate_source(cnum).unwrap()
}
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>
{
self.find_extern_mod_stmt_cnum(emod_id)
self.do_extern_mod_stmt_cnum(emod_id)
}
fn encode_metadata(&self,

@ -136,7 +136,7 @@ impl CStore {
I: FnMut(ast::CrateNum, &crate_metadata, Option<CrateSource>),
{
for (&k, v) in self.metas.borrow().iter() {
let origin = self.do_get_used_crate_source(k);
let origin = self.opt_used_crate_source(k);
origin.as_ref().map(|cs| { assert!(k == cs.cnum); });
i(k, &**v, origin);
}
@ -149,9 +149,8 @@ impl CStore {
}
}
// TODO: killdo
pub fn do_get_used_crate_source(&self, cnum: ast::CrateNum)
-> Option<CrateSource> {
pub fn opt_used_crate_source(&self, cnum: ast::CrateNum)
-> Option<CrateSource> {
self.used_crate_sources.borrow_mut()
.iter().find(|source| source.cnum == cnum).cloned()
}
@ -174,7 +173,6 @@ impl CStore {
// In order to get this left-to-right dependency ordering, we perform a
// topological sort of all crates putting the leaves at the right-most
// positions.
// TODO: killdo
pub fn do_get_used_crates(&self, prefer: LinkagePreference)
-> Vec<(ast::CrateNum, Option<PathBuf>)> {
let mut ordering = Vec::new();
@ -234,11 +232,6 @@ impl CStore {
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
}
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
-> Option<ast::CrateNum> {
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
}
pub fn add_statically_included_foreign_item(&self, id: ast::NodeId) {
self.statically_included_foreign_items.borrow_mut().insert(id);
}
@ -246,6 +239,11 @@ impl CStore {
pub fn do_is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool {
self.statically_included_foreign_items.borrow().contains(&id)
}
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>
{
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
}
}
impl crate_metadata {

@ -169,7 +169,7 @@ fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: DefId) -> clean
_ => panic!("bad function"),
};
let constness = if csearch::is_const_fn(&tcx.sess.cstore, did) {
let constness = if tcx.sess.cstore.is_const_fn(did) {
hir::Constness::Const
} else {
hir::Constness::NotConst
@ -346,7 +346,7 @@ pub fn build_impl(cx: &DocContext,
clean::TyMethodItem(clean::TyMethod {
unsafety, decl, self_, generics, abi
}) => {
let constness = if csearch::is_const_fn(&tcx.sess.cstore, did) {
let constness = if tcx.sess.cstore.is_const_fn(did) {
hir::Constness::Const
} else {
hir::Constness::NotConst

@ -22,13 +22,13 @@ use use_from_trait_xc::Trait::CONST;
//~^ ERROR `CONST` is not directly importable
use use_from_trait_xc::Foo::new;
//~^ ERROR `new` is not directly importable
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`
use use_from_trait_xc::Foo::C;
//~^ ERROR unresolved import `use_from_trait_xc::Foo::C`
use use_from_trait_xc::Bar::new as bnew;
//~^ ERROR `bnew` is not directly importable
//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`
use use_from_trait_xc::Baz::new as baznew;
//~^ ERROR `baznew` is not directly importable