Skip to content

Commit

Permalink
fix tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Ben-Yehuda committed Nov 26, 2015
1 parent 52dd2b4 commit 4190dce
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
15 changes: 9 additions & 6 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 8 additions & 10 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()
}
Expand All @@ -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();
Expand Down Expand Up @@ -234,18 +232,18 @@ 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);
}

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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/use-from-trait-xc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4190dce

Please sign in to comment.