From 4190dce3a76f299791c1c6c97e096b381719b2a7 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 25 Nov 2015 17:02:59 +0200 Subject: [PATCH] fix tidy --- src/librustc/middle/cstore.rs | 15 +++++++++------ src/librustc_driver/lib.rs | 5 ++++- src/librustc_metadata/creader.rs | 9 +++++---- src/librustc_metadata/csearch.rs | 4 ++-- src/librustc_metadata/cstore.rs | 18 ++++++++---------- src/librustdoc/clean/inline.rs | 4 ++-- src/test/compile-fail/use-from-trait-xc.rs | 4 ++-- 7 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index ee337f02ffc96..2db43a9497612 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -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; @@ -244,11 +251,7 @@ impl InlinedItem { } pub fn visit_ids(&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); } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index b77425e180929..3a91b573fd4aa 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -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) -> Rc CrateStore<'s>> { use std::mem; diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 89aa3bf86611a..4420da5f9b87d 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -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, diff --git a/src/librustc_metadata/csearch.rs b/src/librustc_metadata/csearch.rs index 99fa18837ebe6..3c97692ee56eb 100644 --- a/src/librustc_metadata/csearch.rs +++ b/src/librustc_metadata/csearch.rs @@ -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 { - self.find_extern_mod_stmt_cnum(emod_id) + self.do_extern_mod_stmt_cnum(emod_id) } fn encode_metadata(&self, diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs index 6a1f9d16fe7a4..b0eef29467ba2 100644 --- a/src/librustc_metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -136,7 +136,7 @@ impl CStore { I: FnMut(ast::CrateNum, &crate_metadata, Option), { 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 { + pub fn opt_used_crate_source(&self, cnum: ast::CrateNum) + -> Option { 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)> { 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 { - 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 + { + self.extern_mod_crate_map.borrow().get(&emod_id).cloned() + } } impl crate_metadata { diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 8b687a250dc2e..40cd5e5bf2787 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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 diff --git a/src/test/compile-fail/use-from-trait-xc.rs b/src/test/compile-fail/use-from-trait-xc.rs index 4f7e38bd26b0a..e6c9b1b41c048 100644 --- a/src/test/compile-fail/use-from-trait-xc.rs +++ b/src/test/compile-fail/use-from-trait-xc.rs @@ -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